Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. 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

Basically I need to store (in a database) and subsequently fast compare histograms of two images.

Let's say I have an image and the green histograms is:

Where basically I have 4 buckects, and green pixel from 0 to 63 are 15 and so on.

How could I condense this graph in a numeric value so I can easly compare it to a new image?

The most simple solution is to create a string like this:
^  ^
>--|--------number of pixel from 0-64
   >--------number of pixel from 64-127
   (and so on)

The problem with this solution is that i can't easly compare 2 images with similar value. Let's say I have another images with the green histogram is:
> 14 pixel instead of 15

This new image is basically the same with just 1 pixel less of 0-63 range. But I can't easly compare this 2 strings

share|cite|improve this question
> How could I condense this graph in a numeric value so I can easly compare it to a new image? Just store the tuple of 4 numbers. What's wrong with that? the 4 numbers occupy less space than a string, and are easier to compare. – leonbloy Jun 1 '12 at 21:04
@leonbloy: that would lock the database table to a given number of buckets, i would avoid that – dynamic Jun 1 '12 at 21:24
And, consider for example we choose 50 buckets for each channel (RGB), that would mean a table with 150 field on the table. Not good – dynamic Jun 1 '12 at 21:27

Some options:

  1. Store the full information, eg as a array of numbers (if your DB supports some ARRAY datatype), or as a hexadecimal string, or a JSON string, or whatever representation that suits you (but not "a numeric value", that does not make much sense)
  2. Depending on what you consider to be a good measure of similarity, you could store, say, three numbers per channel (what would correspond to a decimated 3-buckets histogram)

The advantage of 1 is that you retain the full information and coul do a good comparison. The disadvantage is that it might be difficult to do compute the difference, specially inside the database, specially for varying number of buckets.

share|cite|improve this answer

Your Answer


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.