title: Automatically recognize patterns in images
body: <p>Recently I downloaded some flags from the <a href="https://www.cia.gov/library/publications/the-world-factbook/docs/flagsoftheworld.html" rel="noreferrer">CIA world factbook</a>. Now I want to "classify them.</p>
  
  <ol>
  <li>Get the colors</li>
  <li>Get some shapes (stars, moons etc.)</li>
  </ol>
  
  <p>While browsing I came across the Python Image Library which allows me to extract the colors (i.e. for <a href="https://www.cia.gov/library/publications/the-world-factbook/flags/flagtemplate_au.html" rel="noreferrer">Austria</a>:</p>
  
  <pre><code>#!/usr/bin/env python
  import Image
  bild = Image.open("au-lgflag.gif").convert("RGB")
  bild.getcolors()
  [(44748, (255, 255, 255)), (452, (236, 145, 146)), (653, (191, 147, 149)), ...)]
  </code></pre>
  
  <p>What I found strange here is that the austrian flag only has two colors in it, but the above output shows more than ten. Do you know why? My idea was to only count the top 5 colors and as I'm not interested in <em>every</em> color I would do some "normalize" the numbers to multiples of 64 (so (236, 145, 146) becomes (192, 128, 128)).</p>
  
  <p>However at the moment I have no idea what is the best way to extract more information (Ist there a star in the image? or else). Could you give me some hints on how to do it?</p>
  
  <p>Thanks in advance</p>