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

Phase contribution #1737

Merged
merged 67 commits into from
Jul 16, 2024
Merged

Phase contribution #1737

merged 67 commits into from
Jul 16, 2024

Conversation

hrobarts
Copy link
Contributor

@hrobarts hrobarts commented Mar 1, 2024

Changes

Add Paganin phase retrieval methods based on the description in https://onlinelibrary.wiley.com/doi/10.1046/j.1365-2818.2002.01010.x

The phase retrieval can be applied using

processor = PaganinProcessor(delta, beta, energy)
processor.set_input(data)
thickness = processor.get_output()

Runs the Paganin method, returning the sample thickness,
$ T = -\frac{1}{\mu}\ln(F^{-1}\frac{F(M^2 I_{norm}(x,y,z=\Delta))}{1+\frac{\Delta\lambda\delta}{4\pi\beta}(k_x^2+k_y^2)})$

Or with the filter_type argument ='generalised_paganin_method' uses the filter described in https://iopscience.iop.org/article/10.1088/2040-8986/abbab9
$ T = -\frac{1}{\mu}\ln(F^{-1}\frac{F(M^2 I_{norm}(x,y,z=\Delta))}{1-\frac{2\Delta\lambda\delta}{4\pi\beta W^2}(cos(Wk_x)+cos(Wk_y)-2)})$

Both methods require normalised transmission data, $I_{norm}$, physical parameters for delta, beta (the real and complex part of the material refractive index) and energy. The propagation distance, $\Delta$, magnification, $M$, and pixel size, $W$, are accessed from the data geometry. If these values are not found in the geometry, the processor prints a warning and uses default values. The geometry values can be over-ridden using

processor = PaganinProcessor(delta, beta, energy)
processor.set_input(data)
processor.get_output(override_geometry={'propagation_distance': 0.1, override_filter={'alpha':1})

We can return only the filtered image using,

processor = PaganinProcessor(delta, beta, energy, full_retrieval=False)
processor.set_input(data)
filtered_image = processor.get_output()

which returns

$ I_{filtered} = F^{-1}\frac{F( I(x,y,z=\Delta))}{1+\frac{\Delta\lambda\delta}{4\pi\beta}(k_x^2+k_y^2)}$

Testing you performed

I've made a pull request to add an example to CIL-Demos/misc using these methods
TomographicImaging/CIL-Demos#151
Below is an output from the notebook showing a comparison of the cross-section of a test image with different phase retrieval methods. The scaled phase retrieval in CIL matches the phase retrieval method in Tomopy when performed on transmission data then converted to absorption, and the filter in CIL matches the Tomopy method performed on absorption data
image
where the Tomopy regularisation parameter argument is tomopy_alpha = 1/(4*np.pi**2*(delta/beta))

Unit tests of the functionality are in test_DataProcessor.py TestPaganinPhaseRetriver() and TestFilter()

Related issues/links

Checklist

  • I have performed a self-review of my code
  • I have added docstrings in line with the guidance in the developer guide
  • I have updated the relevant documentation
  • I have implemented unit tests that cover any new or modified functionality
  • CHANGELOG.md has been updated with any functionality change
  • Request review from all relevant developers
  • Change pull request label to 'Waiting for review'

Contribution Notes

Please read and adhere to the developer guide and local patterns and conventions.

  • The content of this Pull Request (the Contribution) is intentionally submitted for inclusion in CIL (the Work) under the terms and conditions of the Apache-2.0 License
  • I confirm that the contribution does not violate any intellectual property rights of third parties

@hrobarts hrobarts self-assigned this Mar 1, 2024
@jakobsj
Copy link
Contributor

jakobsj commented Mar 4, 2024 via email

@hrobarts
Copy link
Contributor Author

hrobarts commented Mar 4, 2024

Hi Jakob, yes we can avoid it. I thought it already was a dependency but I can remove it if not

@hrobarts hrobarts requested a review from gfardell June 6, 2024 10:13
Copy link
Member

@gfardell gfardell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looking good. Now I've had a good look I think we need to update the units handling here as I've suggested in individual comments. We can discuss this more though.

Otherwise I see some memory issues with the padding, but that's an easy fix.

Wrappers/Python/cil/processors/PaganinProcessor.py Outdated Show resolved Hide resolved
Wrappers/Python/cil/processors/PaganinProcessor.py Outdated Show resolved Hide resolved
Wrappers/Python/cil/processors/PaganinProcessor.py Outdated Show resolved Hide resolved
Wrappers/Python/cil/processors/PaganinProcessor.py Outdated Show resolved Hide resolved
Wrappers/Python/cil/processors/PaganinProcessor.py Outdated Show resolved Hide resolved
@hrobarts hrobarts requested a review from jakobsj June 24, 2024 11:33
Copy link
Contributor

@jakobsj jakobsj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @hrobarts thanks for the update, I am happy with the changes. I added a couple of minor points and also a couple of my previous conversations remain open, could you take a look and respond to each so we can see (and have a record of) what has been done and if can be resolved? Thanks!

Wrappers/Python/cil/processors/PaganinProcessor.py Outdated Show resolved Hide resolved
Wrappers/Python/cil/processors/PaganinProcessor.py Outdated Show resolved Hide resolved
Co-authored-by: Jakob Sauer Jørgensen <[email protected]>
Signed-off-by: Hannah Robarts <[email protected]>
Copy link
Contributor

@jakobsj jakobsj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy with it!

Copy link
Member

@gfardell gfardell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks great! I'm happy once tests pass.

@gfardell gfardell linked an issue Jul 16, 2024 that may be closed by this pull request
@hrobarts hrobarts added Merge pending jenkins Once jenkins is happy with can be merged and removed Waiting for review labels Jul 16, 2024
@gfardell gfardell removed the Merge pending jenkins Once jenkins is happy with can be merged label Jul 16, 2024
@hrobarts hrobarts merged commit 48d89c9 into master Jul 16, 2024
8 checks passed
@hrobarts hrobarts deleted the phase_contribution branch July 16, 2024 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement simple phase contrast retrieval/recon
4 participants