intensity and grayscale

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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

intensity and grayscale

Post by snibgo »

IM 6.8.5-8 on Windows 7.

The documentation for "-intensity" (http://www.imagemagick.org/script/comma ... #intensity) claims Lightness is the average of the min and max RGB values, and that "-grayscale" should do the same.

Code: Select all

Lightness         (min(R', G', B') + max(R', G', B')) / 2.0
However, it seems to be simply the minimum.

Code: Select all

D:\web\im>c:\im\ImageMagick-6.8.5-8-Q16\convert xc:red xc:yellow xc:brown xc:rgb(100,110,120) xc:rgb(50,150,200) -append test.png

D:\web\im>c:\im\ImageMagick-6.8.5-8-Q16\convert test.png txt:
# ImageMagick pixel enumeration: 1,5,255,srgb
0,0: (255,  0,  0)  #FF0000  red
0,1: (255,255,  0)  #FFFF00  yellow
0,2: (165, 42, 42)  #A52A2A  brown
0,3: (100,110,120)  #646E78  srgb(100,110,120)
0,4: ( 50,150,200)  #3296C8  srgb(50,150,200)

D:\web\im>c:\im\ImageMagick-6.8.5-8-Q16\convert test.png -grayscale Lightness txt:
# ImageMagick pixel enumeration: 1,5,255,gray
0,0: (  0,  0,  0)  #000000  gray(0)
0,1: (  0,  0,  0)  #000000  gray(0)
0,2: ( 42, 42, 42)  #2A2A2A  gray(42)
0,3: (100,100,100)  #646464  gray(100)
0,4: ( 50, 50, 50)  #323232  gray(50)
While I'm on the topic, there is no difference between Rec601Luma and Rec601Luminance (or between Rec709Luma and Rec709Luminance). I wouldn't expect a difference between my first three pixels, but the last two pixels should.

Code: Select all

D:\web\im>c:\im\ImageMagick-6.8.5-8-Q16\convert test.png -grayscale Rec601Luma txt:
# ImageMagick pixel enumeration: 1,5,255,gray
0,0: ( 76, 76, 76)  #4C4C4C  gray(76)
0,1: (226,226,226)  #E2E2E2  gray(226)
0,2: ( 79, 79, 79)  #4F4F4F  gray(79)
0,3: (108,108,108)  #6C6C6C  gray(108)
0,4: (126,126,126)  #7E7E7E  gray(126)

D:\web\im>c:\im\ImageMagick-6.8.5-8-Q16\convert test.png -grayscale Rec601Luminance txt:
# ImageMagick pixel enumeration: 1,5,255,gray
0,0: ( 76, 76, 76)  #4C4C4C  gray(76)
0,1: (226,226,226)  #E2E2E2  gray(226)
0,2: ( 79, 79, 79)  #4F4F4F  gray(79)
0,3: (108,108,108)  #6C6C6C  gray(108)
0,4: (126,126,126)  #7E7E7E  gray(126)
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: intensity and grayscale

Post by magick »

We can reproduce the problem you posted and have a patch in ImageMagick 6.8.5-9 Beta available by sometime tomorrow. Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: intensity and grayscale

Post by fmw42 »

Just to be clear if any questions. Lightness is the average of the min and max of RGB. Brightness is just the max.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: intensity and grayscale

Post by snibgo »

Yes. "Brightness" is the maximum of RG and B; "Average" is the average, and "Lightness" should be the average of the minimum and maximum. To complete the picture, perhaps we could also have a "Minimum", though I can't see any use for it.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: intensity and grayscale

Post by fmw42 »

As you pointed out before (with -evaluate-sequence), you can easily get that using

convert image -separate -evaluate-sequency min result

But there are reasons that Lightness =( Max + Min)/2 and Brightness = Max and Intensity = (R+G+B)/3. They come from the color conversions to HSL and HSB and HSI using the double and single hexcone models. There is no colorspace model that happens to use just the min, that I know about. So I see no reason to make it special, in my opinion.

see (if you are not already familiar with this ref)
http://en.wikipedia.org/wiki/HSL_and_HSV
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: intensity and grayscale

Post by fmw42 »

Just installed IM 6.8.5.9 Q16 Mac OSX Snow Leopard

Testing:
convert rose: -grayscale lightness 1tmpL.png
convert rose: -grayscale brightness 1tmpB.png
convert rose: -grayscale average 1tmpA.png
convert rose: -grayscale rms 1tmpR.png


Lightness does not look right and does not match

convert rose: -fx "(max(max(u.r,u.g),u.b) + min(min(u.r,u.g),u.b))/2" 1rose_lightness.png

The others match fine to

convert rose: -fx "max(max(u.r,u.g),u.b)" 1rose_brightness.png
convert rose: -fx "(u.r+u.g+u.b)/3" 1rose_ave.png
convert rose: -fx "sqrt((u.r^2+u.g^2+u.b^2)/3)" 1rose_rms.png


But there is still no difference between

convert rose: -grayscale rec601luma 1roseluma.png
convert rose: -grayscale rec601luminance 1roseluminance.png
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: intensity and grayscale

Post by magick »

We can reproduce the problem you posted and have a patch in ImageMagick 6.8.5-10 Beta available by sometime tomorrow. Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: intensity and grayscale

Post by fmw42 »

Seems to be fixed in 6.8.5.10 Q16 beta

Thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: intensity and grayscale

Post by snibgo »

Thanks, magick.

Fred, can you check that Rec709Luma and Rec709Luminance are also different to each other? Thanks.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: intensity and grayscale

Post by fmw42 »

snibgo wrote:Thanks, magick.

Fred, can you check that Rec709Luma and Rec709Luminance are also different to each other? Thanks.

Yes, I tested that also and they are different as they should be with rec601luminance being very dark and lightness is correct also.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: intensity and grayscale

Post by anthony »

Just remember some of these are 'mathematical' in that they will not take into account the colorspace of the input image.

as such transforming the image to a 'linear RGB' first will produce a different result.

Others (such as Rec709Luma) will take into account the colorspace of the input image, and so will get the same result regardless of if the image was transformed to a different colorspace before hand.

The mathematical ones are important for handling images such as a 'difference of two images'. Letting you say convert that difference into a 'color vector distance' or 'difference error squared'. Basically defining different 'error metrics' similar to what is seen from a "compare", whether you then want the maximum error, or average error of the pixels is the next step.

More such 'metrics' possibly depending on such things as alpha channel masking can also then be DIY'd
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply