chaiNNer-org / chaiNNer

A node-based image processing GUI aimed at making chaining image processing tasks easy and customizable. Born as an AI upscaling application, chaiNNer has grown into an extremely flexible and powerful programmatic image processing application.
https://chaiNNer.app
GNU General Public License v3.0
4.47k stars 279 forks source link

Support for handling embedded ICC profiles #2599

Open the-database opened 7 months ago

the-database commented 7 months ago

Motivation When processing images with embedded ICC profiles and saving the output, the colors in the saved output don't look as expected compared to the colors of the input image. Based on the discussion on Discord, chaiNNer currently does not support color profiles and reads in all images as sRGB.

Description This is a complex feature and there are many ways it could be designed and implemented. As long as there is a way to handle images with embedded ICC profiles, so that exported images don't unexpectedly shift colors, any solution works for me.

Alternatives Converting an image with embedded ICC profile to sRGB in another software (such as Photoshop) allowed me to use the sRGB image in chaiNNer without any issues. However, many people wouldn't know that this workaround is necessary for handling images with ICC profiles. For example, when I first encountered this when upscaling a specific image, I thought the color shift was simply a flaw of the model, but it turned out that wasn't the case.

mrjschulte commented 7 months ago

Do you have an example image?

the-database commented 7 months ago

Here is the image I was using, zipped to make sure the image file is untouched by github.

GAvGRBhaUAApWr3.zip

If I load this image into chaiNNer and then save it to another file and then compare the files, the new file appears to be less saturated than the original file when I load them into Photoshop to compare.

Here's the output from magick identify -verbose .\GAvGRBhaUAApWr3.jpg which shows the embedded ICC profile:

Image:
  Filename: .\GAvGRBhaUAApWr3.jpg
  Permissions: rw-rw-rw-
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: DirectClass
  Geometry: 816x508+0+0
  Resolution: 72x72
  Print size: 11.3333x7.05556
  Units: Undefined
  Colorspace: sRGB
  Type: TrueColor
  Base type: Undefined
  Endianness: Undefined
  Depth: 8-bit
  Channels: 3.0
  Channel depth:
    Red: 8-bit
    Green: 8-bit
    Blue: 8-bit
  Channel statistics:
    Pixels: 414528
    Red:
      min: 0  (0)
      max: 255 (1)
      mean: 194.361 (0.762202)
      median: 185 (0.72549)
      standard deviation: 34.7114 (0.136123)
      kurtosis: 1.81024
      skewness: -0.271293
      entropy: 0.674755
    Green:
      min: 0  (0)
      max: 255 (1)
      mean: 154.072 (0.604204)
      median: 116 (0.454902)
      standard deviation: 57.8123 (0.226715)
      kurtosis: -1.16799
      skewness: 0.620514
      entropy: 0.689868
    Blue:
      min: 0  (0)
      max: 255 (1)
      mean: 155.619 (0.61027)
      median: 118 (0.462745)
      standard deviation: 58.8426 (0.230755)
      kurtosis: -1.27659
      skewness: 0.531043
      entropy: 0.713966
  Image statistics:
    Overall:
      min: 0  (0)
      max: 255 (1)
      mean: 168.017 (0.658892)
      median: 139.667 (0.547712)
      standard deviation: 50.4554 (0.197864)
      kurtosis: -0.211444
      skewness: 0.293421
      entropy: 0.692863
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33,0.03)
    green primary: (0.3,0.6,0.1)
    blue primary: (0.15,0.06,0.79)
    white point: (0.3127,0.329,0.3583)
  Matte color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: black
  Interlace: JPEG
  Intensity: Undefined
  Compose: Over
  Page geometry: 816x508+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 85
  Orientation: Undefined
  Profiles:
    Profile-icc: 536 bytes
  Properties:
    date:create: 2024-02-20T14:21:20+00:00
    date:modify: 2024-02-20T14:21:20+00:00
    date:timestamp: 2024-02-21T06:18:47+00:00
    icc:copyright: Copyright Apple Inc., 2022
    icc:description: Display P3
    jpeg:colorspace: 2
    jpeg:sampling-factor: 2x2,1x1,1x1
    signature: d23f47ac61796d02028f846d321329d88e4941fa215a11025870888dc76c830a
  Artifacts:
    verbose: true
  Tainted: False
  Filesize: 59412B
  Number pixels: 414528
  Pixel cache type: Memory
  Pixels per second: 79.0014MP
  Time-to-live: 0:0:0:0  2024-02-21T06:18:47Z
  User time: 0.005u
  Elapsed time: 0:01.005
  Version: ImageMagick 7.1.1-25 Q16-HDRI x64 98e7513:20231230 https://imagemagick.org
mrjschulte commented 6 months ago

Could you maybe attach screenshots of the versions of the image you have in various apps that clearly show the difference between what other apps are showing (assuming the stored icc profile is being honored and applied) and what you see in chaiNNer?

Also, for a basic support preflight here, which OS are you on and what version of chaiNNer are you using?