TomographicImaging / CIL

A versatile python framework for tomographic imaging
https://tomographicimaging.github.io/CIL/
Apache License 2.0
98 stars 45 forks source link

How to use ring remover? #1923

Closed Cosme-liu closed 1 month ago

Cosme-liu commented 2 months ago

Description

I try to use cil.processors.RingRemover to pre-process the normalized data, but I find that there is no guidance in cil website. And I try to invoke this function, but something go wrong.

Code

proj = TIFFStackReader(file_name=path_input)
ag = AcquisitionGeometry.create_Parallel3D(detector_position=[0,1500,0])\
    .set_panel(num_pixels=[755,450])\
    .set_angles(angles=np.linspace(0,180,1080))
pj = proj.read_as_AcquisitionData(ag)
removering = RingRemover(decNum = 4, wname= 'db10', sigma = 1.5)
removering.set_input(pj)
pj_clean = removering.get_output()

The info of input data pj:

Number of dimensions: 3
Shape: (1080, 450, 755)
Axis labels: ('angle', 'vertical', 'horizontal')

Error

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[34], line 3
      1 removering = RingRemover(decNum = 4, wname= 'db10', sigma = 1.5)
      2 removering.set_input(pj)
----> 3 pj_clean = removering.get_output()

File E:\anaconda3\envs\cil-demos\lib\site-packages\cil\framework\framework.py:3743, in Processor.get_output(self, out)
   3741 if self.output is None or self.shouldRun:
   3742     if out is None:
-> 3743         out = self.process()
   3744     else:
   3745         self.process(out=out)

File E:\anaconda3\envs\cil-demos\lib\site-packages\cil\processors\RingRemover.py:96, in RingRemover.process(self, out)
     94     for i in range(vertical):
     95         tmp_corrected = self.xRemoveStripesVertical(data.get_slice(vertical=i, force=True).as_array(), decNum, wname, sigma) 
---> 96         out.fill(tmp_corrected, vertical = i)  
     98 # for 2D data
     99 else:
    100     tmp_corrected = self.xRemoveStripesVertical(data.as_array(), decNum, wname, sigma)

File E:\anaconda3\envs\cil-demos\lib\site-packages\cil\framework\framework.py:2884, in DataContainer.fill(self, array, **dimension)
   2882 else:
   2883     raise TypeError('Can fill only with number, numpy array or DataContainer and subclasses. Got {}'.format(type(array)))
-> 2884 exec(command)

File <string>:1

ValueError: could not broadcast input array from shape (1080,756) into shape (1080,755)
MargaretDuff commented 2 months ago

Hi @Cosme-liu - many thanks for your contribution to CIL!

Please can you confirm which version of CIL you are using e.g. using

import cil, sys
print(cil.version.version, cil.version.commit_hash, sys.version, sys.platform)

We think we had a fix in this PR for the change in shape: https://github.com/TomographicImaging/CIL/issues/1603

Cosme-liu commented 2 months ago

Hi @Cosme-liu - many thanks for your contribution to CIL!

Please can you confirm which version of CIL you are using e.g. using

import cil, sys
print(cil.version.version, cil.version.commit_hash, sys.version, sys.platform)

We think we had a fix in this PR for the change in shape: #1603

The CIL version is 22.2.0

MargaretDuff commented 2 months ago

@Cosme-liu - Please could you try updating to a later version of CIL e.g. 24.1. That should fix the difference in array shape issue.

Cosme-liu commented 2 months ago

@MargaretDuff I update to 24.0.0, the RingRemover works, but another error appears when I try to reconstruct using tigre.

Code:

recon = FBP(pj_center,filter = 'shepp-logan', backend= 'tigre')
output = recon.run()

Error:

File E:\anaconda3\envs\cil\lib\os.py:680, in _Environ.__getitem__(self, key)
    677     value = self._data[self.encodekey(key)]
    678 except KeyError:
    679     # raise KeyError with the original key value
--> 680     raise KeyError(key) from None
    681 return self.decodevalue(value)

KeyError: 'CUDA_PATH'
MargaretDuff commented 2 months ago

Thanks @Cosme-liu! Good news that the update helped with the ring remover. Does the command nvidia-smi work on the machine/environment you are using?

Cosme-liu commented 2 months ago

@MargaretDuff the command works.

image

paskino commented 2 months ago

This error on Windows has been noticed already, see the thread https://github.com/TomographicImaging/CIL/issues/1596 and https://github.com/TomographicImaging/TIGRE-conda/issues/7

A couple of solutions are proposed:

  1. install the CUDA toolkit directly from NVIDIA, https://github.com/TomographicImaging/CIL/issues/1596#issuecomment-1827526888.
  2. using an activation script for conda every time an environment is used, https://github.com/TomographicImaging/CIL/issues/1596#issuecomment-1825580813
  3. conda env config vars set CUDA_PATH="X", https://github.com/TomographicImaging/TIGRE-conda/issues/7#issuecomment-2025439783
Cosme-liu commented 2 months ago

@paskino I tried the third method that typing conda env config vars set CUDA_PATH="X", but it didn't work and raised an error:

File E:\anaconda3\envs\cil\lib\site-packages\tigre\__init__.py:19
     17     # The user must install the CUDA Toolkit
     18     cuda_bin = os.path.join(os.environ["CUDA_PATH"], "bin")
---> 19     os.add_dll_directory(cuda_bin)
     21 from .utilities.geometry import geometry
     22 from .utilities.geometry_default import ConeGeometryDefault as geometry_default

File E:\anaconda3\envs\cil\lib\os.py:1118, in add_dll_directory(path)
   1108 """Add a path to the DLL search path.
   1109 
   1110 This search path is used when resolving dependencies for imported
   (...)
   1115 using it in a with statement.
   1116 """
   1117 import nt
-> 1118 cookie = nt._add_dll_directory(path)
   1119 return _AddedDllDirectory(
   1120     path,
   1121     cookie,
   1122     nt._remove_dll_directory
   1123 )

OSError: [WinError 87] PARAMETER ERROR: 'X\\bin'

Now I don't know how to reset the parameter, should I reinstall CIL and try again?

gfardell commented 2 months ago

@Cosme-liu This has been fixed very recently in the windows build with CIL version 2.4.1 and TIGRE 2.6. Can you try creating a fresh environment using our instructions here https://github.com/TomographicImaging/CIL?tab=readme-ov-file#conda and let us know how you get on.