8

Is there possible to compare two images with different resolutions?

I mean here some algorithmic/programming approach. For instance, now I calculate hash code from image's byte array and compare these hash code values. That is work great but fail in case of different resolutions, i.e. images are identical by eye but different in it byte content.

For example see my image attaches:
enter image description hereenter image description here

one of it has 72 ppi but another 96 ppi. I would like to have TRUE value while comparing on equality but now I get FALSE. Help please to find correct solution here.

Michael Z
  • 3,229
  • 6
  • 35
  • 54

2 Answers2

5

Two very simple perceptual hashing methods you might give a try before venturing into more complicated territory are based on the Discrete Cosine Transform and the local vs glocal mean of an image:

  1. Convert image to grayscale

    1.1 (EDIT) Make your image zero mean

  2. Crush your image down to thumbnail size, say [32x32]
  3. Run the two dimensional Discrete Cosine Transform
  4. Keep the top left [8 x 8], most significant low frequency components
  5. Binarize the block, based on the sign of the components
  6. Result is a 64 bit hash

And a variant on this theme would be

  1. Convert image to grayscale
  2. Optionally re-size to a predefined size.
  3. Partition the image in a fixed number of blocks
  4. Determine the global mean
  5. Determine the local mean per block
  6. For the hash, write out a 1 or a 0 per block, pending if the local mean was larger or smaller than the global mean.

Also, have a look at phash.

Maurits
  • 2,014
  • 3
  • 27
  • 31
  • What is official method name for your first approach? Is there any free implementations in some programming language? – Michael Z Apr 17 '12 at 11:20
  • @Michael Z, I only know them as "perceptual hashing" sorry. phash is opensource, but there are restrictions for commercial usage. Best to talk to them. Good luck. – Maurits Apr 17 '12 at 19:37
  • 1
    Well thanks. But I had some problems with your algo (I have used the first). The lack is in *5.Binarize the block, based on the sign of the components* you have not clarified this process. I have performed binarization based on below/above of zero (0) value, but the correct solution is considering mean value of colors but not zero. This article much helps me: https://www.memonic.com/user/aengus/folder/coding/id/1qVeq – Michael Z May 05 '12 at 10:41
  • @Michael Z You are right! I forgot to mention that I make images zero mean. – Maurits May 05 '12 at 12:54
  • @Maurits,I am using the same logic for my Image comparison case. but it fails for the following image whose link I have added in the comment. And the difference is just of a size and nothing else. Link1 = http://www.snapdeal.com/product/park-avenue-green-polyester-regular/674651359945#bcrumbLabelId:745 Link2 = https://www.flipkart.com/park-avenue-formal-sleeveless-self-design-women-s-green-top/p/itmedshpbs2xkth5?pid=TOPEDSHPWZUE5SXW&srno=b_1_51&otracker=browse&lid=LSTTOPEDSHPWZUE5SXWH63N7L – Mr x Sep 07 '16 at 08:41
3

For synthetic images with a few distinct colours I would start with histogram matching.

Basically add up the number of pixels of each colour in each image and divide by the total number of pixels. Then you have a simple float vector as a fingerprint. You can ignore white if you want images with more or less border to count as a match

It's not going to detect the same image with the slices re-arranged, or the text moved down a line but i don't think that is the concern in this case

Martin Beckett
  • 90,457
  • 25
  • 178
  • 252