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

Random artifacts in image display with IJulia #925

Closed
jonasaugust opened this issue Nov 11, 2020 · 5 comments
Closed

Random artifacts in image display with IJulia #925

jonasaugust opened this issue Nov 11, 2020 · 5 comments

Comments

@jonasaugust
Copy link

I sometimes get display artifacts when I display images using IJulia, and it appears to depend on the contents of the image. The simplest example of this that I've found is a 2 pixel image, a 2x1 Float64 array [.40196 0], which should display as adjacent gray and black blocks, but instead the two blocks appear to get crushed to the left and some random vertical lines display on the right.
Code:

[Gray.([.40196 0]),Gray.([.40196 0]),Gray.([.40197 0])]

Screen capture (Julia 1.5.2, in Debian running inside WSL2 under Windows 10, displayed on Firefox on the Windows side; the same issue appears using Edge browser, or running everything on Mac OS High Sierra with Firefox):
juliaimages-artifact
The first two instances of this image will have different such artifacts (confirming their randomness), while the last image, where the 0.40196 is very slightly increased to 0.40197, displays correctly.

@timholy
Copy link
Member

timholy commented Nov 11, 2020

I'm not sure how IJulia manages the display, but it might be worth pkg> add ImageIO if you haven't done this already.

@jonasaugust
Copy link
Author

jonasaugust commented Nov 11, 2020

I'm not sure how IJulia manages the display, but it might be worth pkg> add ImageIO if you haven't done this already.

Thanks for the suggestion. I think I had done that at one point, but did it again anyway. After restarting the notebook, the artifacts remain. I think image display is mediated by ImageMagick.jl, because when I removed that Julia package using pkg> remove ImageMagick, I get an error (which asks for ImageMagick.jl to be added, which I then did) when in IJulia I try to show a simple image using Gray.(rand(2,2)).

@timholy
Copy link
Member

timholy commented Nov 11, 2020

Do you know what format it uses? ImageIO is better for PNG than ImageMagick, and your issue seems similar to JuliaIO/ImageMagick.jl#184. Perhaps it's using a format not supported by ImageIO and the error is not specific to PNGs.

@johnnychen94
Copy link
Member

The same problem can be reproduced in vscode, too. If I understand it correctly, the image show pipeline is:

Colorant array ---> Base64 encoding --> PNG encoding --> atom/vscode/Jupyter/Pluto --> HTML rendering(Base64 decoding + PNG decoding)

ImageIO does not yet support IO stream well: JuliaIO/PNGFiles.jl#22 so ]add ImageIO won't help in this case.

If we look at the following two results, it seems that size(img, 2) is improperly doubled in the first image when ImageMagick processees the image.

Gray[0.0 0.4 0.6 0.8] result:

image

Gray[0.0 0.4 0.6 0.81] result:

image

@johnnychen94
Copy link
Member

closed by JuliaIO/PNGFiles.jl#27 and JuliaIO/ImageIO.jl#15

As a side note:

ImageMagick is still problematic here, I don't know where the issue is. For image display purposes, since ImageShow will pass all the work to PNGFiles(it has a higher priority than ImageMagick), so ImageMagick will never be called in this case.

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

3 participants