.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "demos\03_geometry\d16_2Dtomography.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_d16_2Dtomography.py: 2D tomography ============= Fan-beam and parallel-beam 2D problems, as one-slice 3D problems. Source: `Python/demos/d16_2Dtomography.py `__ ยท `MATLAB/Demos/d16_2Dtomography.m `__ .. dropdown:: MATLAB version of this demo :icon: code .. literalinclude:: /../MATLAB/Demos/d16_2Dtomography.m :language: matlab .. GENERATED FROM PYTHON SOURCE LINES 17-19 Initialize ---------- .. GENERATED FROM PYTHON SOURCE LINES 19-26 .. code-block:: Python import tigre import numpy as np from tigre.utilities import sample_loader from tigre.utilities import CTnoise import tigre.algorithms as algs .. GENERATED FROM PYTHON SOURCE LINES 27-29 2D Parallel beam ---------------- .. GENERATED FROM PYTHON SOURCE LINES 29-58 .. code-block:: Python # VARIABLE DESCRIPTION UNITS # HERE COMES THE TRICK. # # 1- Make the detector Nx1 (instead of 1) # 2- Make the image NxMx1 (instead of 1) geo = tigre.geometry() # VARIABLE DESCRIPTION UNITS # ------------------------------------------------------------------------------------- # Distances geo.DSD = 1536 # Distance Source Detector (mm) geo.DSO = 1000 # Distance Source Origin (mm) # Image parameters geo.nVoxel = np.array([1, 256, 256]) # number of voxels (vx) geo.sVoxel = np.array([1, 256, 256]) # total size of the image (mm) geo.dVoxel = geo.sVoxel / geo.nVoxel # size of each voxel (mm) # Detector parameters geo.nDetector = np.array([1, 512]) # number of pixels (px) geo.dDetector = np.array([geo.dVoxel[0], 0.8]) # size of each pixel (mm) geo.sDetector = geo.nDetector * geo.dDetector # total size of the detector (mm) # Offsets geo.offOrigin = np.array([0, 0, 0]) # Offset of image from origin (mm) geo.offDetector = np.array([0, 0]) # Offset of Detector (mm) # MAKE SURE THAT THE DETECTOR PIXELS SIZE IN V IS THE SAME AS THE IMAGE! geo.mode = "parallel" .. GENERATED FROM PYTHON SOURCE LINES 59-61 Define angles of projection and load phantom image -------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 61-67 .. code-block:: Python angles = np.linspace(0, 2 * np.pi, 100, endpoint=False) head = sample_loader.load_head_phantom(geo.nVoxel) projections = tigre.Ax(head, geo, angles) tigre.plotSinogram(projections, 0) .. image-sg:: /demos/03_geometry/images/sphx_glr_d16_2Dtomography_001.png :alt: d16 2Dtomography :srcset: /demos/03_geometry/images/sphx_glr_d16_2Dtomography_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 68-70 reconstruct ----------- .. GENERATED FROM PYTHON SOURCE LINES 70-74 .. code-block:: Python imgOSSART = algs.ossart(projections, geo, angles, 40) imgCGLS = algs.cgls(projections, geo, angles, 40) .. rst-class:: sphx-glr-script-out .. code-block:: none OSSART algorithm in progress. Estimated time until completion : 00:00:00 Algorithm will finish at : 16:55:27 CGLS algorithm in progress. Estimated time until completion : 00:00:00 Algorithm will finish at : 16:55:28 Average time taken for each iteration for CGLS:0.0049770874989917505(s) .. GENERATED FROM PYTHON SOURCE LINES 75-77 Plot ---- .. GENERATED FROM PYTHON SOURCE LINES 77-80 .. code-block:: Python tigre.plotimg(np.concatenate([head, imgOSSART, imgCGLS], axis=1), dim="z", slice=0, clims=[0, 0.5]) .. image-sg:: /demos/03_geometry/images/sphx_glr_d16_2Dtomography_002.png :alt: d16 2Dtomography :srcset: /demos/03_geometry/images/sphx_glr_d16_2Dtomography_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 81-83 And now Fan Beam ---------------- .. GENERATED FROM PYTHON SOURCE LINES 83-110 .. code-block:: Python ## # The same thing! Just remember to offset the detector half a pixel, so its # centered (this is a bug, it will be changed at some point) ## FAN BEAM 2D geo = tigre.geometry() # VARIABLE DESCRIPTION UNITS # ------------------------------------------------------------------------------------- # Distances geo.DSD = 1536 # Distance Source Detector (mm) geo.DSO = 1000 # Distance Source Origin (mm) # Image parameters geo.nVoxel = np.array([1, 256, 256]) # number of voxels (vx) geo.sVoxel = np.array([1, 256, 256]) # total size of the image (mm) geo.dVoxel = geo.sVoxel / geo.nVoxel # size of each voxel (mm) # Detector parameters geo.nDetector = np.array([1, 512]) # number of pixels (px) geo.dDetector = np.array([geo.dVoxel[0], 0.8]) # size of each pixel (mm) geo.sDetector = geo.nDetector * geo.dDetector # total size of the detector (mm) # Offsets geo.offOrigin = np.array([0, 0, 0]) # Offset of image from origin (mm) geo.offDetector = np.array([0, 0]) # Offset of Detector (mm) # MAKE SURE THAT THE DETECTOR PIXELS SIZE IN V IS THE SAME AS THE IMAGE! geo.mode = "cone" .. GENERATED FROM PYTHON SOURCE LINES 111-113 Define angles of projection and load phantom image -------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 113-118 .. code-block:: Python angles = np.linspace(0, 2 * np.pi, 100, endpoint=False) head = sample_loader.load_head_phantom(geo.nVoxel) projections = tigre.Ax(head, geo, angles) .. GENERATED FROM PYTHON SOURCE LINES 119-121 reconstruct ----------- .. GENERATED FROM PYTHON SOURCE LINES 121-125 .. code-block:: Python imgOSSART = algs.ossart(projections, geo, angles, 40) imgCGLS = algs.cgls(projections, geo, angles, 40) .. rst-class:: sphx-glr-script-out .. code-block:: none OSSART algorithm in progress. Estimated time until completion : 00:00:00 Algorithm will finish at : 16:55:29 CGLS algorithm in progress. Estimated time until completion : 00:00:00 Algorithm will finish at : 16:55:29 re-initilization of CGLS called at iteration:1 Estimated time until completion : 00:00:01 Algorithm will finish at : 16:55:30 re-initilization of CGLS called at iteration:2 re-initilization of CGLS called at iteration:3 re-initilization of CGLS called at iteration:4 re-initilization of CGLS called at iteration:5 re-initilization of CGLS called at iteration:6 re-initilization of CGLS called at iteration:7 re-initilization of CGLS called at iteration:8 re-initilization of CGLS called at iteration:9 re-initilization of CGLS called at iteration:10 re-initilization of CGLS called at iteration:11 re-initilization of CGLS called at iteration:12 re-initilization of CGLS called at iteration:13 re-initilization of CGLS called at iteration:14 re-initilization of CGLS called at iteration:15 re-initilization of CGLS called at iteration:16 re-initilization of CGLS called at iteration:17 re-initilization of CGLS called at iteration:18 re-initilization of CGLS called at iteration:19 re-initilization of CGLS called at iteration:20 re-initilization of CGLS called at iteration:21 re-initilization of CGLS called at iteration:22 re-initilization of CGLS called at iteration:23 re-initilization of CGLS called at iteration:24 re-initilization of CGLS called at iteration:25 re-initilization of CGLS called at iteration:26 re-initilization of CGLS called at iteration:27 re-initilization of CGLS called at iteration:28 re-initilization of CGLS called at iteration:29 re-initilization of CGLS called at iteration:30 re-initilization of CGLS called at iteration:31 re-initilization of CGLS called at iteration:32 re-initilization of CGLS called at iteration:33 re-initilization of CGLS called at iteration:34 re-initilization of CGLS called at iteration:35 re-initilization of CGLS called at iteration:36 re-initilization of CGLS called at iteration:37 re-initilization of CGLS called at iteration:38 re-initilization of CGLS called at iteration:39 Average time taken for each iteration for CGLS:0.004182805063510962(s) .. GENERATED FROM PYTHON SOURCE LINES 126-128 Plot ---- .. GENERATED FROM PYTHON SOURCE LINES 128-130 .. code-block:: Python tigre.plotimg(np.concatenate([head, imgOSSART, imgCGLS], axis=1), dim="z", slice=0, clims=[0, 0.5]) .. image-sg:: /demos/03_geometry/images/sphx_glr_d16_2Dtomography_003.png :alt: d16 2Dtomography :srcset: /demos/03_geometry/images/sphx_glr_d16_2Dtomography_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.700 seconds) .. _sphx_glr_download_demos_03_geometry_d16_2Dtomography.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: d16_2Dtomography.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: d16_2Dtomography.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: d16_2Dtomography.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_