ImageIO reading slightly different RGB values than other methods

后端 未结 4 398
灰色年华
灰色年华 2020-12-25 12:35

I\'ve found that I\'m getting different RGB when using Java (& actually paint.NET) than I am using ImageMagick, Gimp, Python, and Octave. The last 4 all agreeing with ea

4条回答
  •  自闭症患者
    2020-12-25 13:16

    As per my comment, the major difference between the various applications/libraries that you've used to retrieve pixel colour value is that they're all using different versions of libjpeg - at least on Mac OSX.

    When you check out your Github project onto certain versions of Ubuntu you'll see that all values are reported the same across the board. In these cases, python ImageMagick and the Java JDK/JRE are using the same libjpeg implementation.

    On the Mac, if you installed jpeg via homebrew, or Pillow via pip then you'll notice that they're using libjpeg v9 (libjpeg.9.dylib), whereas Java 7 and 8 JDKs come with their own libjpeg bundled that are quite different.

    Octave lists its jpeg dependencies as libjpeg8-dev.

    GIMP, Inkscape, Scribus etc also come bundled with their own. In my case, GIMP comes bundled with the same version as python and ImageMagick, which would explain the similar values (ie: /Applications/GIMP.app/Contents/Resources/lib/libjpeg.9.dylib)

    If you want to guarantee the values being the same across apps, you have options:

    1. Stick to the same platform/stack (as suggested by @haraldk) - Stick with developing/running your stuff on Linux platforms that guarantee all of them use the same libjpeg version
    2. Bind your Java code to the same version that the other apps are using - ie: load libjpeg.9.dylib and use that from your Java app. I'm not 100% sure how you'd do that though.
    3. Recompile your JDK to use the right one - an option referenced by this answer is to use openjdk and compile it against the desired version of libjpeg, which sounds more achievable.

    I'll admit that options 2 and 3 are really harder versions of option 1!

    Note:
    I'm definitely up-voting @haraldk's answer because his conclusion is pretty much the same.

    I also played with using different icc profiles, and they give totally different answers. So it's worth being wary of that.

    I just wanted to add an answer that added more emphasis on the libjpeg implementation, because I believe that is what is catching you out in your specific instance.

    Update

    Actually, there is another major difference noted in @haraldk's answer, being the diff between CMM and Little CMS. As he says: Java uses Little CMS, which is also used by Ubuntu

    I actually think that's more likely to be the answer here.

提交回复
热议问题