<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body 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('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>
<br>
<div class="moz-cite-prefix">On 07/12/16 04:41, wine lover wrote:<br>
</div>
<blockquote
cite="mid:CAFyUc2DqUB9OuOCAizx3+JEO3YfrkAK2VPdC6jTp4M3myBKHVw@mail.gmail.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<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="gmail-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="gmail-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="gmail-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="gmail-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="gmail-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="gmail-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="gmail-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’,temp_mask)</span></code><span
class="gmail-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="gmail-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="gmail-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="gmail-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="gmail-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="gmail-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="gmail-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="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
scikit-image mailing list
<a class="moz-txt-link-abbreviated" href="mailto:scikit-image@python.org">scikit-image@python.org</a>
<a class="moz-txt-link-freetext" href="https://mail.python.org/mailman/listinfo/scikit-image">https://mail.python.org/mailman/listinfo/scikit-image</a>
</pre>
</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></body>
</html>