[RESOLVED] -intensity ... -threshold IM 6.8.7.5 beta Q16

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

[RESOLVED] -intensity ... -threshold IM 6.8.7.5 beta Q16

Post by fmw42 »

I was under the impression that -intensity rec709luminance should produce a result with gamma=1 no matter which of the allowed functions it precedes. This was fixed for -intensity rec709luminance -colorspace gray, but does not seem to be fixed for any of the other allowed functions such as -threshold.


Is this a bug or do I misunderstand how -intensity rec709luminance (or rec601luminance) should behave for functions other than -colorspace gray. See my my subsequent post below?



# create test image

Code: Select all

imb convert -size 128x128 -depth 16 gradient: grad.png

Testing with -colorspace gray produces the correct gamma=1
imb convert grad.png -intensity rec709luminance -colorspace gray -format "%[fx:mean] %[colorspace] %[type] %[gamma]\n" -write info: grad_irec709luminance_gray.png
0.311763 Gray Grayscale 1

Testing with -threshold results in an incorrect gamma=0.4545
imb convert grad.png -intensity rec709luminance -threshold 50% -format "%[fx:mean] %[colorspace] %[type] %[gamma]\n" -write info: grad_irec709luminance_t50.png
0.265624 sRGB Bilevel 0.45455

I suspect this is the same for all the allowed functions, though I have only tested with -threshold.
Last edited by fmw42 on 2013-11-01T09:56:35-07:00, edited 18 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug -intensity ... -threshold IM 6.8.7.5 beta Q

Post by fmw42 »

Similar results using rose:

imb convert rose: -intensity rec709luminance -colorspace gray -format "%[fx:mean] %[colorspace] %[type] %[gamma]\n" -write info: rosde_irec709luminance_gray.png
0.196013 Gray Grayscale 1
imb convert rose: -intensity rec709luminance -threshold 50% -format "%[fx:mean] %[colorspace] %[type] %[gamma]\n" -write info: rose_irec709luminance_t50.png
0.0723603 sRGB Bilevel 0.454545
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug -intensity ... -threshold IM 6.8.7.5 beta Q

Post by fmw42 »

I might be wrong about my assumptions above. Was it is intended that -intensity was simply a channel mixing function without regard to linearity/non-linearity (colorspace of the input). If so, then I assume one must first use -colorspace RGB to get the linear result, such as the following. If so, that seems a bit inconsistent with how it works with -colorspace gray

imb convert grad.png -colorspace RGB -intensity rec709luminance -threshold 50% -format "%[fx:mean] %[colorspace] %[type] %[gamma]\n" -write info: grad_irec709luminance_t50b.png
0.265624 RGB Bilevel 1



If it is required to use -colorspace RGB -intensity rec709luminance, then I do not see why we even need the luminance versions. One could just use

convert image -colorspace RGB -colorspace gray result

rather than

convert image -intensity rec709luminance -colorspace gray result


and

convert image -colorspace RGB -threshold 50% result

rather than

image -colorspace RGB -intensity rec709luminance -threshold 50% result


The bottom line: Was -intensity (and -grayscale) intended just to be channel mixing functions without regard to linear or nonlinear results? If so, then perhaps it was a mistake to have -colorspace gray sensitive to the linearity from luminance or luma while all the other functions are not. And if we change back to that channel mixing only pardigm, are there consequences or differences if we eliminate the luminance arguments to -intensity and simply precede it with -colorspace RGB in order to get the linear results.


How do we make -intensity work consistently so that it is clearly understood how it works?
Last edited by fmw42 on 2013-10-31T20:25:09-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug -intensity ... -threshold IM 6.8.7.5 beta Q

Post by fmw42 »

To partially answer my own question. These two are not the same. So we cannot do away with rec709luminance.


imb convert rose: -intensity rec709luminance -colorspace gray -format "%[fx:mean] %[colorspace] %[type] %[gamma]\n" -write info: rose_irec709luminance_gray.png
0.196013 Gray Grayscale 1


imb convert rose: -colorspace RGB -colorspace gray -format "%[fx:mean] %[colorspace] %[type] %[gamma]\n" -write info: rose_rgb_gray.png
0.394629 Gray Grayscale 0.454545


The latter converts first to linear (RGB), but then -colorspace gray converts back to non-linear (sRGB)


So the question becomes, should -intensity rec709luminance when used with other functions require -colorspace RGB to precede it or should it automatically force a conversion to linear (gamma=1) like it does for -colorspace gray.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [RESOLVED] -intensity ... -threshold IM 6.8.7.5 beta Q16

Post by fmw42 »

After all these post, I think I have a better understanding of -intensity. So rather than rocking the boat and changing anything. I am OK with it as is.
Post Reply