0

I'm using Shipwreck.Phash for image comparison. I just recognized that two identical white images return a cross correlation of 0, although it should return 1.

hash1: 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000

hash2: 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000

CrossCorrelation: 0

My code:

static void Main(string[] args)
    {


        var firstImage = new Bitmap(@"Bilder\\hash1.JPG");
        var secondImage = new Bitmap(@"Bilder\\hash1.JPG");


        var hash = ImagePhash.ComputeDigest(firstImage.ToLuminanceImage());
        var hash2 = ImagePhash.ComputeDigest(secondImage.ToLuminanceImage());

        var score = ImagePhash.GetCrossCorrelation(hash, hash2);

        Console.WriteLine(hash);
        Console.WriteLine(hash2);

        Console.WriteLine(score);


    }

Can someone please explain me my result? Thanks in advance.

Given image: whiteImage

AndiH
  • 31
  • 1
  • 7
  • **two identical white images** so.. what is the difference of the two image? by the description on phash.org, it says `".. 'attacks' on a given input and yet be flexible enough to distinguish between dissimilar files. Such attacks can include rotation, skew, contrast adjustment and different compression/formats.."` i guess the contrast isnt that different so it considered as similar by the hash. and they do say `"Unlike cryptographic hash functions which rely on the avalanche effect of small changes in input leading to drastic changes in the output"` at the beginning of the page. – Bagus Tesa Jul 14 '20 at 14:11
  • tl;dr, double check what the algorithm do before implementing it on the code.. – Bagus Tesa Jul 14 '20 at 14:12
  • Ok let me clearify. I split both images into some subimages. After that I want to compare those image pairs for getting the location of the differences in the original pictures. (I know there are other ways to do it but I also wanted to try it this way). Both pictures have white parts. As you see both images return the same hash. But for calculate the crosscorrelation I expect 1 as result, since both are the same but I get 0 as result. – AndiH Jul 15 '20 at 06:40
  • now, i am also confused. with the hash string you provided it should return 1. [see fiddle](https://dotnetfiddle.net/nW9Flb). maybe you have something in between? in your code. – Bagus Tesa Jul 15 '20 at 13:10
  • unfortunatelly there is nothing in between. I edited my question, added the image and integrate my whole code. I'm really confused. Do you think that is a bug in Shipwreck.Phash? It seems like that the problem is only given with the provided hash and picture. My only idea is to check whether the hash is similar to the provided hash and then I return 1 manually.. – AndiH Jul 17 '20 at 11:52

1 Answers1

0

I asked the Shipwreck Developers directly and that is their answer:

As the cross-correlation calculation is based on a kind of division, it doesn't support zero vectors. So the pHash doesn't support single-color-image.

Implementing the fiddle from @Bagus Tesa it is working, although it's a copy from Shipwreck.Phash. Therefore I changed the CrossCorrelation method from the NuGet to his.

AndiH
  • 31
  • 1
  • 7