Page 1 of 1

[3 gamma=1 Gray imgs -combine: Will patch set colorspc RGB? -edit] round-trip error (-separate or -combine change gamma)

Posted: 2017-08-09T16:59:19-07:00
by Dabrosny
When the colorspace is linear RGB with gamma=1, the operators -separate and -combine ignore all of that and mark their output as nonlinear (colorspace gray for -separate or colorspace sRGB for -combine) with gamma~0.4545...

In the following, -separate is changing the marked gamma from 1 to 0.454545 in each of the three resulting identical grayscale images, without changing the data values (back) to have mean 25864.7 as they should (and originally did) when gamma=0.454545. So the resulting image(s) will be too dark.

Code: Select all

$ magick rose: -colorspace gray -write rosegray.miff -colorspace RGB -write rosegrayRGB.miff -separate  rosegrayRGBseparated.miff
$ magick identify -format  '%M  %[colorspace]  %[gamma]  %[mean]\n'  rosegray.miff rosegrayRGB.miff rosegrayRGBseparated.miff 
rosegray.miff  Gray  0.454545  25864.7
rosegrayRGB.miff  RGB  1  11130.8
rosegrayRGBseparated.miff  Gray  0.454545  11130.8
rosegrayRGBseparated.miff  Gray  0.454545  11130.8
rosegrayRGBseparated.miff  Gray  0.454545  11130.8
In the following I work around the -separate problem by explicitly setting the gamma back to 1.
But then I do a -combine and this changes it to 0.45455 when combining the three identical linear single-channel images.
So again the result is too dark, this time due to -combine.

Code: Select all

$ magick rosegrayRGBseparated.miff -set gamma 1 -write roselinear.miff -combine roselinearcombined.miff
$ magick identify -format  '%M  %[colorspace]  %[gamma]  %[mean]\n'  roselinear.miff roselinearcombined.miff 
roselinear.miff  Gray  1  11130.8
roselinear.miff  Gray  1  11130.8
roselinear.miff  Gray  1  11130.8
roselinearcombined.miff  sRGB  0.454545  11130.8
Since we only have one single-channel colorspace ("gray" which seems usually to be treated by default as nonlinear in the sRGB sense), the only way to preserve this information is by preserving gamma.

I'm using IM7.0.6-2 Q16 HDRI x64 (Windows 7).

Re: round-trip error (-separate and -combine ignore/lose gamma)

Posted: 2017-08-10T06:02:48-07:00
by magick
Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.

Re: round-trip error (-separate and -combine ignore/lose gamma)

Posted: 2017-08-10T06:42:37-07:00
by Dabrosny
magick wrote: 2017-08-10T06:02:48-07:00 Thanks for the problem report. We can reproduce it and will have a patch to fix it...
Thank you very much.
In addition to preserving the gamma setting of the image, will -combine on three gamma=1 gray images produce linear RGB as the colorspace of the result instead of sRGB?

Re: [3 gamma=1 Gray imgs -combine: Will patch set colorspc RGB? -edit] round-trip error (-separate or -combine change ga

Posted: 2017-08-24T15:17:53-07:00
by fmw42
In IM 6.9.9.9 Q16 Mac OSX and -grayscale Rec709luminance, I get (same for IM 7.0.6.9 Q16 HDRI using magick)

convert rose: -grayscale Rec709luminance -write rosegray.miff -separate rosegrayRGBseparated.miff

Image: rosegray.miff
Format: MIFF (Magick Image File Format)
Class: DirectClass
Geometry: 70x46+0+0
Units: Undefined
Type: Grayscale
Base type: Grayscale
Endianess: Undefined
Colorspace: Gray
Depth: 8-bit
Channel depth:
gray: 8-bit
Channel statistics:
Pixels: 3220
Gray:
min: 5 (0.0196078)
max: 255 (1)
mean: 49.9761 (0.195985)
standard deviation: 53.9171 (0.211439)
kurtosis: 6.58825
skewness: 2.58769
entropy: 0.856942

Gamma: 1


and

Image: rosegrayRGBseparated.miff
Format: MIFF (Magick Image File Format)
Class: DirectClass
Geometry: 70x46+0+0
Units: Undefined
Type: Grayscale
Base type: Grayscale
Endianess: Undefined
Colorspace: Gray
Depth: 8-bit
Channel depth:
gray: 8-bit
Channel statistics:
Pixels: 3220
Gray:
min: 5 (0.0196078)
max: 255 (1)
mean: 49.9761 (0.195985)
standard deviation: 53.9171 (0.211439)
kurtosis: 6.58825
skewness: 2.58769
entropy: 0.856942
Gamma: 1


So they are identical and after -separate, both are gamma=1

Now if I combine them:


convert rosegrayRGBseparated.miff rosegrayRGBseparated.miff rosegrayRGBseparated.miff -set colorspace RGB -combine roseRGBseparated_combined.miff


Image: roseRGBseparated_combined.miff
Format: MIFF (Magick Image File Format)
Class: DirectClass
Geometry: 70x46+0+0
Units: Undefined
Type: Grayscale
Base type: TrueColor
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
gray: 8-bit
Channel statistics:
Pixels: 3220
Gray:
min: 5 (0.0196078)
max: 255 (1)
mean: 49.9761 (0.195985)
standard deviation: 53.9171 (0.211439)
kurtosis: 6.58825
skewness: 2.58769
entropy: 0.856942

Gamma: 1


Does this resolve your problem? Or do I misunderstand your issue?

Re: [3 gamma=1 Gray imgs -combine: Will patch set colorspc RGB? -edit] round-trip error (-separate or -combine change ga

Posted: 2017-08-29T12:39:30-07:00
by Dabrosny
fmw42 wrote: 2017-08-24T15:17:53-07:00 In IM 6.9.9.9 Q16 Mac OSX and -grayscale Rec709luminance, I get (same for IM 7.0.6.9 Q16 HDRI using magick)

convert rose: -grayscale Rec709luminance -write rosegray.miff -separate rosegrayRGBseparated.miff
...
So they are identical and after -separate, both are gamma=1
The grayscale image (result of -grayscale) can't really be separated, so the -separate would have to be tested directly on a multichannel images, as in my original example. It should probably be tested on an RGB (with gamma=1) and on an sRGB (with gamma=0.454545), to make sure the gamma is preserved after -separate.
fmw42 wrote: 2017-08-24T15:17:53-07:00 Now if I combine them:

convert rosegrayRGBseparated.miff rosegrayRGBseparated.miff rosegrayRGBseparated.miff -set colorspace RGB -combine roseRGBseparated_combined.miff
...
Gamma: 1
What happens if you remove the -set colorspace RGB? It should still preserve the gamma=1 of the three grayscale images in the resulting image without your having to explicitly set the colorspace.
Ideally it should also set the resulting colorspace to RGB itself by default with the -combine since it knows that it is combining three linear channels (gamma=1). Otherwise it could perhaps set the colorspace to Undefined. In any case I believe it definitely should not set it to sRGB since this is completely inconsistent with the gamma=1.

Re: [3 gamma=1 Gray imgs -combine: Will patch set colorspc RGB? -edit] round-trip error (-separate or -combine change ga

Posted: 2017-08-29T15:40:36-07:00
by fmw42
The grayscale image (result of -grayscale) can't really be separated
In IM 6, grayscale images internally have 3 equal channels. So you can separate them into a miff format.