.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "demos\01_basics\d10_MeasureQuality.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_d10_MeasureQuality.py: Measure image quality ===================== Compute error and similarity measures against a reference image, also during the iterations of an algorithm. Source: `Python/demos/d10_MeasureQuality.py `__ ยท `MATLAB/Demos/d10_QualityMeasurements.m `__ .. dropdown:: MATLAB version of this demo :icon: code .. literalinclude:: /../MATLAB/Demos/d10_QualityMeasurements.m :language: matlab .. GENERATED FROM PYTHON SOURCE LINES 17-19 Initialize ---------- .. GENERATED FROM PYTHON SOURCE LINES 19-28 .. 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.Measure_Quality import Measure_Quality as MQ .. GENERATED FROM PYTHON SOURCE LINES 29-31 Geometry -------- .. GENERATED FROM PYTHON SOURCE LINES 31-34 .. code-block:: Python geo = tigre.geometry_default(high_resolution=False) .. GENERATED FROM PYTHON SOURCE LINES 35-37 Load data and generate projections ---------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 37-47 .. 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 48-50 Image quality measurement ------------------------- .. GENERATED FROM PYTHON SOURCE LINES 50-94 .. code-block:: Python # There are three inputs to the function # # 'RMSE' : The square root of the mean of the squared differences # of pixel intensities of two images. # # Taken from "A rigid motion correction method for helical # computed tomography (CT)" # (doi:10.1088/0031-9155/60/5/2047) # 'nRMSE': The square root of the mean of the squared differences # of pixel intensities of two images, normalized # # 'CC' : The Pearson correlation coefficient which measures the # linear dependence between two images. # # Taken from "A rigid motion correction method for helical # computed tomography (CT)" # (doi:10.1088/0031-9155/60/5/2047) # # 'MSSIM': The mean structural similarity index, a measure of the # similarity of two images in terms of luminance, # contrast and structure that is designed to provide a # good approximation of perceptual image quality. # # Taken from "A rigid motion correction method for helical # computed tomography (CT)" # (doi:10.1088/0031-9155/60/5/2047) # # 'UQI' : The universal quality index to evaluate the degree of # similarity between the reconstructed and phantom images # for chosen ROIs. Its value ranges from zero to one. # A UQI value closer to one suggests better similarity to true image. # # Taken from "Few-view cone-beam CT reconstruction with # deformed prior image" (doi: 10.1118/1.4901265) # # # # ## Define a cell array of image quality measures qualmeas = ["RMSE", "CC", "MSSIM", "UQI"] .. GENERATED FROM PYTHON SOURCE LINES 95-97 Reconstruct image using SIRT, SART and OS-SART ---------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 97-103 .. code-block:: Python # ========================================================================= imgSIRT, qualitySIRT = algs.sirt(noise_projections, geo, angles, 20, Quameasopts=qualmeas) imgSART, qualitySART = algs.sart(noise_projections, geo, angles, 20, Quameasopts=qualmeas) imgOSSART, qualityOSSART = algs.ossart(noise_projections, geo, angles, 20, Quameasopts=qualmeas) .. rst-class:: sphx-glr-script-out .. code-block:: none SIRT algorithm in progress. C:\Users\ander\anaconda3\envs\tigre\Lib\site-packages\numpy\lib\_function_base_impl.py:3023: RuntimeWarning: invalid value encountered in divide c /= stddev[:, None] C:\Users\ander\anaconda3\envs\tigre\Lib\site-packages\numpy\lib\_function_base_impl.py:3024: RuntimeWarning: invalid value encountered in divide c /= stddev[None, :] Estimated time until completion : 00:00:00 Algorithm will finish at : 16:48:48 SART algorithm in progress. Estimated time until completion : 00:00:12 Algorithm will finish at : 16:49:02 OSSART algorithm in progress. Estimated time until completion : 00:00:01 Algorithm will finish at : 16:49:02 .. GENERATED FROM PYTHON SOURCE LINES 104-106 Plot the changes of image quality measures over iterations, i.e. how much each iteration looks like the previous iteration. --------------------------------------------------------------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 106-143 .. code-block:: Python # (without the original image one can not compute the absolute image quality, of course) ##RMSE plot plt.figure() plt.plot(np.vstack((qualitySIRT[0, :], qualityOSSART[0, :], qualitySART[0, :])).T) plt.title("Evolution of RMSE per iteration") plt.xlabel("Iteration") plt.ylabel("RMSE") plt.gca().legend(("SIRT", "OS-SART", "SART")) ##CC plot plt.figure() plt.plot(np.vstack((qualitySIRT[1, :], qualityOSSART[1, :], qualitySART[1, :])).T) plt.title("Evolution of CC per iteration") plt.xlabel("Iteration") plt.ylabel("CC") plt.gca().legend(("SIRT", "OS-SART", "SART")) ##MSSIM plot plt.figure() plt.plot(np.vstack((qualitySIRT[2, :], qualityOSSART[2, :], qualitySART[2, :])).T) plt.title("Evolution of MSSIM per iteration") plt.xlabel("Iteration") plt.ylabel("MSSIM") plt.gca().legend(("SIRT", "OS-SART", "SART")) ##UQI plot plt.figure() plt.plot(np.vstack((qualitySIRT[3, :], qualityOSSART[3, :], qualitySART[3, :])).T) plt.title("Evolution of UQI per iteration") plt.xlabel("Iteration") plt.ylabel("UQI") plt.gca().legend(("SIRT", "OS-SART", "SART")) plt.show() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /demos/01_basics/images/sphx_glr_d10_MeasureQuality_001.png :alt: Evolution of RMSE per iteration :srcset: /demos/01_basics/images/sphx_glr_d10_MeasureQuality_001.png :class: sphx-glr-multi-img * .. image-sg:: /demos/01_basics/images/sphx_glr_d10_MeasureQuality_002.png :alt: Evolution of CC per iteration :srcset: /demos/01_basics/images/sphx_glr_d10_MeasureQuality_002.png :class: sphx-glr-multi-img * .. image-sg:: /demos/01_basics/images/sphx_glr_d10_MeasureQuality_003.png :alt: Evolution of MSSIM per iteration :srcset: /demos/01_basics/images/sphx_glr_d10_MeasureQuality_003.png :class: sphx-glr-multi-img * .. image-sg:: /demos/01_basics/images/sphx_glr_d10_MeasureQuality_004.png :alt: Evolution of UQI per iteration :srcset: /demos/01_basics/images/sphx_glr_d10_MeasureQuality_004.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 144-146 Compute the parameters for the target image ------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 146-164 .. code-block:: Python # Knowing change of the parameters per iteration can be interesting, but # The main use of them would be to compare a reconstructed image to a given # known target image. sart_uqi = MQ(head, imgSART, ["UQI"]) sirt_uqi = MQ(head, imgSIRT, ["UQI"]) ossart_uqi = MQ(head, imgOSSART, ["UQI"]) print("UQI for SART, SIRT, OS-SART") print(" " + str(sart_uqi) + " " + str(sirt_uqi) + " " + str(ossart_uqi)) sart_rmse = MQ(head, imgSART, ["RMSE"]) sirt_rmse = MQ(head, imgSIRT, ["RMSE"]) ossart_rmse = MQ(head, imgOSSART, ["RMSE"]) print("RMSE for SART, SIRT, OS-SART") print(" " + str(sart_rmse) + " " + str(sirt_rmse) + " " + str(ossart_rmse)) .. rst-class:: sphx-glr-script-out .. code-block:: none UQI for SART, SIRT, OS-SART 0.9996299654256502 0.9481986239371448 0.9930949515753248 RMSE for SART, SIRT, OS-SART 0.005299152075107854 0.05864690912342974 0.022644113658784406 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 15.757 seconds) .. _sphx_glr_download_demos_01_basics_d10_MeasureQuality.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: d10_MeasureQuality.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: d10_MeasureQuality.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: d10_MeasureQuality.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_