Freeimage plugin mirrors RGB arrays while saving in 16-bit

I am working with 2D floating point numpy arrays and store them as high precision .png files (see this question for how I came to this question). For this, I am using the freeimage plugin as in this related question.

This creates strange behavior when images are flipped (both left and right) if saved to 16 bits. This behavior occurs only for RGB or RGBA images, not for grayscale images. Here's some sample 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 image:

8 bit greyscale

when i try to store this in 16 bits i get the same result (although i accept 99kb instead of 50 so i know bitdept works).

Now do the same as the 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)

      

8-bit result:

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 also contains an alpha level.

It can be fixed by turning on

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

      

before saving. However, it seems to me that this is rather strange behavior and not very desirable. Any idea why this is happening or is it intended? As far as I could see this is not documented.

+3


source to share





All Articles