First i want to thank you for all the help. So far what i was able to do with ImageMaick is great. Is it possible to use below command and somehow exclude pixle close to gray scale pixle when averaging for color. I have jpg images [img]c:\test.jpg[/img]
convert c:\images\test.jpg -colorspace HCL -channel green -separate +channel -format "%M %[fx:100*mean]\n" info:
Telling the difference between color and grayscale image
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Telling the difference between color and grayscale image
First I create a test image that is black with a small area of red in the middle.
If you want to know the color, do the following:
red
If you want to know the percentage of the red, then do
4
So this is 4% red and the rest is pure grayscale.
Note I have used 1% in the threshold, you can change that if you want. The larger the value, the more "color" will be considered gray.
Code: Select all
convert -size 500x500 xc:gray -size 100x100 xc:red -gravity center -compose over -composite gray_red.png
Code: Select all
convert gray_red.png \
\( -clone 0 -colorspace HCL -channel green -separate -threshold 1% \) \
-alpha off -compose copy_opacity -composite -scale 1x1! -alpha off \
-format "%[pixel:u.p{0,0}]\n" info:
If you want to know the percentage of the red, then do
Code: Select all
convert gray_red.png -colorspace HCL -channel green -separate +channel -threshold 1% -format "%[fx:100*mean]\n" info:
So this is 4% red and the rest is pure grayscale.
Note I have used 1% in the threshold, you can change that if you want. The larger the value, the more "color" will be considered gray.