Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a large amount of jpeg thumbnail images ranging in size from 120x90 to 320x240 and I would like to classify them as either Real Life-like or Cartoon-like.

Are there any applications that will have cartoon classification capabilities?

This application should work on Linux, and should take an image path on the command-line and return either 0 or 1 (echo $?).

share|improve this question
What exactly are you after? A program that will allow you to manually tag images, or a program that will automatically tag pictures as either cartoon or real-life? Also, what operating system? – Josh Hunt Oct 5 '09 at 5:23
I've edited my submission to include answers to your questions. – user13212 Oct 5 '09 at 5:40
I think you need to be more specific about what you mean by "Cartoon like". If they are line drawings with solid fills, it's farily simple. If they contain shading, it gets a lot harder. – rjmunro Jan 20 '11 at 10:24

I think you could do something like this with Imagemagick. It has image quantization and histogram analysis features that you'll probably need to give this a real treatment.

The simplest thing to do is count the number of unique colors in each picture - cartoons should generally have fewer than photos. This may work as is if your search space is fairly simple. i.e. differentiating simple cartoons form color photos. If you have 'fancy' cartoons, you may have to add additional checks. I added an extra echo for RGB vs. Grey color space before checking each image.

A more sophisticated test might involve checking the histogram, either total or in RGB space of each image.


for i in `ls *.jpg`
    echo "$i is `convert $i -format \"%[colorspace]\" info:`"
    x=`convert $i -unique-colors txt:- | wc -l`

    if [ $x -le 512 ]; then
        echo "$i is cartoon like ($x)"
    elif [ $x -le 1024 ]; then
        echo "$i is a bw photo ($x)"
        echo "$i is real life-like ($x)"

The main complication is separating complex computer animations from b&w photos. A B&W photo may have relatively few unique colors in it, while a sophisticated cartoom may have thousands due to computer aided shading. You'll probably need to experiment with the thresholds for 'X' depending on what your images look like.

share|improve this answer
"cartoons should generally have fewer than photos" .. not always true, think of color gradients. i would try to use an edge-detecor (google sobel, laplace etc) .. and then use that information to decide, if its a cartoon or not. real life pictures tend to have much more noise in such 'edge pictures' – akira Oct 5 '09 at 9:02
I agree, which is why I prefaced it with 'the simplest thing'. With no information on what these cartoons were like, I went with the simplest thing that just might work. – DaveParillo Oct 5 '09 at 15:25
This topic is specifically discussed on the imagemagick web site: . An outline of a solution is described, but not a concrete example. Maybe I'll write one tonight... – DaveParillo Oct 5 '09 at 16:07

Provided that you have images that you can show to school children and there are lots of cartoons.

You can go to a school and use HUMAN COMPUTING.

share|improve this answer

You must log in to answer this question.