-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Raise warning and downsample if data given to _image.resample is too large #19368
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
Conversation
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.
We can accurately downsample so I don't think we should error here. An aliased downsampled image is still zoomable, at which point the aliasing will go away. If the image is above 2**23 we should just subsample by a factor of 2 and warn.
👍 - for subsampling, would you recommend just doing |
I think we want |
Yep, my comment was modulo finding the right stride, but just wanted to double check that striding was the correct approach. |
The right approach is open to debate, in that you could anti-alias the data before hitting it with a stride. But for such a massive subsample, I think a simple stride is better than an unspecified overflow/wrap! |
5f1773c
to
1fd6269
Compare
40b5664
to
a81575c
Compare
Why do we bother to downsample at all? We cannot display more than N pixels and should refuse to accept more (In the face of ambiguity refuse the temptation to guess). If a user has more data, it's their responsibility and competence to reduce them. |
I'm happy to go either way - perhaps worth discussing on a dev call and coming back with a decision? |
We almost always resample so I don't see the problem with reducing the data before trying the final resample step. This will be aliased, but a max-sized image will also be aliased by the final downsample, so I doubt it would be detectable. |
I am 👍🏻 in favor of this. |
As discussed on the call, we should go ahead and subsample and warn, which I think is what this PR does. |
👍 - I still need to add a test for resampling the columns that's similar to the existing one for rows |
60a3373
to
cecd991
Compare
This should be good for review now. Tests and an API note added. |
d38e82c
to
525cd0c
Compare
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.
Sorry to let this languish. I think this looks good.
lib/matplotlib/image.py
Outdated
if data.shape[1] > 2**23: | ||
warnings.warn(msg.format(n='2**23 rows')) | ||
step = int(np.ceil(data.shape[1] / 2**23)) | ||
data = data[:, ::step] | ||
transform = Affine2D().scale(step, 1) + transform | ||
if data.shape[0] > 2**24: | ||
warnings.warn(msg.format(n='2**24 columns')) | ||
step = int(np.ceil(data.shape[0] / 2**24)) | ||
data = data[::step, :] | ||
transform = Affine2D().scale(1, step) + transform |
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.
0 is the rows, 1 is the columns; you have the message swapped. I don't know if the limits should be swapped as well.
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.
Thanks - I checked the limits and they are correct, just the message that needed changing.
525cd0c
to
a9d28f3
Compare
Needs rebase for docs to work. |
a9d28f3
to
468b72c
Compare
power-cycled to pick up the CI config from main. |
Fixes #19276. This still needs: