Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I compare two images to detect duplicates and cropped duplicates?

How can I compare two images and determine if they are 100% similar, or only altered in color, or cropping?

like image 764
makerofthings7 Avatar asked Sep 16 '25 12:09

makerofthings7


1 Answers

Well, abstractly speaking, you need to define a similarity function, that compares two images. To determine if the images are "100% similar" (equal) you can do the following:

  • compare the sizes of the images
  • if the image sizes are the same simply subtract the pixels from each other
  • if ( sum( abs( pixel_1_i - pixel_2_j ) ) / num_pixels < threshold ) return true

For the case that images are differently colored, or cropped

  • apply an edge detector to both images
  • compute the cross-correlation (in the frequency domain, FFT)
  • find the highest peak
  • place the (smaller) edge map in the determined position
  • calculate the absolute error
  • if (error < threshold) return true

BTW: This approach will not work if your images are scaled or rotated.

Further Research:

  • cross-correlation: FFT (fast fourier transformation, link1, link2, FFT in C#), zero-padding (needed for the FFT if the input signals have different sizes)
  • edge detection: Sobel, Canny (these are very common image processing filters, they should be available in a C# library, just like the FFT)
like image 104
bjoernz Avatar answered Sep 19 '25 04:09

bjoernz