<div dir="ltr">Dear All,<div><br></div><div><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif">I have a tif images, its type is <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">float32</code>, shape is <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">(128*128)</code> (a grayscale image). All the pixel values are of range <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">[0.0, 1.0]</code></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif"> I am trying to read it using <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">skimage</code> and show it on screen using <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">matplotlib</code>. </p><pre class="gmail-lang-py gmail-prettyprint gmail-prettyprinted" style="margin-top:0px;margin-bottom:1em;padding:5px;border:0px;font-size:13px;width:auto;max-height:600px;overflow:auto;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);color:rgb(57,51,24);word-wrap:normal"><code style="margin:0px;padding:0px;border:0px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;white-space:inherit"><span class="gmail-kwd" style="margin:0px;padding:0px;border:0px;color:rgb(16,16,148)">from</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> skimage </span><span class="gmail-kwd" style="margin:0px;padding:0px;border:0px;color:rgb(16,16,148)">import</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> io
</span><span class="gmail-kwd" style="margin:0px;padding:0px;border:0px;color:rgb(16,16,148)">import</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> matplotlib</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">.</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">pyplot </span><span class="gmail-kwd" style="margin:0px;padding:0px;border:0px;color:rgb(16,16,148)">as</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> plt
output</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">=</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">io</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">.</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">imread</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">(</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">os</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">.</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">path</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">.</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">join</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">(</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">image_path</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">,</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">raw_image_name</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">))</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
</span><span class="gmail-kwd" style="margin:0px;padding:0px;border:0px;color:rgb(16,16,148)">print</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">(</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">output</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">.</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">dtype</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">)</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
</span><span class="gmail-kwd" style="margin:0px;padding:0px;border:0px;color:rgb(16,16,148)">print</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">(</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">output</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">.</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">shape</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">)</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
</span><span class="gmail-kwd" style="margin:0px;padding:0px;border:0px;color:rgb(16,16,148)">print</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">(</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">output</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">.</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">max</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">())</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
</span><span class="gmail-kwd" style="margin:0px;padding:0px;border:0px;color:rgb(16,16,148)">print</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">(</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">output</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">.</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">min</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">())</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
plt</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">.</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">imshow</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">(</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">output</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">)</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
plt</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">.</span><span class="gmail-pln" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">show</span><span class="gmail-pun" style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">()</span></code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif">The output image looks like color image instead of gray image as shown originally. I attached the screenshot as the capture-1.jpg.<br></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif"><span style="font-family:arial,"helvetica neue",helvetica,sans-serif">However, when I read the image using </span><code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">matplotlib</code><span style="font-family:arial,"helvetica neue",helvetica,sans-serif"> instead,i.e., </span><code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">output=plt.imread(os.path.join(image_path,raw_image_name))</code><span style="font-family:arial,"helvetica neue",helvetica,sans-serif">. 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.</span></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif">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, <br></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif"><br></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif">Thanks,</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif">Yuanyuan</p></div></div>