Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Paganin processor work with one angle #1920

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Make Binner accept accelerated=False (#1887)
- Changes that break backwards compatibility:
- CGLS will no longer automatically stop iterations once a default tolerance is reached. The option to pass `tolerance` will be deprecated to be replaced by `optimisation.utilities.callbacks` (#1892)
- Make Paganin Processor work with AcquistionData with one angle (#1920)

* 24.1.0
- New Features:
Expand Down
34 changes: 21 additions & 13 deletions Wrappers/Python/cil/processors/PaganinProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,11 @@ def process(self, out=None):

# make slice indices to get the projection
slice_proj = [slice(None)]*len(data.shape)
angle_axis = data.get_dimension_axis('angle')
slice_proj[angle_axis] = 0
if 'angle' in data.dimension_labels:
angle_axis = data.get_dimension_axis('angle')
slice_proj[angle_axis] = 0
else:
angle_axis = None

if data.geometry.channels>1:
channel_axis = data.get_dimension_axis('channel')
Expand All @@ -236,18 +239,16 @@ def process(self, out=None):
data_proj = data.as_array()[tuple(slice_proj)]

# create an empty axis if the data is 2D
if len(data.shape) == 2:
if data.geometry.dimension == '2D':
data.array = np.expand_dims(data.array, len(data.shape))
slice_proj.append(slice(None))
data_proj = data.as_array()[tuple(slice_proj)]
if len(out.shape) == 2:
out.array = np.expand_dims(out.array, len(out.shape))

elif len(data_proj.shape) == 2:
pass
else:
if len(data_proj.shape) != 2:
raise(ValueError('Data must be 2D or 3D per channel'))

if len(out.shape) == 2:
out.array = np.expand_dims(out.array, len(out.shape))

# create a filter based on the shape of the data
filter_shape = np.shape(data_proj)
Expand Down Expand Up @@ -275,7 +276,8 @@ def process(self, out=None):
# loop over the projections
for i in tqdm(range(len(data.geometry.angles))):

slice_proj[angle_axis] = i
if angle_axis is not None:
slice_proj[angle_axis] = i
padded_buffer.fill(0)
padded_buffer[slice_pad] = data.array[(tuple(slice_proj))]

Expand All @@ -294,11 +296,17 @@ def process(self, out=None):
padded_buffer[:] = ifft2(fI*self.filter).real

if data.geometry.channels>1:
out.fill(padded_buffer[slice_pad], angle = i,
channel=j)
if len(data.geometry.angles)>1:
out.fill(padded_buffer[slice_pad], angle = i,
channel=j)
else:
out.fill(padded_buffer[slice_pad], channel=j)
else:
out.fill(padded_buffer[slice_pad], angle = i)

if len(data.geometry.angles)>1:
out.fill(padded_buffer[slice_pad], angle = i)
else:
out.fill(padded_buffer[slice_pad])

data.array = np.squeeze(data.array)
out.array = np.squeeze(out.array)
return out
Expand Down
23 changes: 23 additions & 0 deletions Wrappers/Python/test/test_DataProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3085,6 +3085,29 @@ def test_PaganinProcessor_2D(self):
output = processor.get_output(override_geometry={'propagation_distance':1})
self.assertLessEqual(quality_measures.mse(output, thickness), 0.05)

def test_PaganinProcessor_1angle(self):
data = self.data_cone.get_slice(angle=1)
data.geometry.config.units = 'm'
wavelength = (constants.h*constants.speed_of_light)/(40000*constants.electron_volt)
mu = 4.0*numpy.pi*1e-2/(wavelength)
thickness = -(1/mu)*numpy.log(data)

processor = PaganinProcessor(pad=10)
processor.set_input(data)
output = processor.get_output(override_geometry={'propagation_distance':1})
self.assertLessEqual(quality_measures.mse(output, thickness), 0.05)

# check with different data order
data.reorder(('horizontal','vertical'))
wavelength = (constants.h*constants.speed_of_light)/(40000*constants.electron_volt)
mu = 4.0*numpy.pi*1e-2/(wavelength)
thickness = -(1/mu)*numpy.log(data)

processor = PaganinProcessor(pad=10)
processor.set_input(data)
output = processor.get_output(override_geometry={'propagation_distance':1})
self.assertLessEqual(quality_measures.mse(output, thickness), 0.05)


if __name__ == "__main__":

Expand Down
Loading