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

BUG: Weird result when saving matrix to png file #1067

Open
IoachimusRoderici opened this issue Feb 5, 2025 · 1 comment
Open

BUG: Weird result when saving matrix to png file #1067

IoachimusRoderici opened this issue Feb 5, 2025 · 1 comment

Comments

@IoachimusRoderici
Copy link

IoachimusRoderici commented Feb 5, 2025

I have stored an image in a Matrix{RGB24}.

When i save the image to a jpg file, i get the expected result. When i save the image to a png file, it looks very wrong.

I am using Julia v1.11.3 and Images v0.26.2.

Minimal Working Example:

using Images, ColorTypes

# Fill a matrix with 4 random colors:
image = zeros(RGB24, 100,100)
image[1:50,1:50] .= RGB24(1, 1, 1)
image[50:100,50:100] .= RGB24(1, 0.7, 0.5)
image[1:50,50:100] .= RGB24(0.32, 0.9, 0.01)
image[50:100,1:50] .= RGB24(0.85, 0.52, 0.1)

# Save to jpg and png:
save("image.jpg", image)
save("image.png", image)

image.jpg (looks ok):

Image

image.png (looks wrong):

Image


EDIT: Better example

@IoachimusRoderici IoachimusRoderici changed the title Weird result when saving matrix to png file BUG: Weird result when saving matrix to png file Feb 5, 2025
@RalphAS
Copy link
Contributor

RalphAS commented Feb 7, 2025

RGB24 is not as well supported as other Colorants. I haven't figured out how it's handled in the JPEG chain, but until someone implements something similar for PNGFiles.jl, one can convert image_to_write = RGBA{N0f8}.(image) before saving.

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