Open dskkato opened 4 years ago
The broken images have 2-bit or 4-bit depth, curiously. When the bit depth is specified directly as below, the lattice pattern is preserved.
save("png8:sample.png", img)
By the way, I knew this method from twitter (Japanese, though). https://twitter.com/LirimyDh/status/1293779034321518592?s=20
Oh, that's very interesting, thanks for sharing!
This issue was originally reported to Images.jl: https://github.com/JuliaImages/Images.jl/issues/909
When I saved an image which has values of multiples of 1/3, the saved image shrank along horizontal axis by factor of 1/4 and rest of the image was filled with random vertical pattern.
Examples of generating broken images
What I tried was as follow.
An expected image from above snippet is a lattice pattern with vertical and horizontal lines.
But actual was those. These outputs were obtained by repeating
save(...)
function in the snippet. While the sameimg
was passed tosave
, different vertical pattern appears in right 3/4 in images every time.A curious point is that when some different value was assigned to the array, the
save
function works as expected.Another examples
Here, 1/5 was assigned instead of 1/3. This time, shrinking ratio seems to be about 1/2, though
save with ImageIO worked as expected
The above examples were generated without ImageIO package. When you see FileIO package and search png format, it tries to use ImageIO if installed. So I added ImageIO and then re-run the above snipped. That condition created an expected lattice pattern image. So the main cause might be ImageMagick module.
https://github.com/JuliaIO/FileIO.jl/blob/c55ffe1439dbef1f9a2b44852dda52e89beb530a/src/registry.jl#L90-L98
Other info.
Following is my environment.
Brief debug info
Following is @timholy's reply to original post.
I inserted some debugging code in ImageMagick.jl:
and then did this:
and got this:
So, the image is fine up to the point where Julia hands the data off to the imagemagick C library. Consequently, fixing this bug requires that it be reported to the ImageMagick developers.
Originally posted by @timholy in https://github.com/JuliaImages/Images.jl/issues/909#issuecomment-673388448