Page 1 of 1

Save down pHash string (or info) with Magick.NET

Posted: 2017-06-07T03:29:24-07:00
by pjmaybe
Hello!

Loving ImageMagick and Magick.NET

I want to compare a whole lot of images to see which ones are similar, using pHash. Naturally, the best way to do this is to calculate the pHash data once for each image - then use that data to do the comparison many times (for each combination of two images).

Magick.NET provides the "var res = firstImage.Compare(secondImage, ErrorMetric.PerceptualHash);" type interface.... but this isn't much good for me, as it is very slow to calculate the "firstImage" pHash for each comparison I want to do.

Something like this was talked about with relation to ImageMagick via scripting (see link here) - but not Magick.NET. I am wondering if there is a way to save down that pHash data in Magick.NET.

THANKS FOR THE HELP!

Re: Save down pHash string (or info) with Magick.NET

Posted: 2017-06-07T10:06:10-07:00
by fmw42
If you use the equivalent of

identify -verbose -phash image.gif

you can get the 42 hash moments

Code: Select all

 Channel perceptual hash:
    Red, Hue:
      PH1: 0.474336, 11
      PH2: 1.07177, 11
      PH3: 11, 11
      PH4: 11, 11
      PH5: 11, 11
      PH6: 11, 11
      PH7: 11, 11
    Green, Chroma:
      PH1: 0.296259, 0.00810099
      PH2: 0.740509, 0.0674632
      PH3: 3.74048, 2.07303
      PH4: 3.78247, 2.34916
      PH5: 7.71439, 4.56337
      PH6: 4.21556, 2.3971
      PH7: 7.6762, 5.48365
    Blue, Luma:
      PH1: 0.296259, 0.357227
      PH2: 0.740509, 0.85367
      PH3: 3.74048, 4.33613
      PH4: 3.78247, 4.39974
      PH5: 7.71439, 8.9046
      PH6: 4.21556, 4.88376
      PH7: 7.6762, 8.93268
You can then store them. Then for any two images, you can do Sum Squared Difference to compute the phase value.