[scikit-image] pixel value changes during reading image and showing images using skimage and matplotlib

Imanol Luengo imanol.luengo at nottingham.ac.uk
Sun Dec 11 05:54:49 EST 2016


Dear Yuanyuan,

The reason why you are looking at a *color* image is due to the colormaps:

http://matplotlib.org/users/colormaps.html

The default colormap (to map from numbers to colors) is not grayscale, 
as matplotlib is not primarly focus on images, and grayscale is not an 
*adequate* colormap to represent other types of plots.

To properly visualize your image specify a colormap to the plot function:

      plt.imshow(output, 'gray')

Cheers,

Imanol


On 11/12/16 06:46, wine lover wrote:
> Dear All,
>
> I have a tif images, its type is |float32|, shape is |(128*128)| (a 
> grayscale image). All the pixel values are of range |[0.0, 1.0]|
>
>  I am trying to read it using |skimage| and show it on screen using 
> |matplotlib|.
>
> |fromskimage importio importmatplotlib.pyplot asplt 
> output=io.imread(os.path.join(image_path,raw_image_name))print(output.dtype)print(output.shape)print(output.max())print(output.min())plt.imshow(output)plt.show()|
>
> The output image looks like color image instead of gray image as shown 
> originally. I attached the screenshot as the capture-1.jpg.
>
> However, when I read the image using |matplotlib| instead,i.e., 
> |output=plt.imread(os.path.join(image_path,raw_image_name))|. I found 
> that pixel value will become 255 and 0. The dtype is still float32. 
> But when I print output, the pixel values are either 0. or 255.
>
> The output image will become black as shown in the second image 
> (capture-2.jpg). I am confused how does this work? My guess is that 
> there are some dtype changes happening during the reading image and 
> showing image,
>
>
> Thanks,
>
> Yuanyuan
>
>
>
> _______________________________________________
> scikit-image mailing list
> scikit-image at python.org
> https://mail.python.org/mailman/listinfo/scikit-image





This message and any attachment are intended solely for the addressee
and may contain confidential information. If you have received this
message in error, please send it back to me, and immediately delete it. 

Please do not use, copy or disclose the information contained in this
message or in any attachment.  Any views or opinions expressed by the
author of this email do not necessarily reflect the views of the
University of Nottingham.

This message has been checked for viruses but the contents of an
attachment may still contain software viruses which could damage your
computer system, you are advised to perform your own checks. Email
communications with the University of Nottingham may be monitored as
permitted by UK legislation.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20161211/5fa62ae6/attachment.html>


More information about the scikit-image mailing list