0

I'm working on an image comparsion algorithm and need a bit help. I do not want find identical images, but images with similar colors and color-temperatures. My first try was to use hash-values, second try was to use histograms. But both methods didn't produce satisfactory results.

Now I simply want to count colors in the images:

  1. I bring the images to same size (let's say 100x100px).
  2. I reduce the colors to 8 or only 4 bits per pixel.

Afterwards I calculate a dictionary with color-values per image:

// sample output:
// Dictionary<Color, int> imageColors;
// imageColors[(0, 32, 128)] = 67   // 67 pixels have this color
// imageColors[(0, 64, 128)] = 198  // ...
// imageColors[(96, 0, 160)] = 74   // ...
// and so on...

That work's well and fast. I'm using LockBits und unsafe pointer. For better understanding here the simple method to reduce colors:

static byte ReduceColorValue(byte colorChannelValue, byte factor = 32)
{
    return (byte)(colorChannelValue / factor * factor);
}

I hope that's understandable.

And now the question: How can I compare those dictionaries with color-values/count? I have to calculate a comparable value that says how equal 2 pictures are.

  • 1
    Hashes on pixels is not a great way to compare colors/temperatures. I think you should use something like averages to scale down the data. Dividing the images in squares to average. – Jeroen van Langen Oct 19 '21 at 22:46
  • 1
    Minor point: 8 colors is 3 bits/pixel, not 4. – 500 - Internal Server Error Oct 19 '21 at 23:20
  • 1
    conceptually: represent each picture as a vector of features. calculate the distance between those vectors. "distance" can be euclidean, manhattan, ... -- you should do some research. this isn't a new problem and you aren't the first to work on it. browse for "content based image retrieval" and also "perceptual hashing" – Christoph Rackwitz Oct 19 '21 at 23:21
  • Thanks for all your comments and inputs. I'll try some more approaches. Server Error: yes, you're right of cource ;-) Christoph: I haven't heard about those terms. Thx for the suggestion. Very useful – Peter Perni Oct 20 '21 at 21:00

0 Answers0