-
Notifications
You must be signed in to change notification settings - Fork 6
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
Addition of chi2_shift as a Method to calculate Shifts to the "Calculate Registration (image-based)" Task #741
Conversation
…utils.py and add registration docstring to manifest
Hi there, I included a few changes:
@adrtsc can you please review fba4dba? I think the returned object is a list of numpy arrays, but the docstring says "List of tuple of shift in y and x direction.". |
Nice PR @adrtsc , I like the approach you took! I'll leave some comments here while I review this. First one: |
…descriptive ValueError with chi2_shift method
The |
Another thing I've noticed: Pylance type checking isn't happy about the way Literal is used based on a dict in the function definition. See long discussion on the Cellpose issues on this. For Cellpose, we didn't really have a different choice (at least back then, maybe now with Enum support we could also solve it differently?). I'll try switching the |
I'm mostly happy with this PR now, the functionality is useful to have for sure! The last thing I'll want to review but won't manage tonight anymore is the weird typing issue in Given your comment @adrtsc :
It looks like there is some complexity here we don't understand well. I'll want to test the typing we get from the phase_crosscorrelation function and see if we can get that behavior tested. Kind of weird that values need to be rounded to int actually. @adrtsc Do you still have the error traceback you got when not casting those values to a different type? |
@adrtsc Sure, no stress & enjoy your holidays! Sorry also for the delay on my side to look into this PR. I'll try to find some time still to look into the types mentioned above. Maybe I'll manage that before you return from your holidays ;) |
I've tried to test the typing questions more. I don't understand how the original types of See example test here:
Leads to output:
Thus: The output of The casting it to int and then back to float obviously rounds to the next integer. I don't see a harm in rounding to the next integer in general. But I don't understand how it would prevent any kind of error tbh... tl;dr: I don't mind the rounding, but not sure I'd expect it to prevent any errors. Thus, I'd be fine with merging this now after you review @adrtsc . Also fine if we want to dig into anything on the typing here. |
I tested this and it also closes the longstanding #511 through one of my minor changes above |
Finally back from holidays and found some time to look over it!
Looks good, thanks for the updates and catching the wrong return type and error in the docstring. The docstring now also mentions the correct type.
I looked into this again a bit. So it appears that, although returning floats, the phase cross correlation function also rounds the values and always returns whole values. This may be the reason there was never an issue with that function. For now, I think it's safest to leave the rounding in there, as this worked fine so far. Unfortunately, I don't have the error message anymore from back when it failed randomly without rounding the values. I'm fine with all the updates by you guys so from my perspective this is good to go once you've had a final look! |
Great, thanks a lot @adrtsc . I'm merging this to main then and it will become part of the 1.1.0 release of Fractal tasks core :) Thanks for contributing this chi2_shift method back into core! |
The chi2_shift function from the image_registration python package (https://pypi.org/project/image-registration/) was used for a long time for image registration on TissueMAPS and performed very well in a task I had in the APx fractal task collection. After discussions with Joel, we decided that we would like to include that option in the "Calculate Registration (image-based)" task in fractal-tasks-core besides the currently available phase_cross_correlation function.
Happy to receive feedback on things that are still missing or should be cleaned up.
Checklist before merging
CHANGELOG.md