1

I wanted to batch-convert some JPG images to PNG, so I used the following ImageMagick command:

convert before.jpg after.png

However, things didn't go as smooth as I planned. See two images below - first is before.jpg, second is after.png:

enter image description here enter image description here

You can see that the second one is quite darker than the original.

I'm using ImageMagick 6.9.9-19.

Opening JPEG image in GIMP and exporting it as PNG gives expected result - output image is identical to original.

What am I doing wrong?

Edit: re-saving after.png with GIMP also makes the image identical to original.

Edit: even after I saved after.png with GIMP, re-converting with ImageMagick breaks colors again (convert after-gimp.png after-gimp-and-im.png).

Edit: converting to sRGB or CMYK TIFF, or even again to JPG, does not give this problem. However, I still need PNG.

Rogach
  • 26,050
  • 21
  • 93
  • 172
  • Check the colorspace in both images. This maybe related to sRGB and Adobe RGB color formats. See this link: https://stackoverflow.com/questions/33142786/opencv-imrite-gives-washed-out-result-for-jpeg-images – zindarod Oct 26 '17 at 13:26
  • @Zindarod - no, both images are in sRGB (as reported by `identify -verbose`). – Rogach Oct 26 '17 at 13:28

1 Answers1

0

The two images you posted are identical according to IM 6.9.9.20 Q16 Mac OSX compare -metric rmse GBooF.jpg geDxn.png null: Which produces: 0 (0). It is possible your viewers may display jpg and png differently, since neither have an sRGB profile. Though, png is usually assumed to be sRGB.

Also my viewer shows both of your images as the same --- no difference, in your post on Mac Safari and using Mac Preview.

Try adding an sRGB profile to your jpg. Then convert.

convert GBooF.jpg -profile path2/sRGB.icc GBooF2.jpg
convert GBooF2.jpg GBooF2.png

See if those view the same.

fmw42
  • 46,825
  • 10
  • 62
  • 80
  • But, as the SO mentions in the comments, the `identify -verbose` command displays `sRGB` colorspace for both images. – zindarod Oct 26 '17 at 19:55
  • `@Zindarod` ImageMagick assumes sRGB unless the image format supports storing gamma=1 for linear. JPG does not support storing gamma. In his case, both of his files are identical in pixel values (according to compare) and display identically on my Safari and Mac Preview. So the only possible difference would be how any particular viewer decides to display when there is no sRGB profile. Putting the same profile in both jpg and png should make them display on most devices the same because they now have an explicit profile to us (and the pixel data is identical). – fmw42 Oct 26 '17 at 22:37
  • If @Rogach thinks the images are really different and perhaps have been changed by uploading here, then he should zip the files and put a link to the zipped file, so others can examine the original images. – fmw42 Oct 26 '17 at 23:01