Page 1 of 2
How to identify a grayscale image (with threshold)?
Posted: 2009-10-06T10:06:07-07:00
by codeswitch
I know how to find out if an image is a true color image or a grayscale image.
But what I'd like to have is the solution on how to identify for example this image:
http://www.pitopia.de/scripts/pictures/ ... D=2&view=1 as a grayscale image.
The whole picture is black and white, except for the eyes which are green. For people it's still black and white.
Is there maybe a solution anywhere on the web? I can't find anything useful. I hope you can inspire me somehow
.
Re: How to identify a grayscale image (with threshold)?
Posted: 2009-10-06T11:31:51-07:00
by fmw42
if there is any color in the image, any statistics such as class or type will tell you it is color and not grayscale.
I think you only hope is to analyze the histogram and decide if there is less than some total percent color other than black or white in the image.
Re: How to identify a grayscale image (with threshold)?
Posted: 2009-10-06T16:24:37-07:00
by anthony
Read in the image, make a clone whcih you greyscale. now compare the original image with the grayscale clone. any differences present is non grayscale color.
see...
Sorting Images by Type, Gray-scale vs Color
http://www.imagemagick.org/Usage/compare/#type_general
I have updated that part with a 'saturation test'
Saturation Test
convert rose: granite: \
-colorspace HSB -channel G -separate +channel \
-format 'avg=%[mean] peak=%[maximum]' info:
rose: -> avg=28750.1 peak=59881
granite: -> avg=1918.87 peak=3490
Numbers are relative to QuantumRange (which in my IM Q16 is 65535)
Note that both have a avg that is about 1/2 that of the peak.
With rose: being very colorful, while granite: only has about 5% color.
The a large difference than 1/2 between the average and peak, would-
indicate small patches of color. Thresholding the saturation channel
can generate a mask of the color area.
Re: How to identify a grayscale image (with threshold)?
Posted: 2009-10-07T08:37:44-07:00
by codeswitch
Well, thank you very much, but it's a little too complicated for me. I hoped for an easy solution.
But never mind, I using PHP itself to do it. It's not perfect, but it'll do.
If anyone wants the code I'll post it here to be discussed.
Re: How to identify a grayscale image (with threshold)?
Posted: 2017-08-07T14:08:44-07:00
by divptl
Hi i am trying to have the code Anthony wrote above work but i keep getting error " convert: unable to open image 'avg-
i am not getting the results he has above. Any help will be appropriated.
I CD to the folder and I have rose and granite both in the ImageMagic dir and trying to run below.
convert rose: granite: \-colorspace HSB -channel G -separate +channel \-format 'avg=%[mean] peak=%[maximum]' info:
Re: How to identify a grayscale image (with threshold)?
Posted: 2017-08-07T14:15:23-07:00
by divptl
Over all i need to separate gray scale image from color but has some color pix in the mix.
Re: How to identify a grayscale image (with threshold)?
Posted: 2017-08-07T14:34:39-07:00
by snibgo
What version IM? On what platform?
Code: Select all
convert rose: granite: \-colorspace HSB -channel G -separate +channel \-format 'avg=%[mean] peak=%[maximum]' info:
Why does your command contain backslashes?
divptl wrote:... and I have rose and granite both in the ImageMagic dir ...
That doesn't make sense. "rose:" and "granite:" (both with colons) are built into IM.
Re: How to identify a grayscale image (with threshold)?
Posted: 2017-08-08T06:04:36-07:00
by divptl
I have the latest version of IM 7.0.6. I am attempting to do same what Anthony did. i kept the blackslashes and removed the line brake from below.
"
Saturation Test
convert rose: granite: \
-colorspace HSB -channel G -separate +channel \
-format 'avg=%[mean] peak=%[maximum]' info:
rose: -> avg=28750.1 peak=59881
"
Re: How to identify a grayscale image (with threshold)?
Posted: 2017-08-08T06:05:04-07:00
by divptl
I have the latest version of IM 7.0.6. I am attempting to do same what Anthony did. i kept the blackslashes and removed the line brake from below.
"
Saturation Test
convert rose: granite: \
-colorspace HSB -channel G -separate +channel \
-format 'avg=%[mean] peak=%[maximum]' info:
rose: -> avg=28750.1 peak=59881
"
Re: How to identify a grayscale image (with threshold)?
Posted: 2017-08-08T09:14:49-07:00
by fmw42
There is no %[maximum] it is %[max] (see
http://www.imagemagick.org/script/escape.php). Try
Code: Select all
magick rose: granite: \
-colorspace HSB -channel G -separate +channel \
-format 'avg=%[mean] peak=%[max]\n' info:
avg=28750.1 peak=59881
avg=1918.71 peak=3490.03
Re: How to identify a grayscale image (with threshold)?
Posted: 2017-08-08T10:20:21-07:00
by divptl
Thank you it worked however my grayscale image has some colors in it and i will have to go on another rout. Is there a way to identify like Image generated out of a Patent software vs actual picture taken from camera ? i have no image property to relay on.
Re: How to identify a grayscale image (with threshold)?
Posted: 2017-08-08T10:22:53-07:00
by fmw42
See
viewtopic.php?f=1&t=16201#p148602
Code: Select all
convert mostly_gray.png -colorspace HCL -channel green -separate +channel -format "%[fx:100*mean]\n" info:
4.2631
So this image contains 4% non-grayscale colors.
A true grayscale image with no color, such as a white to black gradient will have a result of zero.
Code: Select all
convert -size 256x256 gradient: -colorspace HCL -channel green -separate +channel -format "%[fx:100*mean]\n" info:
0
Re: How to identify a grayscale image (with threshold)?
Posted: 2017-08-08T12:00:34-07:00
by divptl
Thank you that works. Any way to tell if its graphic vs picture ? Unfortunately with threshold i am still getting color images in to gray scale because they only have three colors .
Re: How to identify a grayscale image (with threshold)?
Posted: 2017-08-08T12:58:12-07:00
by divptl
On more question . do you know how would i go about implementing "convert mostly_gray.png -colorspace HCL -channel green -separate +channel -format "%[fx:100*mean]\n" info:" in c# ?
Re: How to identify a grayscale image (with threshold)?
Posted: 2017-08-08T13:07:35-07:00
by divptl
i want to utilize the output to move file if it's above or below threshold.