.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "demos\03_geometry\d12_ProjectionOperations.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_demos_03_geometry_d12_ProjectionOperations.py: Projectors and backprojectors ============================= Siddon and interpolated projection, FDK-weighted and matched backprojection. See :doc:`/user-guide/projectors`. Source: `Python/demos/d12_ProjectionOperations.py `__ ยท `MATLAB/Demos/d12_ProjectionOperators.m `__ .. dropdown:: MATLAB version of this demo :icon: code .. literalinclude:: /../MATLAB/Demos/d12_ProjectionOperators.m :language: matlab .. GENERATED FROM PYTHON SOURCE LINES 17-19 Initialize ---------- .. GENERATED FROM PYTHON SOURCE LINES 19-25 .. code-block:: Python import tigre import numpy as np from tigre.utilities import sample_loader import time .. GENERATED FROM PYTHON SOURCE LINES 26-28 Geometry -------- .. GENERATED FROM PYTHON SOURCE LINES 28-31 .. code-block:: Python geo = tigre.geometry_default(high_resolution=False) .. GENERATED FROM PYTHON SOURCE LINES 32-34 This parameter is key for the accuracy of the interpolated FWD projection. -------------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 34-42 .. code-block:: Python geo.accuracy = 0.5 # Accuracy of FWD proj (vx/sample) # lets do just one angles angles = np.array([0]) .. GENERATED FROM PYTHON SOURCE LINES 43-45 Description ----------- .. GENERATED FROM PYTHON SOURCE LINES 45-50 .. code-block:: Python # The difference between them is that `Siddon` will compute the # intersection of a ray crossing each voxel, and the `interpolated` will # sample the voxels at a given sample rate. .. GENERATED FROM PYTHON SOURCE LINES 51-53 Main difference --------------- .. GENERATED FROM PYTHON SOURCE LINES 53-69 .. code-block:: Python head = sample_loader.load_head_phantom(geo.nVoxel) start_time = time.time() projInterp = tigre.Ax(head, geo, angles, "interpolated") interptime = time.time() - start_time start_time = time.time() projray = tigre.Ax(head, geo, angles, "Siddon") raytime = time.time() - start_time # It is relatively clear that discretization artifacts appear with the # ray-voxel approach (middle one) tigre.plotproj(np.concatenate([np.abs(projInterp - projray), projray, projInterp], axis=1), angles) # But also the ray voxel approach is faster (more obvious at bigger sizes) print("Time interpolated: " + str(interptime)) print("Time Siddon : " + str(raytime)) .. image-sg:: /demos/03_geometry/images/sphx_glr_d12_ProjectionOperations_001.gif :alt: d12 ProjectionOperations :srcset: /demos/03_geometry/images/sphx_glr_d12_ProjectionOperations_001.gif :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Time interpolated: 0.008150577545166016 Time Siddon : 0.004004478454589844 .. GENERATED FROM PYTHON SOURCE LINES 70-72 With small voxel the errors are more obvious -------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 72-136 .. code-block:: Python geo.nVoxel = np.array([32, 32, 32]) # number of voxels (vx) geo.sVoxel = np.array([256, 256, 256]) # total size of the image (mm) geo.dVoxel = geo.sVoxel / geo.nVoxel # size of each voxel (mm) head = sample_loader.load_head_phantom(geo.nVoxel) geo.accuracy = 3 projInterp3 = tigre.Ax(head, geo, angles, "interpolated") geo.accuracy = 1 projInterp1 = tigre.Ax(head, geo, angles, "interpolated") geo.accuracy = 0.5 projInterp05 = tigre.Ax(head, geo, angles, "interpolated") geo.accuracy = 0.2 projInterp02 = tigre.Ax(head, geo, angles, "interpolated") geo.accuracy = 0.05 projInterp3005 = tigre.Ax(head, geo, angles, "interpolated") geo.accuracy = 0.01 projInterp3001 = tigre.Ax(head, geo, angles, "interpolated") # the error varies, at big accuracy values because interpolated option # samples too few, but at small values because ray-voxel creates # discretization artifacts # --------------------------------------------------------------------- # However It looks like while there is a big difference between the biggest # and smallers, from accuracy from 1 to 0.01 there is no much change tigre.plotproj( np.concatenate( [ np.abs(projInterp3 - projray), np.abs(projInterp1 - projray), np.abs(projInterp05 - projray), np.abs(projInterp02 - projray), np.abs(projInterp3005 - projray), np.abs(projInterp3001 - projray), ], axis=1, ), angles, clims=[0, 20], ) # lets test the all accuracies against the smallest geo.accuracy value # --------------------------------------------------------------------- # # Observe the colorbars. Note that the maximum value of the projection is # around 60~, meaning a value of error of 14, is very relevant, while a # value of error of 0.1 is less. # geo.accuracy=3 tigre.plotproj(np.abs(projInterp3 - projInterp3001), angles) # geo.accuracy=1 tigre.plotproj(np.abs(projInterp1 - projInterp3001), angles) # geo.accuracy=0.5 tigre.plotproj(np.abs(projInterp05 - projInterp3001), angles) # geo.accuracy=0.2 tigre.plotproj(np.abs(projInterp02 - projInterp3001), angles) # geo.accuracy=0.05 tigre.plotproj(np.abs(projInterp3005 - projInterp3001), angles) # From these plots we can conclude that a value of 1 or less of # geo.accuracy i srasonable. The smaller the better, but eventually the # error will be so small that the imporvement is unperceptible. we # recommend something in the range [0.1-0.5] .. rst-class:: sphx-glr-horizontal * .. image-sg:: /demos/03_geometry/images/sphx_glr_d12_ProjectionOperations_002.gif :alt: d12 ProjectionOperations :srcset: /demos/03_geometry/images/sphx_glr_d12_ProjectionOperations_002.gif :class: sphx-glr-multi-img * .. image-sg:: /demos/03_geometry/images/sphx_glr_d12_ProjectionOperations_003.gif :alt: d12 ProjectionOperations :srcset: /demos/03_geometry/images/sphx_glr_d12_ProjectionOperations_003.gif :class: sphx-glr-multi-img * .. image-sg:: /demos/03_geometry/images/sphx_glr_d12_ProjectionOperations_004.gif :alt: d12 ProjectionOperations :srcset: /demos/03_geometry/images/sphx_glr_d12_ProjectionOperations_004.gif :class: sphx-glr-multi-img * .. image-sg:: /demos/03_geometry/images/sphx_glr_d12_ProjectionOperations_005.gif :alt: d12 ProjectionOperations :srcset: /demos/03_geometry/images/sphx_glr_d12_ProjectionOperations_005.gif :class: sphx-glr-multi-img * .. image-sg:: /demos/03_geometry/images/sphx_glr_d12_ProjectionOperations_006.gif :alt: d12 ProjectionOperations :srcset: /demos/03_geometry/images/sphx_glr_d12_ProjectionOperations_006.gif :class: sphx-glr-multi-img * .. image-sg:: /demos/03_geometry/images/sphx_glr_d12_ProjectionOperations_007.gif :alt: d12 ProjectionOperations :srcset: /demos/03_geometry/images/sphx_glr_d12_ProjectionOperations_007.gif :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.482 seconds) .. _sphx_glr_download_demos_03_geometry_d12_ProjectionOperations.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: d12_ProjectionOperations.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: d12_ProjectionOperations.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: d12_ProjectionOperations.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_