Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RGB arrays mirror reversed when saved to 16-bit png using Freeimage plugin #1101

Closed
tomwallis opened this issue Aug 15, 2014 · 7 comments
Closed

Comments

@tomwallis
Copy link

I am using io.imsave to output a numpy array to a 16-bit .png file (using the Freeimage plugin). If the array is MxNx3 (RGB) or MxNx4 (RGBA), the saved file is mirror reversed (both L-R and T-B). Works fine for greyscale (MxN).

For more details see my question on stackoverflow.

I'm posting here as an issue, as suggested by ali_m on stackoverflow.

@stefanv
Copy link
Member

stefanv commented Aug 15, 2014

Provided code snippet:

import numpy as np
from skimage import io, img_as_uint, img_as_ubyte

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

vs

import numpy as np
from skimage import io, img_as_uint, img_as_ubyte

im = np.random.uniform(size=(256, 256, 3))
im[:128, :128] = 1
im = img_as_uint(im)  # problem here, this works if ubyte
io.use_plugin('freeimage')
io.imsave('test_1.png', im)

@stefanv
Copy link
Member

stefanv commented Aug 15, 2014

test_0.png:

test_0

test_1.png:

test_1

@stefanv
Copy link
Member

stefanv commented Aug 15, 2014

Likely culprit: freeimage_plugin.py:648:_array_to_bitmap()

I see comments like:

# swizzle the color components and flip the scanlines to go to
# FreeImage's BGR[A] and upside-down internal memory format"

@tomwallis
Copy link
Author

Thanks for adding my code snippets. Sorry, this is my first github issue report.

Those comments don't sound good. I'm not sure why I would want my color components "swizzled" and my scanlines flipped.

@stefanv
Copy link
Member

stefanv commented Aug 15, 2014

Having looked at the code a bit, this is because FreeImage uses a different internal representation. I think I've almost got it sorted.

stefanv added a commit to stefanv/scikit-image that referenced this issue Aug 15, 2014
@stefanv
Copy link
Member

stefanv commented Aug 15, 2014

Please see if #1102 solves the problem for you.

@tomwallis
Copy link
Author

Seems to! Thanks stefanv.

ahojnnes added a commit that referenced this issue Aug 15, 2014
freeimage: Correctly handle saving uint16 images (closes gh-1101)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants