.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "demos\01_basics\d05_plottingFunctions.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_01_basics_d05_plottingFunctions.py: Plot images and projections =========================== All the options of ``plotimg`` and ``plotproj``. Source: `Python/demos/d05_plottingFunctions.py `__ ยท `MATLAB/Demos/d05_plottingFunctions.m `__ .. dropdown:: MATLAB version of this demo :icon: code .. literalinclude:: /../MATLAB/Demos/d05_plottingFunctions.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 Geometry -------- .. GENERATED FROM PYTHON SOURCE LINES 29-32 .. code-block:: Python geo = tigre.geometry_default(high_resolution=False) .. GENERATED FROM PYTHON SOURCE LINES 33-35 Load data and generate projections ---------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 35-45 .. code-block:: Python # define angles angles = np.linspace(0, 2 * np.pi, 100, endpoint=False) # Load thorax phantom data head = sample_loader.load_head_phantom(geo.nVoxel) # generate projections projections = tigre.Ax(head, geo, angles) # add noise noise_projections = CTnoise.add(projections, Poisson=1e5, Gaussian=np.array([0, 10])) .. GENERATED FROM PYTHON SOURCE LINES 46-48 Reconstruct image using OS-SART and FDK --------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 48-54 .. code-block:: Python # FDK imgFDK = algs.fdk(noise_projections, geo, angles) niter = 50 imgOSSART = algs.ossart(noise_projections, geo, angles, 50) .. rst-class:: sphx-glr-script-out .. code-block:: none OSSART algorithm in progress. Estimated time until completion : 00:00:03 Algorithm will finish at : 16:48:06 .. GENERATED FROM PYTHON SOURCE LINES 55-57 Lets use PlotProj ----------------- .. GENERATED FROM PYTHON SOURCE LINES 57-98 .. code-block:: Python # # plotProj plots the projection data measure on the detector on each angle. # # exhaustive list of possible parameters: # 'Step' : Defines the step size for skippin projections when plotting, # usefull when there are a big amount of projections. Default is 1 step = 2 # 'Colormap': Defines the colormap used to plot. Default is 'gray'. colormap = "viridis" colormap = "plasma" colormap = "gray" # 'Clims': Defines the data limits for the color, usefull when one wants to # see some specific range. The default uses the minimum and maximum of the # data. clims = [0, 200] # 'Savegif': allows to save the plotted figure as an animated gif, # specified by the given filename. giffilename = "demo5projections.gif" # 'Slice': allows to plot a single projection .Will overwrite the behavior # of 'Step' slice = 5 # Lets try out. tigre.plotproj( noise_projections, angles, step=step, colormap=colormap, clims=clims, savegif=giffilename ) # not using 'Step' # Remember you can also plot errors, for example the added noise by: noise = np.abs(noise_projections - projections) # abs is what we are interested in plotting tigre.plotproj(noise, angles, clims=[0, 2]) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /demos/01_basics/images/sphx_glr_d05_plottingFunctions_001.gif :alt: d05 plottingFunctions :srcset: /demos/01_basics/images/sphx_glr_d05_plottingFunctions_001.gif :class: sphx-glr-multi-img * .. image-sg:: /demos/01_basics/images/sphx_glr_d05_plottingFunctions_002.gif :alt: d05 plottingFunctions :srcset: /demos/01_basics/images/sphx_glr_d05_plottingFunctions_002.gif :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 99-101 PlotImg ------- .. GENERATED FROM PYTHON SOURCE LINES 101-145 .. code-block:: Python # plotImg plots the image slice by slice. # # List of optional parameters: # 'Dim': specifies the dimension for plotting. # Dim can be 'X','Y','Z' # dimension = "Z" # 'Step': step size of the plotting. Useful when images are big or one just # wants an overview of the result step = 2 # 'Colormap': Defines the colormap used to plot. Default is 'gray'. colormap = "plasma" colormap = "magma" colormap = "gray" colormap = "viridis" # 'Clims': Defines the data limits for the color, usefull when one wants to # see some specific range. The default computes the 5% and 95% percentiles # of the data and uses that as limit. clims = [0, 1] # 'Savegif': allows to save the plotted figure as an animated gif, # specified by the given filename. giffilename = "demo5image.gif" # 'Slice': allows to plot a single slice .Will overwrite the behavior # of 'Step' slice = 64 # Lets go for it tigre.plotimg(imgFDK, dim=dimension, step=step, clims=clims, colormap=colormap, savegif=giffilename) # Remember: You can always plot more than 1 image together! tigre.plotimg(np.concatenate([head, imgFDK, imgOSSART], axis=1), dim="z") # Or even the errors! tigre.plotImg(np.concatenate([np.abs(head - imgFDK), np.abs(head - imgOSSART)]), dim="z") .. rst-class:: sphx-glr-horizontal * .. image-sg:: /demos/01_basics/images/sphx_glr_d05_plottingFunctions_003.gif :alt: d05 plottingFunctions :srcset: /demos/01_basics/images/sphx_glr_d05_plottingFunctions_003.gif :class: sphx-glr-multi-img * .. image-sg:: /demos/01_basics/images/sphx_glr_d05_plottingFunctions_004.gif :alt: d05 plottingFunctions :srcset: /demos/01_basics/images/sphx_glr_d05_plottingFunctions_004.gif :class: sphx-glr-multi-img * .. image-sg:: /demos/01_basics/images/sphx_glr_d05_plottingFunctions_005.gif :alt: d05 plottingFunctions :srcset: /demos/01_basics/images/sphx_glr_d05_plottingFunctions_005.gif :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 45.074 seconds) .. _sphx_glr_download_demos_01_basics_d05_plottingFunctions.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: d05_plottingFunctions.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: d05_plottingFunctions.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: d05_plottingFunctions.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_