Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".

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)!

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.

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.

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!

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.

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.

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.

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 ?

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.

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.

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.