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

Converting I;16B PNG to RGB ruins the image #5991

Closed
clairerity opened this issue Jan 26, 2022 · 4 comments
Closed

Converting I;16B PNG to RGB ruins the image #5991

clairerity opened this issue Jan 26, 2022 · 4 comments

Comments

@clairerity
Copy link

Hello! I have a image grayscale image (spectrogram) that looks fine on 32bit (F), but when i try to convert it to RGB, most data is loss, that means the image is almost fully black (majority of the white/gray parts turned to black!), would just like to know how to resolve this. Thank you very much in advance!

@radarhere
Copy link
Member

Would you mind attaching a copy of your image?

@clairerity
Copy link
Author

Hello @radarhere ! thank you very much for your reply :)

This is the original image in F mode (32 bit grayscale aka 1 channel)
mel

when i try to convert it using .convert('RGB'), it becomes this
colored

Almost all parts are lost :(

@radarhere
Copy link
Member

From looking at the image, I conclude that it's not actually in F mode, but I;16B.

Unfortunately, Pillow does not have very good support for I;16 modes at the moment. Also, when I try to convert to RGB, my image becomes too bright, rather than too dark.

If you are looking for an immediate solution, I did

from PIL import Image
im = Image.open('input.png')
im.point(lambda i: i * (1 / 255)).convert("RGB").save("output.png")

but since yours is too dark, I would suggest

from PIL import Image
im = Image.open('input.png')
im.point(lambda i: i * 255).convert("RGB").save("output.png")

@radarhere radarhere changed the title Converting F to RGB ruins the image Converting I;16B PNG to RGB ruins the image Jan 27, 2022
@clairerity
Copy link
Author

Hello! thank you very much for this! although there was still some info loss when converting, it significantly improved using the code you provided! Thank you again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants