-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
matplotlib.pyplot.imread silently fails on uint16 images. #3616
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
Comments
Could you double-check with matplotlib 1.4.0? I think this might have already been fixed. |
@WeatherGod No such luck: In [1]: import matplotlib as mpl
In [2]: mpl.pyplot.imread('Desktop/io3.png')
Out[2]:
array([[ 0. , 0.00392157],
[ 0. , 0.39215687]], dtype=float32)
In [3]: mpl.__version__
Out[3]: u'1.4.0' |
BLEURG! I had a horrible thought and it seems to have panned out: the In [1]: from skimage import io
In [4]: io.imread('Desktop/io3.png', plugin='pil')
Out[4]:
array([[ 0, 1],
[ 0, 100]], dtype=uint8) I'll investigate further... |
Looks like there is a lot of IO voodoo going on everywhere: In [8]: mpl.pyplot.imsave('io4.png', np.array([[0, 1], [0, 4196]], dtype=np.uint16))
In [9]: mpl.pyplot.imread('io4.png')
Out[9]:
array([[[ 0. , 0. , 0.49803922, 1. ],
[ 0. , 0. , 0.49803922, 1. ]],
[[ 0. , 0. , 0.49803922, 1. ],
[ 0.49803922, 0. , 0. , 1. ]]], dtype=float32)
In [10]: im4 = mpl.pyplot.imread('io4.png')
In [11]: im4.shape
Out[11]: (2, 2, 4)
In [12]: np.rollaxis(im4, -1) # display the three channels + alpha of the array
Out[12]:
array([[[ 0. , 0. ],
[ 0. , 0.49803922]],
[[ 0. , 0. ],
[ 0. , 0. ]],
[[ 0.49803922, 0.49803922],
[ 0.49803922, 0. ]],
[[ 1. , 1. ],
[ 1. , 1. ]]], dtype=float32) That save/read roundtrip outcome seems highly undesirable! |
That's hilarious, looking at the actual image I just realised what happened: mpl silently remapped the uint16 values to Jet and then saved that! |
Jet strikes again! "With my last breath, I curse Jet!" On Fri, Oct 3, 2014 at 10:31 PM, Juan Nunez-Iglesias <
|
The uint16 array is not a valid input for |
@cgohlke that should change soon, but thanks for the pointer! =) |
So, if I'm reading the above correctly, this is not an issue with matplotlib's imread, but skimage.io.imsave? Should we close this then? |
@mdboom well, that "saving as jet" thing is bugging me to no end, but perhaps that belongs in a separate issue? |
@tacaswell that's not really the right issue. The issue is colormapping a grayscale image at save time instead of either saving it as-is or raising an error. It's the colormapping that's the problem, not jet. (Jet is the icing on the cake.) Should I raise a new issue? |
In that case, yes. |
It assumes the image is uint8 and incorrectly wraps the input at 255:
The text was updated successfully, but these errors were encountered: