Page 1 of 4
How to check image color or back and white
Posted: 2011-10-04T02:59:02-07:00
by vanquang
Hi
i need check image color (don't accept back and white)
how to check it?
Re: How to check image color or back and white
Posted: 2011-10-04T09:39:34-07:00
by fmw42
vanquang wrote:Hi
i need check image color (don't accept back and white)
how to check it?
Please clarify? Do you mean you don't want any image that is totally black or totally white? Or do you mean you don't want any image that has even 1 black or 1 white pixel?
Re: How to check image color or black and white
Posted: 2011-10-04T17:58:40-07:00
by anthony
For methods of sorting images into categories see...
Image Comparing, Sorting Images by Type
http://www.imagemagick.org/Usage/compare/#type_general
Whcih is also closely related to generating Image Metrics, for sorting before comparisons or database storage
http://www.imagemagick.org/Usage/compare/#metrics
What about line drawings or text? These are typically not truely black and white but mostly black and white with grey anti-aliasing pixels.For example...
Or even... mostly two color gradient images (red on white with anti-aliasing) such as this.
or images with large expanses of pure black or white, or a specific color?
or just a small segment of pure color -- this rose image as an area of pure white!
Also what about greyscale images?
Or images with little 'energy' in the form of edges, only smooth color gradients
What about transparency?
Or even animations (simple or of real images)
Basically you need to define exactly what you want to include or exclude!
Then we can work out something that can detect such images.
While we are on this topic, does anyone have any other basic 'types' of images?
Note I have ignored 'real world photos' which typically do not fit in the above basic groups, but has large numbers of image sub-categories in and of itself (faces, groups, seascapes, buildings, etc)!
Re: How to check image color or back and white
Posted: 2011-10-04T18:27:36-07:00
by vanquang
fmw42 wrote:vanquang wrote:Hi
i need check image color (don't accept back and white)
how to check it?
Please clarify? Do you mean you don't want any image that is totally black or totally white? Or do you mean you don't want any image that has even 1 black or 1 white pixel?
when i use ImageMagick check an image (not compare image)
if check image:
return true
if check
then return false
how to implement it?
Re: How to check image color or black and white
Posted: 2011-10-04T18:29:34-07:00
by vanquang
anthony wrote:For methods of sorting images into categories see...
Image Comparing, Sorting Images by Type
http://www.imagemagick.org/Usage/compare/#type_general
Whcih is also closely related to generating Image Metrics, for sorting before comparisons or database storage
http://www.imagemagick.org/Usage/compare/#metrics
What about line drawings or text? These are typically not truely black and white but mostly black and white with grey anti-aliasing pixels.For example...
Or even... mostly two color gradient images (red on white with anti-aliasing) such as this.
or images with large expanses of pure black or white, or a specific color?
or just a small segment of pure color -- this rose image as an area of pure white!
Also what about greyscale images?
Or images with little 'energy' in the form of edges, only smooth color gradients
What about transparency?
Or even animations (simple or of real images)
Basically you need to define exactly what you want to include or exclude!
Then we can work out something that can detect such images.
While we are on this topic, does anyone have any other basic 'types' of images?
Note I have ignored 'real world photos' which typically do not fit in the above basic groups, but has large numbers of image sub-categories in and of itself (faces, groups, seascapes, buildings, etc)!
when use "-format", "%k", i get an number (eg:2064) is mean?
i don't know it.
Re: How to check image color or back and white
Posted: 2011-10-04T19:06:50-07:00
by anthony
vanquang wrote:if check image:
return true
if check
then return false
how to implement it?
See... Compare, Sorting Images by Type, Gray-scale vs Color
http://www.imagemagick.org/Usage/compar ... _greyscale
Basically you convert the image to HSL and then output verbose information ("identify" statistics).
In HSL space Saturation define how colorful pixels are, and this is returned in the 'Green' channel statistics.
For example...
Code: Select all
convert rose_grey.gif -colorspace HSL -verbose info:
Code: Select all
...
Green:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
...
Max is 0 so no color was present at all! -- It is a perfect grayscale (or black and white) image
The original color rose image on the other hand generated...
Code: Select all
Green:
min: 2 (0.00636301)
max: 255 (1)
mean: 101.764 (0.399074)
standard deviation: 71.0352 (0.278569)
kurtosis: -1.0037
skewness: 0.44952
Showing there was at least one pure color pixel (max = 100%) -- not pure grayscale
and that the image was very colorful in general too (mean is 39.9%) -- not even mostly grayscale (white background)!
Other statistics show how the color ratios was distributed about that mean.
Another method is to compare a grayscale version of the image with the original input image and see how different they are. This will let you find what pixels (areas) in the input image are colorful and by how much!
Re: How to check image color or back and white
Posted: 2011-10-04T19:17:59-07:00
by vanquang
anthony wrote:vanquang wrote:if check image:
return true
if check
then return false
how to implement it?
See... Compare, Sorting Images by Type, Gray-scale vs Color
http://www.imagemagick.org/Usage/compar ... _greyscale
Basically you convert the image to HSL and then output verbose information ("identify" statistics).
In HSL space Saturation define how colorful pixels are, and this is returned in the 'Green' channel statistics.
For example...
Code: Select all
convert rose_grey.gif -colorspace HSL -verbose info:
Code: Select all
...
Green:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
...
Max is 0 so no color was present at all! -- It is a perfect grayscale (or black and white) image
The original color rose image on the other hand generated...
Code: Select all
Green:
min: 2 (0.00636301)
max: 255 (1)
mean: 101.764 (0.399074)
standard deviation: 71.0352 (0.278569)
kurtosis: -1.0037
skewness: 0.44952
Showing there was at least one pure color pixel (max = 100%) -- not pure grayscale
and that the image was very colorful in general too (mean is 39.9%) -- not even mostly grayscale (white background)!
Other statistics show how the color ratios was distributed about that mean.
Another method is to compare a grayscale version of the image with the original input image and see how different they are. This will let you find what pixels (areas) in the input image are colorful and by how much!
when use "-format", "%k", i get an number (eg:2064) is mean?
i don't know it.
because i use in vbscript, please send
Re: How to check image color or back and white
Posted: 2011-10-04T19:27:21-07:00
by fmw42
You are getting the number of shades of gray as 2064 from %k (unique colors or shades of gray)
try
convert rose: -format "%[colorspace]" info:
RGB
convert rose: -type grayscale -format "%[colorspace]" info:
Gray
This only works if your image is pure grayscale. Otherwise, you need to do as Anthony suggests and use the saturation image and threshold to test if low enough saturation that you would consider it gray.
Re: How to check image color or back and white
Posted: 2011-10-04T19:44:49-07:00
by vanquang
in vb script:
Code: Select all
Set img = CreateObject("ImageMagickObject.MagickImage.1")
reponse.write img.convert(fullpath,"-colorspace","HSL","-verbose")
return (w,h,type) only:
not return:
Green:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
Re: How to check image color or back and white
Posted: 2011-10-04T20:17:36-07:00
by fmw42
try adding -format
Re: How to check image color or back and white
Posted: 2012-02-22T07:38:59-07:00
by wvanoeveren
hello,
I guess this should be right post where i should put my question since i'm currently in search of a good method on how to determine if an image is more color than B/W.
I would like to use some kind of threshold but based on the different properties of the image (size, dpi, width, height, ...) so that i can determine whether i should take the color or the B/W image.
Is it possible to give me 1 (or more) command lines which i can use (returning their info) so that i can use it towards the threshold settings ?
Thanks in advance !
Wim
Re: How to check image color or back and white
Posted: 2012-02-22T10:50:02-07:00
by fmw42
try testing the mean (average) saturation of the image.
convert image -colorspace HSL -channel g -separate +channel -format "%[fx:mean]" info:
When the image is perfectly grayscale, the saturation result will be zero. The larger the resulting number (in range 0 to 1) the more color is involved. So you can decide on some threshold value for your decision about how much color to allow while still be nearly grayscale.
You can test this by using -modulate to adjust the saturation for an image. See
http://www.imagemagick.org/script/comma ... p#modulate and
http://www.imagemagick.org/Usage/color_mods/#modulate
convert logo: -modulate 100,X,100 -colorspace HSL -channel g -separate +channel -format "%[fx:mean]" info:
when X=0, you get totally grayscale and the result is 0
when you increase X towards 100, you get a larger result as more color is allowed in the image.
Re: How to check image color or back and white
Posted: 2014-10-03T13:49:02-07:00
by JulietLindl
My images keep coming out in black and white with ImageMagick? I'll try the suggestions here and report back my results. Thanks
Re: How to check image color or back and white
Posted: 2014-10-03T14:27:57-07:00
by fmw42
JulietLindl wrote:My images keep coming out in black and white with ImageMagick? I'll try the suggestions here and report back my results. Thanks
Please clarify. It is not clear what your issue is. You seem to have added a new post to an old topic, which may or may not be relevant to the old topic. In the future, please create a new post even if similar to an old one. And always provide your IM version and platform.
Please read
viewtopic.php?f=1&t=9620, which is the top link on the User's forum.
Re: How to check image color or back and white
Posted: 2016-05-27T22:42:34-07:00
by fmw42
fmw42 wrote:try testing the mean (average) saturation of the image.
convert image -colorspace HSL -channel g -separate +channel -format "%[fx:mean]" info:
Due to HSL being a double hexcone model, this colorspace does not work properly for measuring saturation for L>50% as it approaches the top peak. There white is going to be indetermined saturation and turns out is interpreted as high saturation. In its place, use HCL, HCLp, HSI or HSB above. These are all single hexcone type models and should work fine in the above equation.
Reference:
https://en.wikipedia.org/wiki/HSL_and_HSV