Skip to content

Allow array alpha for imshow #8183

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

Closed
wants to merge 10 commits into from

Conversation

tillahoffmann
Copy link
Contributor

@tillahoffmann tillahoffmann commented Mar 2, 2017

This PR allows the alpha argument of imshow to be an array with shape matching the image to support pixel-by-pixel opacity.

@dstansby
Copy link
Member

dstansby commented Mar 2, 2017

Thanks for submitting this, it looks like a good improvement!

A couple of things that need to be fixed:

There's lots of information that should cover the above at http://matplotlib.org/devel/index.html - let us know if you need any help with anything though.

@dstansby dstansby added this to the 2.1 (next point release) milestone Mar 2, 2017
@@ -419,14 +428,18 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
# colormapping works correctly
hid_output = output
output = np.ma.masked_array(
hid_output[..., 0], hid_output[..., 3] < 0.5)
hid_output[..., 0], hid_output[..., 3] == 0)
Copy link
Member

Choose a reason for hiding this comment

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

I think this is going to break a test, but may fix an issue that @QuLogic found with imshow after #8024

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this line is indeed causing the problem. In particular, the alpha channel is interpolated near the boundary of an image. The < 0.5 implementation will set pixels that are "more than half transparent" to fully transparent whereas the == 0 implementation only treats them as masked if they are fully transparent.

In short, the boundaries in a few tests differ slightly.

rotate_image-failed-diff

I believe the == 0 implementation is preferable because it effectively provides anti aliasing on the boundary by restoring the alpha channel. Here is a zoomed-in example.

screen shot 2017-03-03 at 15 03 01
screen shot 2017-03-03 at 15 03 06

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, but this causes trouble if there are bad data in image. For example, bad values in one of the tests are shown as blue. If we restore the alpha channel, all bad blue values will become transparent. As a compromise, I have rerendered the problematic images (changes only occur at the boundary) and I only restore the alpha channel if _array_alpha is given.

@tacaswell
Copy link
Member

I have to run to dinner, but I suspect the ==0 change is what is breaking the tests, which should be pulled out into it's own PR and put (with re-rendering the tests) on 2.0.x.

@QuLogic
Copy link
Member

QuLogic commented Mar 7, 2017

Please rebase instead of merging, and don't make extra empty commits just to trigger CI.

@dstansby
Copy link
Member

dstansby commented Mar 7, 2017

FYI, we (members of the matplotlib organisation) can manually trigger CI if needed, and you should be able to manually trigger it on your own fork.

@tillahoffmann
Copy link
Contributor Author

Ok, will do that in the future.

@tacaswell tacaswell self-assigned this Mar 8, 2017
@tacaswell
Copy link
Member

Please leave this one for me to review / merge.

@tacaswell tacaswell modified the milestones: 2.1 (next point release), 2.2 (next next feature release) Aug 29, 2017
@jklymak
Copy link
Member

jklymak commented Jul 16, 2019

This looks useful, but fell under the radar. @tillahoffmann do you have the bandwidth to rebase, and we can try and resurrect? If no one touches it for a while, please ping (and re-ping). Sorry for the lack of response here.

@tillahoffmann
Copy link
Contributor Author

tillahoffmann commented Jul 25, 2019

Will close this one and send a new PR because the implementation has changed enough to make a new implementation easier.

@jklymak
Copy link
Member

jklymak commented Jul 25, 2019

Don’t be shy at harassing us

@tacaswell
Copy link
Member

🐑 I thought this had gone in already! This one is definitely on me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants