.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated\examples\plot_reslicing.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_generated_examples_plot_reslicing.py: ==================================== Coronal, sagittal, axial and oblique ==================================== This examples illustrates how vreg can be used to slice 3D volumes in different ways. .. GENERATED FROM PYTHON SOURCE LINES 11-13 Setup ----- .. GENERATED FROM PYTHON SOURCE LINES 13-17 .. code-block:: Python import numpy as np import vreg import vreg.plot as plt .. GENERATED FROM PYTHON SOURCE LINES 18-22 Get data -------- The starting point of this example is a 3D coronal volume of the abdomen. For visual reference we'll also load a 3D coronal mask of the kidneys. .. GENERATED FROM PYTHON SOURCE LINES 22-32 .. code-block:: Python # 3D coronal volume of the abdomen cor = vreg.fetch('Dixon_out_phase') # 3D coronal mask of the kidneys mask = vreg.fetch('kidneys') # Show the data plt.overlay_2d(cor, mask, alpha=1.0, width=6) .. image-sg:: /generated/examples/images/sphx_glr_plot_reslicing_001.png :alt: plot reslicing :srcset: /generated/examples/images/sphx_glr_plot_reslicing_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 33-38 Coronal -> Axial ---------------- We reslice the coronal volume in the axial plane using an isotropic 1mm voxel size. Since 1mm is the default spacing, we do not have to specify it explicitly. .. GENERATED FROM PYTHON SOURCE LINES 38-45 .. code-block:: Python # Reslice isotropically in the axial plane axial = cor.reslice(orient='axial') # Show the result plt.overlay_2d(axial, mask, alpha=1.0, width=6) .. image-sg:: /generated/examples/images/sphx_glr_plot_reslicing_002.png :alt: plot reslicing :srcset: /generated/examples/images/sphx_glr_plot_reslicing_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 46-50 Axial -> Sagittal ----------------- Since vreg keeps track of the position in space, we can keep reslicing the result. Let's reslice the axial volume sagitally: .. GENERATED FROM PYTHON SOURCE LINES 50-57 .. code-block:: Python # Reslice isotropically in the sagittal plane sagit = axial.reslice(orient='sagittal') # Show the result plt.overlay_2d(sagit, mask, alpha=1.0, width=6) .. image-sg:: /generated/examples/images/sphx_glr_plot_reslicing_003.png :alt: plot reslicing :srcset: /generated/examples/images/sphx_glr_plot_reslicing_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 58-62 Sagittal -> Coronal ------------------- As a consistency check, we can reslice the sagittal volume coronally again and check against the original .. GENERATED FROM PYTHON SOURCE LINES 62-69 .. code-block:: Python # Sagittal to coronal cor = sagit.reslice(orient='coronal') # Compare result to the original plt.overlay_2d(cor, mask, alpha=1.0, width=6) .. image-sg:: /generated/examples/images/sphx_glr_plot_reslicing_004.png :alt: plot reslicing :srcset: /generated/examples/images/sphx_glr_plot_reslicing_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 70-73 As expected, this looks visually the same as the original coronal image. The number of slices is increased because this now has a 1mm isotropic voxel size, whereas the original had 1.5mm slice thickness. .. GENERATED FROM PYTHON SOURCE LINES 75-87 Oblique ------- The oblique orientation refers to any that is not in one of the standard plances (coronal, sagittal or axial). A volume can be reslice to any oblique orientation by specifying a rotation vector. As an example, let's reslice the coronal volume obliquely along the principle axis of the kidneys. The sagittal images shows that the kidneys make an angle of approximately 30 degrees with the vertical (z-axis). If we reslice the coronal volume using a rotation of -30 degrees around the x-axis, we get a coronal-oblique view through the kidneys: .. GENERATED FROM PYTHON SOURCE LINES 87-93 .. code-block:: Python obl = cor.reslice(rotation=[-np.radians(30), 0, 0]) # Show the oblique reslice: plt.overlay_2d(obl, mask, alpha=1.0, width=6) .. image-sg:: /generated/examples/images/sphx_glr_plot_reslicing_005.png :alt: plot reslicing :srcset: /generated/examples/images/sphx_glr_plot_reslicing_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 94-99 Oblique in the sagittal plane ----------------------------- The oblique image above cuts along the natural axis of the kidneys. We can verify this visually by looking at this oblique section in the sagittal plane: .. GENERATED FROM PYTHON SOURCE LINES 99-106 .. code-block:: Python obl = cor.reslice(orient='sagittal', rotation=[-np.radians(30), 0, 0]) # Show the sagittal-oblique view plt.overlay_2d(obl, mask, alpha=1.0, width=6) .. image-sg:: /generated/examples/images/sphx_glr_plot_reslicing_006.png :alt: plot reslicing :srcset: /generated/examples/images/sphx_glr_plot_reslicing_006.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (4 minutes 36.951 seconds) .. _sphx_glr_download_generated_examples_plot_reslicing.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_reslicing.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_reslicing.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_reslicing.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_