-1

So Im looking at an image and trying to select one from a set of other images that is the most similar (least different).

Currently I simply look at the average difference between the RGB parts of each pixel, but this has a tendency of picking grey colors. If half the picture is white and the other is black, it's going select some grey shade even though there is no grey in the picture.

I'm assuming there are better algorithms to compare images or trying to achieve what I'm trying to do.

Note that the actual content of the image is not that interesting, just that the colors "look" similar.

For the record what Im trying to do is match someones clothing to a texture-file, if that makes any difference.

Any suggestions or points in the directions of some resources would be greatly appreciated.

EDIT: My solution was to remove the grey colors from the set I was selecting from and it worked pretty well, if anyone else have any better solutions feel free to post.

taracus
  • 393
  • 1
  • 5
  • 19
  • https://stackoverflow.com/questions/23931/algorithm-to-compare-two-images – Emanuele Feb 25 '20 at 14:14
  • Also: https://stackoverflow.com/questions/35151067/algorithm-to-compare-two-images-in-c-sharp –  Feb 25 '20 at 14:15
  • Note I know the images are not identical because one is coming through a live camera-feed and the other is a texture-file on disk. What I need is to calculate "how" different they are, where "how" is how "visually similar" they are I guess. – taracus Feb 25 '20 at 14:45
  • Also I dont have any test-data or "correct" data to train an AI-model on so this needs to be done by the pixel-data without any NN/ML/AI – taracus Feb 25 '20 at 14:54

1 Answers1

1

I just posted this yesterday, I don't want to duplicate the post, but it is very similar.

Making smaller Bitmaps from a Bitmap object

My open source project Transparency Maker creates a Pixel Database, which is actually a list of PixelInformation objects.

Each pixel has properties for Red Green Blue of course, but there are also properties for Total, BlueGreen, BlueRed, and GreenRed, which is just the sum of Blue + Green, Blue + Red, etc.

You can then do Linq queries or for each loops and compare the total for two Pixels (Pixel Information class), and then you can compare on different things like:

Comparing the totals is as easy as:

int difference = pixel1.Total - pixel2.Total;

Which is the same as typing all this if you are using a standard BitMap:

int redDiff = Pixel1.Red - Pixel2.Red;
int green = Pixel1.Green - Pixel2.Green;
int blueDiff = Pixel1.Blue - Pixel2.Blue;
int diff = redDiff + greenDiff + blue;

As a thought, you could refine your algorithm to where each difference gets weighted more, so for the above the last line could be:

int difference = (redDiff * 17) + (greenDiff * 17) + (blueDifference * 17);

I just made up 17 as an example, what value for weight you use it is up to you.

In theory, the above would give you a closer number to closer images.

Here is the link to my open source project if you want the full code: https://github.com/DataJuggler/TransparencyMaker

Maybe this will give you some ideas.

  • I mean this is the algorithm Im using right now (not with your library though), but I was hoping there is a better way as I stated in my question, this algorithm tends to pick some nuance of grey when parts of the pictures are bright and others are not – taracus Feb 25 '20 at 14:46
  • I was thinking more about this while on my 7 mile run just now. How advanced do you want to go? You could could compare the amount of Red in the Top Left Portion, and give that a score, do the same for as many attributes as you can think of. Average is not a good comparison, that is why you are getting gray. Take the difference in Red and times by itself x number of times, do the same for Red, Green and Alpha and you could probably get pretty far. ML.Net has some image comparisons made for this stuff that are better than you or I could write most likely. –  Feb 25 '20 at 17:19