Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing images with different resolutions

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.

like image 742
Michael Z Avatar asked Apr 14 '12 15:04

Michael Z


2 Answers

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.

like image 180
Maurits Avatar answered Oct 31 '22 07:10

Maurits


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

like image 23
Martin Beckett Avatar answered Oct 31 '22 09:10

Martin Beckett