JPG to PNG GIMP convesion differences vs GraphicsMagick

GIMP coverts jpg to png image with massive, but imperceptible differences in color throughout the image. The same conversion process in GraphicsMagick produces 100% identical to the original jpg PNG image. Confirmed on various GIMP and GM versions using various compressions, icc inclusion and source images.
Comparisons can be made using GM or Imagemagick

PS. Why this website doesn’t cover GraphicsMagick tool? This is far far more better and robust software then ImageMagick.

Try it today, developer needs your support.

@alonso Welcome to the forum!

Could you please provide more information about your conversion process, showing examples? That would help the forum get to the bottom of it. I agree we don’t talk about GraphicsMagick. I wonder how different it is from IM at this point…

steps to reproduce:

  1. open random jpg (for example flower.jpg), not exported from GIMP, flatten if you need, export as PNG with or without color profile.
  2. gm convert flower.jpg -quality 100 flower_gm.png
  3. gm compare -metrics mse flower_gimp.png flower_gm.png
    and gm compare -file diff.png flower_gimp.png flower_gm.png
    to view differences directly on image.

    please confirm.
    color management do not affect this.

Are you exporting 8-bit (indexed) or 24-bit (‘true colour’) PNG from the Gimp?

I would try to see if I can reproduce this, but where is the input JPG?
Also, since JPG uses lossy encoding anyway, decoding routines are not required to produce the same output as the reference decoder. See software - Is a JPG guaranteed to produce the same pixels? - Photography Stack Exchange.

1 Like

In principle, decoding a JPEG is lossless. However, it does involve heavy arithmetic, including decompression and conversion from YCbCr to sRGB.

When two different programs are used for supposedly identical image processing, the results will often be slightly different. This is because they often use different algorithms, which result in different arithmetic rounding.

When I take toes.jpg (which is has no embedded colour profile), and create 8-bit t.png from Gimp, and 8-bit t2.png from ImageMagick, there is a difference:

magick compare -metric RMSE t.png t2.png NULL:

52.6405 (0.000803242)

I reckon an RMSE of 0.01 is only just visible. So an RMSE of less than 0.001 is almost certainly not visible.

(I have no experience of GraphicsMagick. But I would expect any two different software systems to show some difference. When two software systems use the same decoding library, there may be no difference.)

1 Like

If you use gm compare to compare the JPG and each of the PNGs, you’re going to compare the JPG rendering (interpretation, decoding) produced by gm, encoded (losslessly) as a PNG, with another (Gimp) rendering, encoded (losslessly) as a PNG. Since the PNG produced by gm simply contains the data that gm extracted from the JPG, there will be no differences (if the PNG en/decoding code of gm has no bugs). What you are comparing is the way two libraries (the one used by gm and the one used by Gimp) decode the JPG, not how they encode the extracted data into PNG.

1 Like

Both GM and GIMP uses libjpeg-turbo, same versions on my machine, to decode jpgs. More information is needed. I shall perrom tests with other libre applications later.

1 Like

ok, so why then when we compare jpgs exported / created in GIMP, further opened in GIMP and converted to PNG are exact compared to exported from GM. I do not implying that somewhere GIMP does something wrong, but GM goes through rigid code check, that was a reason of imagemagick fork back in 2002.

OK, I made an assumption and was wrong. Sorry about that. I’ll be interested to learn what you find.

@alonso wrote:

ok, so why then when we compare jpgs exported / created in GIMP, further opened in GIMP and converted to PNG are exact compared to exported from GM.

Sorry, I don’t understand.

By “exact”, are you now saying that that using GIMP to read a JPG and export as PNG, gives exactly the same pixels using GM to read the JPG and write a PNG?

When I do this with ImageMagick, the pixels are slightly different. But the difference is very small. For example, from the Gimp result:

    Red:
      min: 6939  (0.105882)
      max: 65535 (1)
      mean: 34955.8 (0.533392)
    Green:
      min: 5397  (0.0823529)
      max: 60395 (0.921569)
      mean: 31843.7 (0.485904)
    Blue:
      min: 3084  (0.0470588)
      max: 61680 (0.941176)
      mean: 29173 (0.445151)

From the IM result:

    Red:
      min: 6939  (0.105882)
      max: 65535 (1)
      mean: 34955.8 (0.533391)
    Green:
      min: 5397  (0.0823529)
      max: 60395 (0.921569)
      mean: 31843.9 (0.485906)
    Blue:
      min: 3084  (0.0470588)
      max: 61680 (0.941176)
      mean: 29172.9 (0.445149)

Note that in each channel, the min and max values are equal, but the mean values are slightly different.

In this version of IM:

magick -list format |grep -i jpg

      JPG* JPEG      rw-   Joint Photographic Experts Group JFIF format (libjpeg-turbo 2.0.5)

Another possibility: In this experiment, I am using pre-built versions of ImageMagick and Gimp. Even if they use the same jpeg library, that will have been built by different people on different computers, possibly with different compilers and compilation options. In particular, different optimisations can cause different orderings of arithmetic expressions. As before, this can cause differences in rounding.

libjpeg-turbo>=1.3.0_2 here. Krita produces png that is the exact copy of jpg.

“different optimisations can cause different orderings of arithmetic expressions” I’d rather believe that. But my friends comfirmed my results and they run completely different distro. Yeah, the difference is negligable, but I however had more variance in results with badly encoded jpegs from archives, still unnoticable, but colors changed almost everywhere in the image, compared to

Yes, jpgs created in GIMP after conversion to png don’t have any color changes compared to GM pngs.