Group Abstract Group Abstract

Message Boards Message Boards

Compare ImageKeypoints of two Images?

Posted 9 years ago

I am trying to compare two same images (with little modification in angle/brightness/ImageData) based on Feature Detection(ImageKeypoints).

I have computed ImageKeypoints for imageA (get a small piece of the image for each interesting point) as:

one = MapThread[ImageTrim[imageA, {#1}, 2.5 #2] &, 
 Transpose@
 ImageKeypoints[imageA, {"Position", "Scale"}, 
 "KeypointStrength" -> .001]]

imageA

and similarly for imageB:

two = MapThread[ImageTrim[imageB, {#1}, 2.5 #2] &, 
 Transpose@
 ImageKeypoints[imageB, {"Position", "Scale"}, 
 "KeypointStrength" -> .001]]

imageB

Now I compare these KeyPoints, to do so I have applied perceptual hash algorithm:

generateHash[img_, 
   method_: "Average"] /; (method == "Average" || method == "pHash") :=
   Module[{resized, grayscale, mean, imgdata, binarized}, 
   If[method == "pHash", resized = ImageResize[img, {32, 32}], 
   resized = ImageResize[img, {8, 8}]];
   grayscale = ColorConvert[resized, "Grayscale"];
   imgdata = ImageData[grayscale, "Byte"];
   If[method == "pHash", imgdata = FourierDCT[imgdata];
   mean = Mean@Rest@Flatten@imgdata[[;; 8, ;; 8]], 
   mean = ImageMeasurements[grayscale, "Mean"]];
   binarized = UnitStep[imgdata - mean];
   IntegerString[FromDigits[Flatten@binarized, 2], 16]]

compare[img1_, img2_, 
  method_: "Average"] /; (method == "Average" || method == "pHash") :=
  Module[{hash1, hash2}, hash1 = generateHash[img1, method];
  hash2 = generateHash[img2, method];
  If[StringLength@hash1 == StringLength@hash2, 
  HammingDistance[hash1, hash2], Infinity]]

similarCount=0
 For[i = 1, i <= Length[one], i++, 
  For[j = 1, j <= Length[two], j++,
   If[compare[one[[i]], two[[j]], "pHash"] < 11, similarCount++, 
    continue]]]

Here the compare method return the Hamming distance. If the distance is less up-to 10, I conclude they are same else different.

Now the problem is all the small piece of the images for each interesting point returns Hamming distance above 10 and hence I get the result that Images are Not Same.

I am new to Image Processing and guess I am doing something wrong, can you please help me figure it out or suggest some other alternative for the same!

Thanks.

POSTED BY: Kinley Christian
POSTED BY: Matthias Odisio
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard