Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically recognize patterns in images

Recently I downloaded some flags from the CIA world factbook. Now I want to "classify them.

  1. Get the colors
  2. Get some shapes (stars, moons etc.)

While browsing I came across the Python Image Library which allows me to extract the colors (i.e. for Austria:

#!/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)), ...)]

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 every color I would do some "normalize" the numbers to multiples of 64 (so (236, 145, 146) becomes (192, 128, 128)).

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?

Thanks in advance

like image 289
qbi Avatar asked Jul 14 '10 22:07

qbi


People also ask

How do you find the pattern recognition in an image?

The process of image pattern recognition includes four steps: image acquisition, image preprocessing, image feature extraction and classification. For image preprocessing, more attention is given to image cropping and image enhancement, which are two important steps in dealing with biometric images.

What is automated pattern recognition?

Pattern recognition is the automated recognition of patterns and regularities in data. It has applications in statistical data analysis, signal processing, image analysis, information retrieval, bioinformatics, data compression, computer graphics and machine learning.

What is pattern recognition in image?

Pattern recognition is a data analysis method that uses machine learning algorithms to automatically recognize patterns and regularities in data. This data can be anything from text and images to sounds or other definable qualities.

Can AI recognize patterns?

Most prominently, fields of artificial intelligence aim to enable machines to solve complex human recognition tasks, such as recognizing faces or objects. Accordingly, pattern recognition is a branch of Artificial Intelligence.


1 Answers

The Python Imaging Library - PIL just does basic image manipulation - opening, some transforms or filters, and saving to other formats.

Pattern recognition, is part of an advanced image processign field and evolving -- it deos use algorithms far different than those present in PIL.

There are some libraries and frameworks you can use in Python for pattern recognition - (recognising stars, and moons, and so) - Although I advance you: if you want this just to classify one0-hundered-and-a-few coutnry flags, you should do it manually, rather than try to dive in pattern recognition.

Your comment on the number of colors tells that you are not used with computer images at all. And pattern recognition is hardcore, even with a python front-end. (You can't expect any current framework to know beforehand what is a "moon" or a "star" for example)

So, for less than 500 images, you can resort to software that allows you to tag images manually and write some code to link the tags to each flag.

As for the colors: Computer rasterized images are formed of pixels. These are Square. At the boundary between different colors, if a pixel is on one color (say white), and its neighbor is a complete different color (like red), this boundary will show up jagged. This is known as "aliasing". To diminish this, computer software mixes colors at hard boundaries, creating intermediate colors - that is why a PNG even with 2 apparent colors can have several colors internally. For .JPG it is even worse, because the rounded decimal numbers for RGB colors we use are not even stored as they are in the image.

Unlike pattern recognizing, you can downsize the number of colours seen by using just the most significant bits of each component. I'd say the two most significant bits would be enough. The following python function could do that using a color count given by PIL:

def get_main_colors(col_list):
    main_colors = set()
    for index, color in col_list:
        main_colors.add(tuple(component >> 6 for component in color))
    return [tuple(component << 6 for component in color) for color in main_colors]

call it with "get_main_colors(bild.get_colors()) " for example.

Here is another question dealing with the pattern recognition part: python image recognition

like image 132
jsbueno Avatar answered Sep 21 '22 17:09

jsbueno