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

Showing np.uint16 images of the form (h,w,3) is broken #2499

Closed
luispedro opened this issue Oct 6, 2013 · 4 comments
Closed

Showing np.uint16 images of the form (h,w,3) is broken #2499

luispedro opened this issue Oct 6, 2013 · 4 comments
Assignees
Milestone

Comments

@luispedro
Copy link
Contributor

Here is a simple test case:

import matplotlib.pyplot as plt
import numpy as np
A = np.array([np.arange(256,dtype=np.uint16) for _ in xrange(256)])
B =  (A<<8)+(255*np.random.random(A.shape)).astype(np.uint16)
B = np.dstack([B,B,B])
plt.imshow(B)
plt.show()

This results in random bits.

The problem is in file lib/matplotlib.cm.py: the conversion to np.uint8 assumes that the input is in 0..1 format.

@tacaswell
Copy link
Member

To be fair, the docs (http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.imshow) only claim to support float or uint8 so I would not call this broken.

@luispedro
Copy link
Contributor Author

Then, maybe the real bug is that it doesn't raise an exception :)

It's certainly surprising behaviour.

luispedro added a commit to luispedro/matplotlib that referenced this issue Oct 8, 2013
Arrays of non-uint8 types were assumed to be in 0..1 range, resulting in
the small bits being showing when this was not true. Now, an explicit
exception is raised.

Closes issue matplotlib#2499
@tacaswell
Copy link
Member

@luispedro Can you make a PR with that fix?

luispedro added a commit to luispedro/matplotlib that referenced this issue Nov 30, 2013
Arrays of non-uint8 types were assumed to be in 0..1 range, resulting in
the small bits being showing when this was not true. Now, an explicit
exception is raised.

Closes issue matplotlib#2499
luispedro added a commit to luispedro/matplotlib that referenced this issue Nov 30, 2013
Arrays of non-uint8 types were assumed to be in 0..1 range.

When this was not true and integer values were used, only the low-order
bits were used, resulting in a mangled image. Now, an explicit exception
is raised.

Closes issue matplotlib#2499
@tacaswell tacaswell added this to the v1.5.x milestone Aug 17, 2014
efiring pushed a commit to efiring/matplotlib that referenced this issue Mar 7, 2016
Arrays of non-uint8 types were assumed to be in 0..1 range.

When this was not true and integer values were used, only the low-order
bits were used, resulting in a mangled image. Now, an explicit exception
is raised.

Closes issue matplotlib#2499
efiring added a commit to efiring/matplotlib that referenced this issue Mar 7, 2016
@efiring efiring self-assigned this Mar 7, 2016
tacaswell added a commit that referenced this issue Mar 7, 2016
MNT: improve image array argument checking in to_rgba. Closes #2499.
@tacaswell
Copy link
Member

@luispedro Thanks, sorry this took so long to get resolved.

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

No branches or pull requests

3 participants