Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am trying to classify a set of images into grayscale or color groups. I have been using ImageMagic to do that, comparing the color image to a grayscale version of itself and then using the Peak Error to determine if it is a grayscale image, as shown here:

http://www.imagemagick.org/Usage/compare/#type_general

This is working, however, it is producing false results for a lot of back and white images. I have tracked this issue down and I believe it is being caused by pseudo-black pixels (e.g.: rgb(0,0,5)). These psuedo black pixels appear as full color, because they technically are.

Is there a better way to classify these images?

What would you suggest I do to get rid of these false results?

share|improve this question
2  
@Framester I disagree. The OP isn't asking for code to get this done, he's asking for strategies to classify these images and if I'm not mistaken, this is well within the scope of Programmers.SE. –  Marvin Pinto Jan 20 '12 at 16:36
    
@Framester As Marvin pointed out the question is perfectly suitable for Programmers. Furthermore it's possibly off topic on SO (no code). Please refrain from such comments if not absolutely certain. We have a huge problem with people on SO incorrectly point people to Programmers, let's not do the reverse. –  Yannis Rizos Jan 20 '12 at 16:49
1  
@Sergio. Can you provide concrete example images where the two approaches failed? –  Framester Jan 20 '12 at 17:02
    
Can you clarify what you mean by 'classify a set of images into grayscale or color groups'? Are you simply trying to detect when an image is grayscale? Or are there different groups of color images you are trying to map to? –  GrandmasterB Jan 20 '12 at 19:19
add comment

2 Answers

Convert the images to another color space like HSV and than just check the S component. S stands for saturation and the saturation should be (nearly) 0 for all grayscale images. Here is the documentation from ImageMagick: http://www.imagemagick.org/script/color.php

share|improve this answer
    
I already tried this solution as well, and it is producing more false positives than the one I posted. I am trying to find a way to combine these two in order to get a more accurate classification. These two approaches fail in different ways, by the way. –  Sergio R. Jan 20 '12 at 16:53
add comment

Your problem is setting the margin of error too strictly for classifying an image as black and white. The trick is to not go too far the other way and falsely classify color images as black and white.

Do some research on Bayes classification. Basically, you do the classification manually for a sample of your images. That will give you the total probability of an image being black and white in your collection, as well as the probabilities of an average saturation in any given black and white image. Then, you use a formula to compare the probability of a new unknown image being a black and white image versus the probability of it being color, given its average saturation.

For example, say 10% of the images in your collection are black and white, 20% of black and white images have an average saturation of 5, but only 1% of color images have an average saturation of 5.

black and white posterior for saturation of 5 = 0.1 * 0.2 = 0.02
color posterior for saturation of 5 = 0.9 * 0.01 = 0.009

So you would classify an image with saturation of 5 as black and white.

The nice thing about Bayes classification is that you can use more than one factor in your determination, if you find another feature that you think is useful in addition to saturation. Maybe maximum saturation works better than average, or you can combine the two. Also, you don't have to guess at the right cutoff point, because it's based on your training set.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.