# Condense a discrete function (histogram) in a single value

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:

15.12.22.9
^  ^
>--|--------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.12.22.9
^
> 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

-
> 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