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

Save output with the same format as brainreg #66

Merged
merged 40 commits into from
Jan 10, 2025

Conversation

IgorTatarnikov
Copy link
Member

@IgorTatarnikov IgorTatarnikov commented Dec 17, 2024

Before submitting a pull request (PR), please read the contributing guide.

Please fill out as much of this template as you can, but if you have any problems or questions, just leave a comment and we will help out :)

Description

What is this PR

  • Bug fix
  • Addition of a new feature
  • Other

Why is this PR needed?
Currently, the output of brainglobe-registration are displayed in the napari viewer but not saved anywhere.

What does this PR do?
This PR adds functionality to save the outputs to a specified output_directory. The forward and backward elastix parameters are saved, along with files equivalent to brainreg.

Refactored elastix/register.py.

Added a function to remap values greater than 216 to consecutive values starting at 216. This prevents floating point errors when transforming using transformix as ITK only supports float32 and not float64 in the pypi wheels. The changes are reverted following transformation.

Added expected outputs that can be used for regression testing.

References

#63

How has this PR been tested?

Added tests for new functionality.

Is this a breaking change?

No

Does this PR require an update to the documentation?

Yes, will come later.

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality (unit & integration)
  • The code has been formatted with pre-commit

@IgorTatarnikov IgorTatarnikov changed the title Save output to the same output as brainreg Save output with the same format as brainreg Dec 17, 2024
Copy link

codecov bot commented Dec 17, 2024

Codecov Report

Attention: Patch coverage is 70.16575% with 54 lines in your changes missing coverage. Please review.

Project coverage is 81.02%. Comparing base (123b25b) to head (4e276f3).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
brainglobe_registration/registration_widget.py 46.15% 35 Missing ⚠️
brainglobe_registration/utils/utils.py 74.54% 14 Missing ⚠️
brainglobe_registration/elastix/register.py 92.15% 4 Missing ⚠️
...e_registration/widgets/adjust_moving_image_view.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #66      +/-   ##
==========================================
- Coverage   82.09%   81.02%   -1.07%     
==========================================
  Files           9        9              
  Lines         592      738     +146     
==========================================
+ Hits          486      598     +112     
- Misses        106      140      +34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@IgorTatarnikov IgorTatarnikov marked this pull request as ready for review January 2, 2025 13:58
@IgorTatarnikov IgorTatarnikov requested a review from a team January 2, 2025 14:28
@adamltyson
Copy link
Member

Looks nice, is the plan for this to allow compatibility with other tools that expect a brainreg output? If so, I think the next step should be to add a loader for brainglobe-napari-io, and then look into adding suport in brainglobe-segmentation and brainmapper.

@IgorTatarnikov
Copy link
Member Author

That's the plan, I'll look into adding a loader for brianglobe-napari-io!

Copy link
Member

@adamltyson adamltyson left a comment

Choose a reason for hiding this comment

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

Very nice. A couple of suggestions/thoughts:

  • The output directory should have some kind of specific identifier that it came from brainglobe-registration. If we’re modelling the output on brainreg, it should be a brainglobe-registration.json that stores registration metadata. This will then “tell” brainglobe-napari-io that it can load the directory, and how it should load it.
  • I’m not sure about the workflow where the user specifies an output directory if they want the results to be saved. I can see a likely scenario in which the user runs registration (which may take a while), but they don’t save it. They may expect to be able to save it after running, but they cannot. I think it should be made more obvious how to save the outputs (it’s currently one part of a very large widget), or it should be possible to save the output after registration. I think this can wait for a new PR though.

for i in range(len(parameter_lists))
]

itk.ParameterObject.WriteParameterFile(
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to use pathlib here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried using pathlib but ITK wants a string, and crashes otherwise. It felt a bit convoluted to create a bunch of Path objects just to convert them back to strings before using them.

transformix_object.GetOutputDeformationField()
)[..., ::-1]

# Cleanup files generated by elastix
Copy link
Member

Choose a reason for hiding this comment

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

Is there any conceivable reason to keep these files, e.g. in a "Debug" mode that could be chosen by the user?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure, the generated file is the deformation field saved in (x, y, z) rather than (z, y, x). I'll add a debug flag to the Python API but won't expose it via the widget at this time.

@IgorTatarnikov
Copy link
Member Author

Agreed on both points. Important configurations are now saved in a brainglobe-registration.json. I'll make the output directory mandatory for now to avoid registering and not saving the results.

@IgorTatarnikov IgorTatarnikov merged commit 408a3e6 into main Jan 10, 2025
11 of 13 checks passed
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.

2 participants