.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "demos\01_basics\d03_generateData.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_d03_generateData.py: Simulate projections and noise ============================== Forward-project an image and add realistic Poisson and Gaussian noise. Source: `Python/demos/d03_generateData.py `__ ยท `MATLAB/Demos/d03_generateData.m `__ .. dropdown:: MATLAB version of this demo :icon: code .. literalinclude:: /../MATLAB/Demos/d03_generateData.m :language: matlab .. GENERATED FROM PYTHON SOURCE LINES 17-25 .. code-block:: Python import tigre import numpy as np from tigre.utilities import sample_loader from tigre.utilities import CTnoise geo = tigre.geometry_default(high_resolution=False) .. GENERATED FROM PYTHON SOURCE LINES 26-28 Define angles of projection and load phantom image -------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 28-48 .. code-block:: Python # define projection angles (in radians) angles = np.linspace(0, 2 * np.pi, 50, endpoint=False) # load phantom image head = sample_loader.load_head_phantom(geo.nVoxel) # Simulate forward projection. # To match with mathematical notation, the projection operation is called Ax projections = tigre.Ax(head, geo, angles) # Add realistic noise. Adds photon scattering noise ('Poisson') and # electronic noise of the detector ('Gaussian'). # # 'Poisson' is related to the maximum photon count in the detector. 1e5 is # a standard clinical number, reduce it for more noise # 'Gaussian' is related to possible electronic noise in the detector. mean # of 0 and std of 10 is common in clinical scenario. Increase std for more # noise. noise_projections = CTnoise.add(projections, Poisson=1e5, Gaussian=np.array([0, 10])) .. GENERATED FROM PYTHON SOURCE LINES 49-51 Plot Projections ---------------- .. GENERATED FROM PYTHON SOURCE LINES 51-55 .. code-block:: Python tigre.plotproj(projections) # plot noise tigre.plotproj(projections - noise_projections) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /demos/01_basics/images/sphx_glr_d03_generateData_001.gif :alt: d03 generateData :srcset: /demos/01_basics/images/sphx_glr_d03_generateData_001.gif :class: sphx-glr-multi-img * .. image-sg:: /demos/01_basics/images/sphx_glr_d03_generateData_002.gif :alt: d03 generateData :srcset: /demos/01_basics/images/sphx_glr_d03_generateData_002.gif :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 11.219 seconds) .. _sphx_glr_download_demos_01_basics_d03_generateData.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: d03_generateData.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: d03_generateData.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: d03_generateData.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_