<div dir="ltr"><div><div>What kind of array is "img"? What is its dtype and shape?<br><br></div>plt.imshow() will use the default colormap for matplotlib if the given array is just 2D. But if it is 3D (a 2D array of RGB[A] channels), then it will forego the colormap and utilize that for the colors. It knows nothing of the colormap contained in the TIFF.<br><br></div>Ben Root<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 29, 2016 at 12:31 PM, Henrique Almeida <span dir="ltr"><<a href="mailto:hdante.lnls@gmail.com" target="_blank">hdante.lnls@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Paul, yes, imread() worked for reading the black and white TIFF. The<br>
situation improved, but now, there seems to be some problem with the<br>
color map. Example code:<br>
<br>
#!/usr/bin/env python3<br>
import numpy<br>
from matplotlib import pyplot, cm<br>
<br>
img = pyplot.imread('oi-00.tiff')<br>
pyplot.imshow(img)<br>
pyplot.colorbar()<br>
pyplot.show()<br>
<br>
 The code can open both 1-bit and 8-bit images, but only with 8 bits<br>
the image is shown with the colormap colors. The 1 bit image is shown<br>
as black and white.<br>
<br>
 The questions:<br>
 1) Should Image.open() behave like pyplot.imread() ? Is this a bug in PIL ?<br>
 2) Why isn't the colormap working with black and white images ?<br>
<div class="HOEnZb"><div class="h5"><br>
2016-04-29 13:06 GMT-03:00 Paul Hobson <<a href="mailto:pmhobson@gmail.com">pmhobson@gmail.com</a>>:<br>
> Does using pyplot.imgread work?<br>
><br>
> On Fri, Apr 29, 2016 at 8:27 AM, Henrique Almeida <<a href="mailto:hdante.lnls@gmail.com">hdante.lnls@gmail.com</a>><br>
> wrote:<br>
>><br>
>>  Any help with this problem ?<br>
>><br>
>> 2016-04-27 11:35 GMT-03:00 Henrique Almeida <<a href="mailto:hdante.lnls@gmail.com">hdante.lnls@gmail.com</a>>:<br>
>> >  Hello, what's the current status on numpy for loading bit-arrays ?<br>
>> ><br>
>> > I'm currently unable to correctly load black and white (1-bit) TIFF<br>
>> > images. Code example follows:<br>
>> ><br>
>> > from PIL import Image<br>
>> > import numpy<br>
>> > from matplotlib import pyplot<br>
>> ><br>
>> > img = Image.open('oi-00.tiff')<br>
>> > a = numpy.array(img)<br>
>> ><br>
>> > ^ does not work for 1-bit TIFF images<br>
>> ><br>
>> > PIL source shows that it incorrectly uses typestr == '|b1'. I tried to<br>
>> > change this to '|t1', but I get :<br>
>> ><br>
>> > TypeError: data type "|t1" not understood<br>
>> ><br>
>> > My goal is to make the above code to work for black and white TIFF<br>
>> > images the same way it works for grayscale images. Any help ?<br>
>> _______________________________________________<br>
>> NumPy-Discussion mailing list<br>
>> <a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
>> <a href="https://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> NumPy-Discussion mailing list<br>
> <a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
> <a href="https://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
><br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="https://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</div></div></blockquote></div><br></div>