-
-
Notifications
You must be signed in to change notification settings - Fork 591
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
Add OpenCV as an option for rotation #6089
Conversation
Hey @ayshih ! Thanks for digging out my old PR and incorporating it into your |
Rats, my implementation isn't working correctly on non-square pixels... Stay tuned |
The bug with rotating by a PCij matrix that is not a pure rotation has been fixed. It's neat that parametrizing a figure test works. The figure-test CI builds are currently failing due to a bug that is present in the latest stable release of |
There is a quirk in my implementation here where I allow for This may be an opportune time to reconsider the change in #1185 (by me, for SunPy 0.7!), and perhaps revert back to a default of |
I went ahead and switched |
b9e2aef
to
84981c4
Compare
sunpy/image/transform.py
Outdated
@@ -325,8 +346,58 @@ def _rotation_skimage(image, matrix, shift, order, missing, clip): | |||
return rotated_image | |||
|
|||
|
|||
@add_rotation_function("cv2", allowed_orders={0, 1, 3}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 'cv2'
and not 'opencv'
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<shrug> Extrapolating from the single point of 'skimage'
instead of 'scikit-image'
, it seems that we are preferring the import name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also like "cv2" over "opencv".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't like "cv2" it's completely impenetrable to people who haven't used opencv before, unlike opencv it doesn't give you sensible things when you search for it (unlike skimage which is the first result). While it might be the module name, I would argue that whoever decided that you should do import cv2
was also not of sound mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I recall correctly, the reason that the package is called cv2
is because they changed the API from their original cv
package. It has nothing to do with the version of OpenCV.
If we want, we could actually support both 'cv2'
and 'opencv'
. We could also support both 'skimage'
and 'scikit-image'
. Why not!
I added an initial commit that preserves @cbard's authorship at some level. I added (potentially objectionable) scraping of the OpenCV docs to construct the link to their docstring for |
I'll point out that even though the figure-test CI builds are crashing (with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - I've left some comments that shouldn't block feature freeze, so if they aren't read/replied to by this afternoon I will merge this and open a new issue with my comments.
# In the event of any failure (e.g., no network connectivity) | ||
warpAffine_full = "" | ||
|
||
rst_epilog = f""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Putting this at the end of every .rst file seems a bit much - I presume there's not an easy way to put this just on the pages that it's needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not particularly an issue putting it everywhere, and putting it everywhere means that you don't have to do anything to use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A different approach would be to programmatically add it to the specific docstring where it is needed, but that would be fiddly if we ever rename the function or want to use the shortcut in more places. If this showed up in the rendered pages, it'd of course be untenable, but it's essentially invisible to the reader.
@pytest.mark.parametrize('order', range(6)) | ||
def test_endian(method, order, rot30): | ||
if order not in _rotation_registry[method].allowed_orders: | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do a pytest.skip
with a suitable message here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yes, that could be done, but wouldn't that just add noise to the short summary of every test run? There'd always be skips reported because these orders are simply not supported. I'm inclined to consider them passes rather than skips.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am with Albert on this, adding more skip test results at the end of the test output is not something I support especially since we might never be able to unskip them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am really struggling to get past cv2
over opencv
, and the arguments to add_rotation_function
should be keyword only arguments.
As discussed on Element, the rotation method names have been changed from |
Thanks to everyone here for their work in getting OpenCV into Sunpy! I also want to acknowledge Raphael Attie (@WaaallEEE), whose work during the HelioHackweek2020 demonstrated the utility of OpenCV as a worthwhile alternative to skimage and scipy and led me to create the original PR #4502. |
affine_transform()
andGenericMap.rotate()
#5867, this PR adds OpenCV as an option for rotating images or maps (by specifyingmethod='cv2'
). This closes OpenCV as alternative library for map.image.affine_transform #4478. See also Changes tomap.rotate
: Compatibility with custom affine_transforms viamethod=
argument #4502 and Update affine_transform with openCV support #6071.GenericMap.rotate()
from 4 to 3order
part of the rotation-function registrationTo do:
cv2.warpAffine()
Fix the bug inBug is present inpytest-mpl
for generating the HTML summary when an image comparison fails due to a mismatch in image dimensionspytest-mpl
0.14.0, but is not present in the dev branch.