【发布时间】:2020-07-14 14:01:01
【问题描述】:
我正在使用 Shipwreck.Phash 进行图像比较。 我刚刚认识到两个相同的白色图像返回的互相关为 0,尽管它应该返回 1。
哈希1:0x00000000000000000000000000000000000000000000000000000000000000000000000000000000
哈希2:0x00000000000000000000000000000000000000000000000000000000000000000000000000000000
互相关:0
我的代码:
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);
}
有人可以解释一下我的结果吗?提前致谢。
给定图片:whiteImage
【问题讨论】:
-
两张相同的白色图片 那么..这两张图片有什么区别?根据 phash.org 上的描述,它说
".. '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.."我猜对比并没有那么不同,所以它被哈希认为是相似的。他们确实在页面开头说"Unlike cryptographic hash functions which rely on the avalanche effect of small changes in input leading to drastic changes in the output"。 -
tl;dr,在代码上实现之前仔细检查算法的作用..
-
好的,让我澄清一下。我将两个图像分成一些子图像。之后,我想比较这些图像对以获得原始图片中差异的位置。 (我知道还有其他方法可以做到,但我也想以这种方式尝试)。两张图片都有白色部分。如您所见,两个图像都返回相同的哈希值。但是为了计算互相关,我希望结果为 1,因为两者相同,但结果为 0。
-
现在,我也很困惑。使用您提供的哈希字符串,它应该返回 1.see fiddle。也许你有什么介于两者之间?在您的代码中。
-
不幸的是,两者之间没有任何关系。我编辑了我的问题,添加了图像并整合了我的整个代码。我真的很困惑。您认为这是 Shipwreck.Phash 中的错误吗?似乎只有提供的哈希和图片才能给出问题。我唯一的想法是检查哈希是否与提供的哈希相似,然后我手动返回 1..
标签: c# image-comparison phash