3

I am working with 2D floating-point numpy arrays and saving them as .png files with high precision (see this question for how I came to this point). To do this I use the freeimage plugin, as in that linked question.

This creates a weird behaviour where the images are flipped (both left-right and up-down) if saved to 16-bit. This behaviour happens only for RGB or RGBA images, not for greyscale images. Here is some example code:

from skimage import io, img_as_uint, img_as_ubyte
im = np.random.uniform(size=(256, 256))
im[:128, :128] = 1
im = img_as_ubyte(im)
io.use_plugin('freeimage')
io.imsave('test_1.png', im)

creates the following picture:

8 bit greyscale

when I try to save this in 16 bit, I get the same result (albeit taking 99kb instead of 50, so I know the bitdepth is working).

Now do the same as an RGB image:

im = np.random.uniform(size=(256, 256, 3))
im[:128, :128] = 1
im = img_as_ubyte(im)
io.use_plugin('freeimage')
io.imsave('test_1.png', im)

The 8-bit result is:

8 bit rgb

but doing the following

im = img_as_uint(im)
io.use_plugin('freeimage')
io.imsave('test_1.png', im)

gives me

16 bit rgb

This happens if the array contains an alpha level too.

It can be fixed by including

im = np.fliplr(np.flipud(im))

before saving. However, it seems to me this is pretty weird behaviour and not very desirable. Any idea why this is happening or whether it is intended? As far as I could see it's not documented.

Community
  • 1
  • 1
tsawallis
  • 1,035
  • 4
  • 13
  • 26
  • 1
    I can reproduce this bug in the current dev version of scikit-image. You should raise an issue on their [GitHub repo](https://github.com/scikit-image/scikit-image). – ali_m Aug 14 '14 at 16:50
  • Thanks for the response ali_m; I've raised an issue [here](https://github.com/scikit-image/scikit-image/issues/1101) – tsawallis Aug 15 '14 at 11:53
  • I can confirm that I see the same broken behavior. We'll discuss this further on the submitted issue. – Stefan van der Walt Aug 15 '14 at 12:24
  • 2
    @StefanvanderWalt has fixed the issue in the scikit-image dev version and the issue is closed. – tsawallis Aug 15 '14 at 14:45

0 Answers0