.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "demos\01_basics\d11_PostProcessing.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_d11_PostProcessing.py: Post-process a reconstruction ============================= Denoise a reconstruction with total variation after it is computed. Source: `Python/demos/d11_PostProcessing.py `__ ยท `MATLAB/Demos/d11_PostProcessing.m `__ .. dropdown:: MATLAB version of this demo :icon: code .. literalinclude:: /../MATLAB/Demos/d11_PostProcessing.m :language: matlab .. GENERATED FROM PYTHON SOURCE LINES 17-19 Initialize ---------- .. GENERATED FROM PYTHON SOURCE LINES 19-29 .. 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 from matplotlib import pyplot as plt from tigre.utilities.im_3d_denoise import im3ddenoise from tigre.utilities.crop_CBCT import cropCBCT .. GENERATED FROM PYTHON SOURCE LINES 30-32 Geometry -------- .. GENERATED FROM PYTHON SOURCE LINES 32-35 .. code-block:: Python geo = tigre.geometry_default(high_resolution=False) .. GENERATED FROM PYTHON SOURCE LINES 36-38 Load data and generate projections ---------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 38-48 .. 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 49-51 Some recon, FDK for example --------------------------- .. GENERATED FROM PYTHON SOURCE LINES 51-54 .. code-block:: Python imgFDK = algs.fdk(projections, geo, angles) .. GENERATED FROM PYTHON SOURCE LINES 55-57 Postprocessing -------------- .. GENERATED FROM PYTHON SOURCE LINES 57-74 .. code-block:: Python # # Currently the postprocessing steps in TIGRE are limited, but there are 2 # functions you can use # # im3ddenoise : Denoises a 3D image, using Total Variation denoising. # # Arguments are the number of iterations and the hyperparameter (same as in # SART-TV) imgdenoised = im3ddenoise(imgFDK, 100, 15) # cropCBCT: Crops all the sections that lie outide the area that is covered # by the cone # Note this does not consider offsets nor does it remove the top and bottom # cone sections imcropped = cropCBCT(imgFDK) .. GENERATED FROM PYTHON SOURCE LINES 75-77 plot results ------------ .. GENERATED FROM PYTHON SOURCE LINES 77-88 .. code-block:: Python # denoised image is clearer tigre.plotImg( np.concatenate([imgFDK, imgdenoised, imcropped], axis=1), dim="z" ) # however, the denoising has no knoledge of the original data (projections) # this it doesnt reduce the error. The error increases, specially in small # areas tigre.plotImg( abs(np.concatenate([head - imgFDK, head - imgdenoised, head - imcropped], axis=1)), dim="z" ) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /demos/01_basics/images/sphx_glr_d11_PostProcessing_001.gif :alt: d11 PostProcessing :srcset: /demos/01_basics/images/sphx_glr_d11_PostProcessing_001.gif :class: sphx-glr-multi-img * .. image-sg:: /demos/01_basics/images/sphx_glr_d11_PostProcessing_002.gif :alt: d11 PostProcessing :srcset: /demos/01_basics/images/sphx_glr_d11_PostProcessing_002.gif :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 8.337 seconds) .. _sphx_glr_download_demos_01_basics_d11_PostProcessing.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: d11_PostProcessing.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: d11_PostProcessing.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: d11_PostProcessing.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_