.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "demos\03_geometry\d14_Offsets.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_d14_Offsets.py: Image and detector offsets ========================== Shift the image and the detector, per scan or per angle. Source: `Python/demos/d14_Offsets.py `__ ยท `MATLAB/Demos/d14_Offsets.m `__ .. dropdown:: MATLAB version of this demo :icon: code .. literalinclude:: /../MATLAB/Demos/d14_Offsets.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 tigre.algorithms as algs .. GENERATED FROM PYTHON SOURCE LINES 26-28 Geometry -------- .. GENERATED FROM PYTHON SOURCE LINES 28-49 .. code-block:: Python geo = tigre.geometry_default(high_resolution=False) # Offsets ## #################################################################################### # Lets try simnple offset: The detector gets completelly displaced geo.offOrigin = np.array([0, 0, 0]) # Offset of image from origin (mm) geo.offDetector = np.array([200, 200]) # Offset of Detector (mm) ## #################################################################################### # Auxiliary geo.accuracy = 0.5 # Accuracy of FWD proj (vx/sample) ## Load data and generate projections # see previous demo for explanation angles = np.linspace(0, 2 * np.pi, 100, endpoint=False) # Load thorax phantom data head = sample_loader.load_head_phantom(geo.nVoxel) projections = tigre.Ax(head, geo, angles) .. GENERATED FROM PYTHON SOURCE LINES 50-52 lets see it ----------- .. GENERATED FROM PYTHON SOURCE LINES 52-59 .. code-block:: Python tigre.plotproj(projections, angles) ## we will skip reconstruction of this tests because the image is outside the detector ## ##################################################################### .. image-sg:: /demos/03_geometry/images/sphx_glr_d14_Offsets_001.gif :alt: d14 Offsets :srcset: /demos/03_geometry/images/sphx_glr_d14_Offsets_001.gif :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 60-62 Second test: lets test variying offsets --------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 62-73 .. code-block:: Python geo.offDetector = np.vstack( [10 * np.sin(angles), 20 * np.cos(angles)] ).T # Offset of Detector (mm) projections2 = tigre.Ax(head, geo, angles) ## lets see it tigre.plotproj(projections2, angles) ## reconstruction res = algs.sart(projections2, geo, angles, 10) tigre.plotimg(res, dim="z") .. rst-class:: sphx-glr-horizontal * .. image-sg:: /demos/03_geometry/images/sphx_glr_d14_Offsets_002.gif :alt: d14 Offsets :srcset: /demos/03_geometry/images/sphx_glr_d14_Offsets_002.gif :class: sphx-glr-multi-img * .. image-sg:: /demos/03_geometry/images/sphx_glr_d14_Offsets_003.gif :alt: d14 Offsets :srcset: /demos/03_geometry/images/sphx_glr_d14_Offsets_003.gif :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none SART algorithm in progress. Estimated time until completion : 00:00:05 Algorithm will finish at : 16:51:40 .. GENERATED FROM PYTHON SOURCE LINES 74-76 Third test: lets vary everything -------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 76-96 .. code-block:: Python # Lets make the image smaller geo.nVoxel = np.array([128, 128, 128]) # number of voxels (vx) geo.sVoxel = np.array([256, 256, 256]) / 2 # 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.offDetector = np.vstack( [10 * np.sin(angles), 10 * np.cos(angles)] ).T # Offset of Detector (mm) geo.offOrigin = np.vstack( [40 * np.sin(angles), np.linspace(-30, 30, len(angles)), 40 * np.cos(angles)] ).T # Offset of image from origin (mm) projections3 = tigre.Ax(head, geo, angles) ## lets see it tigre.plotproj(projections3, angles) ## reconstruction res = algs.sart(projections3, geo, angles, 10) tigre.plotimg(res, dim="z") .. rst-class:: sphx-glr-horizontal * .. image-sg:: /demos/03_geometry/images/sphx_glr_d14_Offsets_004.gif :alt: d14 Offsets :srcset: /demos/03_geometry/images/sphx_glr_d14_Offsets_004.gif :class: sphx-glr-multi-img * .. image-sg:: /demos/03_geometry/images/sphx_glr_d14_Offsets_005.gif :alt: d14 Offsets :srcset: /demos/03_geometry/images/sphx_glr_d14_Offsets_005.gif :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none SART algorithm in progress. Estimated time until completion : 00:00:10 Algorithm will finish at : 16:52:06 .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 6.342 seconds) .. _sphx_glr_download_demos_03_geometry_d14_Offsets.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: d14_Offsets.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: d14_Offsets.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: d14_Offsets.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_