Saturday, May 12, 2012

Using F# to create a simple image search, i.e. using one image to search for other like images...

dzone - Solr-Lucene Zone - A Simple Search by Image Engine in F#

Last week I was playing with a photomosaic composer toy project and needed a simple search by image engine. By search by image I mean searching a database for an image similar to a given one. In this tutorial I will show you how you can implement this functionality –with some obvious limitations– in an extremely simple way just by looking at an image’s color distribution.

If you are looking for feature similarity (shapes, patterns, etc.) you most likely need edge detection algorithms (linear filters or other similar methods), which give excellent results but are usually quite complicated. I suppose that’s the way most image search engines work. Alternatively this paper describes the sophisticated color-based approach used by Google’s skin-detection engine.

In many cases however, finding images with a perceptually similar color distribution can be enough.

If you are in this situation, you may get away with a very simple technique that still gives pretty good results with a minimal implementation effort. The technique is long known and widely used, but if you have no experience in image processing this step-by-step guide may be a fun and painless warm-up to the topic.

I’ll show the concept with the help of F# code, but the approach is so straightforward that you should understand it even without prior knowledge of the language.

TL;DR:

This is the high level outline of the process.

Just once, to build a database “index”:

  • Create a normalized 8-bit color distribution histogram of each image in the database.

For every query:

  • Create a normalized 8-bit color distribution histogram of the query image.
  • Search the database for the histogram closest to the query using some probability distribution distance function.

If you are still interested in the details of each step, please read on.

...

image..."

I've not thought about how I'd every do something like this so found this article a thought provoking read.

No comments: