codewalker has asked for the wisdom of the Perl Monks concerning the following question:

I need to check whether the given image is in color or black and white using perl.

Is it is possible?

  • Comment on To check color of image using perl script

Replies are listed 'Best First'.
Re: To check color of image using perl script
by Corion (Patriarch) on Dec 18, 2014 at 09:39 UTC
Re: To check color of image using perl script
by SuicideJunkie (Vicar) on Dec 18, 2014 at 14:35 UTC

    Of course (see above). Now you need to think about details.

    When you say Black & White, do you mean bitonal 1-bit color, or greyscale?

    Does a 32bit-color image count as B&W if the only colors used are Black + White? Does it count if the saturation of every pixel is (close to?) zero? (IE greys)

    Would you count a sepia tone image, which is basically greyscale with the blue reduced or removed. (All hues are the same)

Re: To check color of image using perl script
by karlgoethebier (Abbot) on Dec 18, 2014 at 10:58 UTC
Re: To check color of image using perl script
by DanBev (Scribe) on Dec 18, 2014 at 15:40 UTC

    Hi codewalker, maybe this can help you or you can get an idea.

    I've had a similar issue in a mail-to-fax context: the fax could be too black, maybe for an error. So, I cycle through the ps file (I create a ps from tiff by requirement) and count the frequency of '0' characters ('black' in ps). If this is too high, I deduce the image is too black.

    Can you dig into the image and count the values, if there are only 'black' and 'white' or various 'gray' or if there are other colours?

    What do you think about?