XYZ to sRGB corrected

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mboufleur
Posts: 2
Joined: 2015-01-28T11:34:02-07:00
Authentication code: 6789

XYZ to sRGB corrected

Post by mboufleur »

While using imagemagick for some JPEG2000 to TIFF conversions using the commands from this page, I noticed a problem with the resulting file.

For this test, I was using a professional DCinema encoder to encode from TIFF to JPEG2000 image, and imagemagick was used to convert it back to TIFF.

Unfortunately, the conversion was not quite right, and the image was slightly brighter. After a lot of searching and reading, I found out that in the imagemagick command line, there was no function to fix the Normalization Factor for White Point in DCinema, using the Luminance level 48fL for a Peak of 52.37 cd/m2.

So, for this command line to be correct, the following change would have to be applied:

Code: Select all

#!/bin/bash

xyz2srgb() {
    convert -verbose "$1" \
    -type TrueColor \
    -alpha Off \
    -gamma 0.384615 \
    -evaluate multiply 1.09104167 \ 
    -color-matrix "3.2404542 -1.5371385 -0.4985314 \
                  -0.9692660  1.8760108  0.0415560 \
                   0.0556434 -0.2040259  1.0572252" \
    -gamma 2.2 \
    -set colorspace sRGB \
    -depth 8 \
    $(basename "$1" ".j2c").tif
The " 1.09104167" is the constant from the calculation of 52.37/48 that should be applied to all pixel values after gamma inverse adjustment and prior to matrix color change.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: XYZ to sRGB corrected

Post by snibgo »

Thanks for the information.

As Anthony notes in the linked thread, the conversion from linear RGB to sRGB isn't actually "-gamma 2.2". The correct conversion can be done with "-set colorspace RGB -colorspace sRGB". The correct result will have very slightly lighter shadows, which is more obvious from a histogram than a screen image. The difference may be unimportant in your application.
snibgo's IM pages: im.snibgo.com
Post Reply