On 5/26/2013 8:31 PM, Juan Nunez-Iglesias wrote:
> Hey all,
>
> I noticed that some of my microscopy images appeared inverted after
> saving them with skimage.io.imsave. After some testing, here's some of
> the weirdness. My image is called s:
>
> ```python
> In [37]: np.min(s)
> Out[37]: 119
>
> In [38]: np.max(s)
> Out[38]: 4095
>
> In [39]: s.shape
> Out[39]: (1040, 1392)
>
> In [40]: s.dtype
> Out[40]: dtype('uint16')
>
> In [41]: io.imsave('/Users/nuneziglesiasj/Desktop/im.tif', s)
>
> In [42]: sr = io.imread('/Users/nuneziglesiasj/Desktop/im.tif')
>
> In [43]: (s == sr).all()
> Out[43]: Image(False, dtype=bool)
>
> In [44]: sr.min()
> Out[44]: Image(0, dtype=uint8)
>
> In [45]: sr.max()
> Out[45]: Image(255, dtype=uint8)
> ```
>
> Ok, already this is not desirable... One would hope than an imsave
> followed by an imread would be a no-op, but whatever, let's accept for
> argument's sake that we want to limit ourselves to uint8. Here's the
> real downer:
>
> ```python
> In [46]: np.corrcoef(s.ravel(), sr.ravel())
> Out[46]:
> array([[ 1. , -0.29849602],
> [-0.29849602, 1. ]])
> ```
>
> This is simply unacceptable. I haven't explored any more than this yet
> but maybe someone has an idea about what is going on here? If it helps,
> the problem is with imsave � opening the images in Apple Preview shows
> the inversion. I just wanted to know if it was some weird
> incompatibility between skimage and Preview, rather than skimage acting
> stupid. Sadly, it appears to be the latter.
>
> PS: I just tested with png and get the exact same result.
>
Not many skimage.io plugins are capable of handling 16 bit data. Use
gdal (read only), tifffile (uncompressed tiff only), or freeimage, e.g.
`io.use_plugin('freeimage')`
Christoph