Page 1 of 1

check if a picture is perfect grayscale

Posted: 2015-08-25T11:57:03-07:00
by baxter stockman
Hi,

Not sure if this is the right forum here, and I'm a noob, sorry! How do I check if a picture is a perfect grayscale?

I tried

Code: Select all

identify -verbose myfile.png 
and got these numbers:
Rendering intent: Perceptual
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Interlace: None
Background color: white
Border color: srgba(223,223,223,1)
Matte color: grey74
Transparent color: none
Compose: Over
Page geometry: 718x256+0+0
Dispose: Undefined
Iterations: 0
Compression: Zip
Orientation: Undefined
Properties:
date:create: 2015-08-25T11:39:25-07:00
date:modify: 2015-08-25T10:23:35-07:00
png:cHRM : chunk was found (see Chromaticity, above)
png:gAMA : gamma=0.45454544 (See Gamma, above)
png:IHDR.bit_depth : 8
png:IHDR.color_type : 6 (RGBA)
png:IHDR.interlace_method: 0 (Not interlaced)
png:IHDR.width,height : 718, 256
png:sRGB : intent=0 (See Rendering intent)
signature: bc27611faa2f558af2d23572aacad0875e0c68719030fe9636df775a07ca74dd
Artifacts:
filename: grey1.png
verbose: true
Tainted: False
Filesize: 15.7KB
Number pixels: 184K
Pixels per second: 18.38MB
User time: 0.010u
Elapsed time: 0:01.010
which one shoes me if it's a perfect greyscale?

Thanks in advance

Re: check if a picture is perfect grayscale

Posted: 2015-08-25T12:04:15-07:00
by fmw42
Look further up in the information listed by identify -verbose and it should show type=grayscale or type=truecolor or type=palette. If type is grayscale or bilevel, then it is grayscale. But this may not work for other image formats.

The better way is to check the mean of the R,G,B channel statistics. It is grayscale if all 3 have the very same mean value.

Re: check if a picture is perfect grayscale

Posted: 2015-08-25T12:24:45-07:00
by baxter stockman
it says
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 718x256+0+0
Resolution: 72x72
Print size: 9.97222x3.55556
Units: Undefined
Type: TrueColorAlpha
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 8-bit
Channel statistics:
Red:
min: 0 (0)
max: 255 (1)
mean: 6.45785 (0.0253249)
standard deviation: 33.8304 (0.132668)
kurtosis: 40.7964
skewness: 6.32248
Green:
min: 0 (0)
max: 255 (1)
mean: 6.45785 (0.0253249)
standard deviation: 33.8304 (0.132668)
kurtosis: 40.7964
skewness: 6.32248
Blue:
min: 0 (0)
max: 255 (1)
mean: 6.45785 (0.0253249)
standard deviation: 33.8304 (0.132668)
kurtosis: 40.7964
skewness: 6.32248
Alpha:
min: 0 (0)
max: 255 (1)
mean: 15.6606 (0.0614141)
standard deviation: 60.9013 (0.238828)
kurtosis: 11.3877
skewness: -3.65404
so type would be TrueColorAlpha, what does that mean?

Re: check if a picture is perfect grayscale

Posted: 2015-08-25T12:26:52-07:00
by baxter stockman
Oh hold on, since RGB is all the same it means it is greyscale right?

Re: check if a picture is perfect grayscale

Posted: 2015-08-25T12:37:07-07:00
by fmw42
baxter stockman wrote:Oh hold on, since RGB is all the same it means it is greyscale right?
Correct.

Re: check if a picture is perfect grayscale

Posted: 2015-08-25T12:51:38-07:00
by snibgo
For an ordinary photograph, having all three means equal suggests the image is probably grayscale.
fmw42 wrote:The better way is to check the mean of the R,G,B channel statistics. It is grayscale if all 3 have the very same mean value.
All grayscale images will have the same mean in all the channels, true. But vice versa is not true. An image with three pixels, one each of red, green and blue will have the same mean in all three channels but clearly isn't grayscale.

If IM reports an image as grayscale, then it is. If IM reports it has three channels, you can convert the image to grayscale, and see if any pixels have changed.

Code: Select all

convert rose: ( +clone -colorspace Gray ) -metric AE -compare -format %[distortion] info:
With metric AE, 0 means no pixels have changed, so it was grayscale.

Or you can use RMSE if you care how different from gray the image is.

Re: check if a picture is perfect grayscale

Posted: 2015-08-25T12:56:26-07:00
by fmw42
Good point snibgo. Thanks.

(Though that situation will be quite rare if not impossible for "real" photographs, and so not very likely to happen. But point taken if one wants to be absolute sure of any image being grayscale.)

Re: check if a picture is perfect grayscale

Posted: 2015-08-25T13:11:18-07:00
by baxter stockman
perfect thank you!