Skip to content

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

Description

@clairerity

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!

Activity

  1. radarhere commented on Jan 26, 2022

    @radarhere
    Member

    Would you mind attaching a copy of your image?

  2. clairerity commented on Jan 27, 2022

    @clairerity
    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 :(

  3. radarhere commented on Jan 27, 2022

    @radarhere
    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")
  4. changed the title [-]Converting F to RGB ruins the image[/-] [+]Converting I;16B PNG to RGB ruins the image[/+] on Jan 27, 2022
  5. clairerity commented on Feb 2, 2022

    @clairerity
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions