3

Is there anyway to compare 2 similar images (not the same) in Delphi.

here are some examples:

enter image description here&enter image description here

Its obvious here that we cant compare pixel by pixel, So my idea was to sum the pixels values of each image, the compare them:

function CalcPix( img : TImage) : longint;
var
  s : longint;
  i, j : integer;
begin
  s := 0;

  for i := 0 to img.Height do
  begin
     for j := 0 to img.Width do
     begin
      if img.Canvas.Pixels[i,j] <> clWhite then
        s := s + img.Canvas.Pixels[i, j];
     end;
  end;

  Result := S;
end;

the results are:

1)14836072057

2)16750850318

as you see they are not that close, and if i do this process with 4 - 5 image at a time it always give me wrong results.

Is there anyother way? like changing the color or contrast etc.

Harriv
  • 6,029
  • 6
  • 44
  • 76
Ouerghi Yassine
  • 1,835
  • 7
  • 43
  • 72
  • 3
    I assume by "compare" you mean to apply some algorithm that will return a degree of correlation between two images? Such a correlation requires rules about what you consider similar and not similar. In your example you seem to mean similar in exclusion of a rotation or translation transform. What about a stretch or a skew, however, or a curvature distortion of some type? What are you trying to achieve and what form should the result take? Do you want a *yes/no* match, or a one-dimensional result indicating strength of correlation (ie: 94% probability of match, etc). – J... Aug 26 '13 at 23:28
  • yes, there will be only rotation and translation, and i my goal is to find out, whether the image is the same or not (after it has been rotated/translated) – Ouerghi Yassine Aug 27 '13 at 00:54
  • Are you looking for similarity or are you looking for identical except for translation/scaling/rotation? There's a whole specific field of research (Image Retrieval) which covers the topic of determining similarity in images. – lurker Aug 27 '13 at 01:06
  • no it shouldnt be very identical, it just need to find out if it is the same picture or not ... – Ouerghi Yassine Aug 27 '13 at 02:20
  • 1
    You could compare histograms. Histogram should stay pretty stable and if images are not too similar give good separation. – Harriv Aug 27 '13 at 06:21
  • 1
    @Yassine "if it is the same picture or not" Stop repeating yourself and answer exactly what 'identical' is, i.e the comparison criteria/algorithm. Without that you can't write code. Probably your pixel sum method isn't good enough. – Jan Doggen Aug 27 '13 at 06:22
  • Here's good write up about the options you have: http://stackoverflow.com/a/844113/7735 – Harriv Aug 27 '13 at 06:33
  • this one will help you: http://stackoverflow.com/questions/15250619/compare-screen-shots-and-get-screen-coordinates-of-first-pixel-change – jimsweb Aug 27 '13 at 20:45
  • @JanDoggen ok here is what i really wana do, http://bit.ly/146AIAb i have to tell which picture is duplicated there. I hope that was clear enough. – Ouerghi Yassine Aug 27 '13 at 20:46

1 Answers1

6

Here's good write up about the options you have: https://stackoverflow.com/a/844113/7735 This requires some background knowledge, and best performing solutions are hard to implement from ground up, so using some kind of library would be easiest. Here's OpenCV wrapper for Delphi: https://github.com/Laex/Delphi-OpenCV

Community
  • 1
  • 1
Harriv
  • 6,029
  • 6
  • 44
  • 76