"See" if a picture is BW

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?".
Post Reply
xpt
Posts: 59
Joined: 2010-10-06T20:18:24-07:00
Authentication code: 8675308

"See" if a picture is BW

Post by xpt »

Hi,

Is it possible to use any tool to detect whether a picture is black-and-white?

I guess the first level is to find all gray-tone images, and the second would be to find all images that has color pallets yet still are black-and-white. The problem is how.

Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "See" if a picture is BW

Post by fmw42 »

by black/white do you mean bi-level or just grayscale. In the verbose info it should say either bilevel, bilevelmatte or grayscale, grayscalematte depending upon the situation. identify -verbose yourimage

convert rose: -colorspace gray -verbose info:
...
Type: Grayscale
...


convert rose: -monochrome -verbose info:
...
Type: Bilevel
...



or use string formats:

convert rose: -colorspace gray -format "%r" info:
DirectClassGray

convert rose: -monochrome -format "%r" info:
PseudoClassGray

convert rose: -colorspace gray -format "%[colorspace]" info:
Gray

convert rose: -monochrome -format "%[colorspace]" info:
Gray



convert rose: -colorspace gray -format "%k" info:
2884

convert rose: -monochrome -format "%k" info:
2
xpt
Posts: 59
Joined: 2010-10-06T20:18:24-07:00
Authentication code: 8675308

Re: "See" if a picture is BW

Post by xpt »

PERFECT!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: "See" if a picture is BW

Post by anthony »

There is a section in IM Examples, Comparing Images, whcih looks at trying to group images by type (as part of a pre-processing step for comparision). On of those types is a measure of how close to pure 'Black and White' or more likely what you want, how close to 'Grayscale' the image is.

One of my other tests whcih is only mentioned in passing is determining if the colors in a colorful image is actually linear colors, That is, test weather the image is really a linearly colored greyscale image!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "See" if a picture is BW

Post by fmw42 »

xpt wrote:PERFECT!

Just curious, but you never really said whether you are distinguishing between grayscale and bilevel?
Post Reply