<div dir="ltr"><p class="MsoNormal">Hi Juan, Hi Imanol,<span></span></p><p class="MsoNormal"><br></p><p class="MsoNormal">Thank you so much for your replies, which are very helpful.<span></span></p><p class="MsoNormal"><br></p><p class="MsoNormal">During saving the image, I got some warning messages such as
follows. What does it indicate?<span></span></p><p class="MsoNormal">/development/lib/python3.4/site-packages/scikit_image-0.12.3-py3.4-linux-x86_64.egg/skimage/io/_io.py:132:
UserWarning: /data/train/image_sampled.tif is a low contrast image                                                                     <span></span></p><p class="MsoNormal">  warn('%s is a low
contrast image' % fname)</p><p class="MsoNormal"><span></span><br>Thanks,<span></span></p><p class="MsoNormal">Yuanyuan</p></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 7, 2016 at 4:54 AM, Imanol Luengo <span dir="ltr"><<a href="mailto:imanol.luengo@nottingham.ac.uk" target="_blank">imanol.luengo@nottingham.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    <p>Hello, <br>
    </p>
    <p>I would say there are two differences between 'Saving the data'
      and 'Displaying the data'. An image is discretized to `uint8` or
      `uint16` prior to being saved as standard formates (`.png` or
      `.jpg`). You could do something like</p>
    ```<br>
    import numpy as np<br>
    from skimage import io, util<br>
    <br>
    A = np.random.rand(100,100)<br>
    io.imsave('tmp.png', A)<br>
    B = util.img_as_float(io.imread('<wbr>tmp.png')<br>
    <br>
    assert np.allclose(A, B) # ERROR<br>
    ```
    <p>But you will find some discretization errors, which makes `B !=
      A`. Having said that, if you want to preserve the data in `B`, I
      think the best option is to export the data using another format,
      e.g. numpy arrays:</p>
    ```<br>
    import numpy as np<br>
    <br>
    A = np.random.rand(100,100)<br>
    np.save('tmp.npy', A)<br>
    B = np.load('tmp.npy')<br>
    <br>
    assert np.allclose(A, B) # True<br>
    ```<br>
    <p>Or alternatively, if you really want to save the data in a
      visualizable format, exporting the image as `.tif` format, which
      preserves data information, should also work:</p>
    ```<br>
    A = np.random.rand(100,100)<br>
    io.imsave('tmp.tif', A)<br>
    B = io.imread('tmp.tif')<br>
    <br>
    assert np.allclose(A, B) # True<br>
    ```<br>
    <p>However, I would personally store my data in non-visualizable
      formats such as `.npy, .h5` (the later if you work with tons of
      data) as they usually offer another advantages (e.g. Datasets in
      HDF5).<br>
    </p>
    <p>Hope it helps,</p>
    <p>Imanol<br>
    </p><div><div class="h5">
    <br>
    <div class="m_-6762154443968081140moz-cite-prefix">On 07/12/16 04:41, wine lover wrote:<br>
    </div>
    </div></div><blockquote type="cite"><div><div class="h5">
      
      <div dir="ltr">
        <p class="MsoNormal"><font color="#242729"><span style="font-size:15.3333px">Dear All, </span></font></p>
        <p class="MsoNormal"><font color="#242729"><span style="font-size:15.3333px"><br>
            </span></font></p>
        <p class="MsoNormal"><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;color:rgb(36,39,41);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">In
            a program, I generate an numpy array, with shape (128,128),
            which is supposed to represent an image. <span></span></span></p>
        <p class="MsoNormal"><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;color:rgb(36,39,41);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">For
            instance, I have<span class="m_-6762154443968081140gmail-apple-converted-space"> </span>an
            array </span><code><span style="font-size:10pt;line-height:115%;font-family:consolas;color:rgb(36,39,41);border:1pt none windowtext;padding:0in;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(239,240,241)">temp_mask</span></code><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;color:rgb(36,39,41);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">,
            which is of type<span class="m_-6762154443968081140gmail-apple-converted-space"> </span></span><code style="white-space:pre-wrap"><span style="font-size:10pt;line-height:115%;font-family:consolas;color:rgb(36,39,41);border:1pt none windowtext;padding:0in;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(239,240,241)">float32 and
shape (128,128)</span></code><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;color:rgb(36,39,41);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">,
            the maximum value is<span class="m_-6762154443968081140gmail-apple-converted-space"> </span></span><code style="white-space:pre-wrap"><span style="font-size:10pt;line-height:115%;font-family:consolas;color:rgb(36,39,41);border:1pt none windowtext;padding:0in;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(239,240,241)">1.0</span></code><span class="m_-6762154443968081140gmail-apple-converted-space"><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;color:rgb(36,39,41);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"> </span><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;color:rgb(36,39,41);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">and
              the minimum value is<span class="m_-6762154443968081140gmail-apple-converted-space"> </span></span></span><code style="white-space:pre-wrap"><span style="font-size:10pt;line-height:115%;font-family:consolas;color:rgb(36,39,41);border:1pt none windowtext;padding:0in;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(239,240,241)">0.0. </span></code><span class="m_-6762154443968081140gmail-apple-converted-space"><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;color:rgb(36,39,41);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"> </span></span><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;color:rgb(36,39,41);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">I
            saved it using<span class="m_-6762154443968081140gmail-apple-converted-space"> </span></span><code style="white-space:pre-wrap"><span style="font-size:10pt;line-height:115%;font-family:consolas;color:rgb(36,39,41);border:1pt none windowtext;padding:0in;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(239,240,241)">io.imsave(‘mask_image’,<wbr>temp_mask)</span></code><span class="m_-6762154443968081140gmail-apple-converted-space"><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;color:rgb(36,39,41);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"> </span><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;color:rgb(36,39,41);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">However,
              after I re-opened this image using<span class="m_-6762154443968081140gmail-apple-converted-space"> </span></span></span><code style="white-space:pre-wrap"><span style="font-size:10pt;line-height:115%;font-family:consolas;color:rgb(36,39,41);border:1pt none windowtext;padding:0in;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(239,240,241)">img_mask =
io.imread(‘mask_image’)</span></code><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;color:rgb(36,39,41);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">.
            The read image turns out to  have type<span class="m_-6762154443968081140gmail-apple-converted-space"> </span></span><code style="white-space:pre-wrap"><span style="font-size:10pt;line-height:115%;font-family:consolas;color:rgb(36,39,41);border:1pt none windowtext;padding:0in;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(239,240,241)">unit16</span></code><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;color:rgb(36,39,41);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">,
            the max value becomes<span class="m_-6762154443968081140gmail-apple-converted-space"> </span></span><code style="white-space:pre-wrap"><span style="font-size:10pt;line-height:115%;font-family:consolas;color:rgb(36,39,41);border:1pt none windowtext;padding:0in;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(239,240,241)">6553</span></code><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;color:rgb(36,39,41);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">5
            and the min value is<span class="m_-6762154443968081140gmail-apple-converted-space"> </span></span><code style="white-space:pre-wrap"><span style="font-size:10pt;line-height:115%;font-family:consolas;color:rgb(36,39,41);border:1pt none windowtext;padding:0in;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(239,240,241)">0</span></code><span class="m_-6762154443968081140gmail-apple-converted-space"><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;color:rgb(36,39,41);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"> . 
              It seems to me that io.imsave automatically transform the
              float32 array into an unit16 array.<span></span></span></span></p>
        <p class="MsoNormal"><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;color:rgb(36,39,41);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">Is
            it possible to save the image while keeping the original
            type? If not, what’s the correct way to save an image
            represented as an array, with type<span class="m_-6762154443968081140gmail-apple-converted-space"> </span></span><code style="white-space:pre-wrap"><span style="font-size:10pt;line-height:115%;font-family:consolas;color:rgb(36,39,41);border:1pt none windowtext;padding:0in;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(239,240,241)">float32</span></code><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;color:rgb(36,39,41);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">
            and the range of value <code><span style="font-size:10pt;line-height:115%;font-family:consolas;border:1pt none windowtext;padding:0in;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;background-color:rgb(239,240,241)">[0.0,1.0]</span></code><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">? </span><span></span></span></p>
        <p class="MsoNormal"><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;color:rgb(36,39,41);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"><br>
            </span></span></p>
        <p class="MsoNormal"><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;color:rgb(36,39,41);background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"><span style="font-size:11.5pt;line-height:115%;font-family:arial,sans-serif;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">Thank
              you very much!</span></span></p>
      </div>
      <br>
      <fieldset class="m_-6762154443968081140mimeAttachmentHeader"></fieldset>
      <br>
      </div></div><span class=""><pre>______________________________<wbr>_________________
scikit-image mailing list
<a class="m_-6762154443968081140moz-txt-link-abbreviated" href="mailto:scikit-image@python.org" target="_blank">scikit-image@python.org</a>
<a class="m_-6762154443968081140moz-txt-link-freetext" href="https://mail.python.org/mailman/listinfo/scikit-image" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/scikit-image</a>
</pre>
    </span></blockquote>
    <br>
  <pre>

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.
</pre></div>

<br>______________________________<wbr>_________________<br>
scikit-image mailing list<br>
<a href="mailto:scikit-image@python.org">scikit-image@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scikit-image" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/scikit-image</a><br>
<br></blockquote></div><br></div>