CERN / TIGRE

TIGRE: Tomographic Iterative GPU-based Reconstruction Toolbox
BSD 3-Clause "New" or "Revised" License
575 stars 189 forks source link

measure image quality #422

Closed shaghayegh1376 closed 1 year ago

shaghayegh1376 commented 1 year ago

hello I was implementing demo number 10, which is related to the measurement of image quality parameters for ART family algorithms. When I tried to check the image quality parameters for the rest of the algorithms and compare all the algorithms, I got an error for fdk and cgls .

Expected Behavior

get a chart like demo for rest of the algorithms

Actual Behavior

facing some errors

Code to reproduce the problem (If applicable)

if i run the following

imgCGLS, qualityCGLS = algs.ossart(noise_projections, geo, angles, 20, Quameasopts=qualmeas)

output would be:

. CGLS algorithm in progress. . Estimated time until completion : 00:00:03 . C:\Users\shaghayegh\anaconda3\lib\site-packages\numpy\lib\function_base.py:2642: RuntimeWarning: invalid value encountered in >. true_divide . c /= stddev[:, None] . C:\Users\shaghayegh\anaconda3\lib\site-packages\numpy\lib\function_base.py:2643: RuntimeWarning: invalid value encountered in >. true_divide . c /= stddev[None, :]

ValueError Traceback (most recent call last)

in ----> 1 imgCGLS, qualityCGLS = algs.cgls(noise_projections, geo, angles, 20, Quameasopts=qualmeas)

c:\users\shaghayegh\tigre\python\tigre\algorithms\iterative_recon_alg.py in iterativereconalg(proj, geo, angles, niter, **kwargs) 461 if name is not None: 462 alg.name = name --> 463 alg.run_main_iter() 464 if alg.computel2 or alg.Quameasopts is not None: 465 return alg.getres(), alg.geterrors()

c:\users\shaghayegh\tigre\python\tigre\algorithms\krylov_subspace_algorithms.py in run_main_iter(self) 78 and np.isnan(getattr(self, item)).any() 79 ): ---> 80 raise ValueError("nan found for " + item + " at iteraton " + str(i)) 81 82 aux = self.proj - tigre.Ax(

ValueError: nan found for lq at iteraton 1



and for fdk :
if i run this
imgFDK, qualityFDK = algs.fdk(projections, geo, angles, Quameasopts=qualmeas)

out put woud be
>.
`---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-43-8f21082ac67f> in <module>
----> 1 imgFDK, qualityFDK = algs.fdk(projections, geo, angles, Quameasopts=qualmeas)
      2 

ValueError: too many values to unpack (expected 2)`
## Specifications 

  - MATLAB/python version:python 3.7 
  - OS:
  - CUDA version:10.1
AnderBiguri commented 1 year ago

@shaghayegh1376 thanks! python has some bugs here and there.

Can you please provide a full code snipped that I can copy paste to reproduce the error, so I can help fix it?

shaghayegh1376 commented 1 year ago

yes of course here is the whole code:

#%%Initialize
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

#%% Geometry
geo = tigre.geometry_default(high_resolution=False)

#%% Load data and generate projections
# define angles
angles = np.linspace(0, 2 * np.pi, 100)
# Load thorax phatom 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]))
## Define a cell array of image quality measures
qualmeas = ["RMSE", "CC", "MSSIM", "UQI"]
imgCGLS, qualityCGLS = algs.cgls(noise_projections, geo, angles, 20, Quameasopts=qualmeas)

.CGLS algorithm in progress. Estimated time until completion : 00:00:03

ValueError Traceback (most recent call last)

in ----> 1 imgCGLS, qualityCGLS = algs.cgls(noise_projections, geo, angles, 20, Quameasopts=qualmeas)

c:\users\shaghayegh\tigre\python\tigre\algorithms\iterative_recon_alg.py in iterativereconalg(proj, geo, angles, niter, **kwargs) 461 if name is not None: 462 alg.name = name --> 463 alg.run_main_iter() 464 if alg.computel2 or alg.Quameasopts is not None: 465 return alg.getres(), alg.geterrors()

c:\users\shaghayegh\tigre\python\tigre\algorithms\krylov_subspace_algorithms.py in run_main_iter(self) 78 and np.isnan(getattr(self, item)).any() 79 ): ---> 80 raise ValueError("nan found for " + item + " at iteraton " + str(i)) 81 82 aux = self.proj - tigre.Ax(

ValueError: nan found for lq at iteraton 1

`

yliu88au commented 1 year ago

fdk is a single pass algorithm, so it cannot have image quality measurement (in current implementation, this measurement is for between iterations, not compared with the "ground truth". Not sure what happens to CGLS though.

AnderBiguri commented 1 year ago

@shaghayegh1376 Hi! Apologies for the very late response.

As @yliu88au said, FDK can't have quality measures, as its not for comparing vs ground truth, but to monitor their change per iteration. However, the rest of the code for CGLS works well on my side while using the same python and CUDA as you. Try to update TIGRE, it may be that you are not in the latest commit.

AnderBiguri commented 1 year ago

I will close this as I can not reproduce it, so it may have been fixed since, but feel free to open it again if you still have the error.