计算感知哈希的距离 [英] Computing distance of perceptual hashes

查看:254
本文介绍了计算感知哈希的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Imagemagick来获取图像的感知哈希.我使用以下命令:

I am using Imagemagick in order to get the perceptual hash of an image. I use the following command:

identify -verbose -define identify:moments x.png

除其他参数外,输出还返回感知哈希:

The output returns amongst other params also the pereceptual hash:

I1: 0.0017694 (0.451197) I2: 3.22345e-07 (0.0209605) I3: 2.88038e-10 (0.00477606) I4: 3.93968e-12 (6.53253e-05) I5: 1.2326e-22 (3.38892e-08) I6: -1.94034e-15 (-8.20426e-06) I7: -4.91938e-23 (-1.35254e-08) I8: 5.56374e-16 (2.35249e-06) Channel perceptual hash: Red, Hue: PH1: 0.407586, 0.690687 PH2: 1.88394, 2.91999 PH3: 2.36028, 3.96979 PH4: 5.36184, 5.3591 PH5: 9.25849, 11 PH6: 6.30422, 6.93025 PH7: 9.6332, 10.0241 Green, Chroma: PH1: 0.293148, -0.0406998 PH2: 1.49146, 2.52843 PH3: 2.21568, 0.992456 PH4: 3.52683, 2.3777 PH5: 6.48291, 4.06334 PH6: 4.38149, 4.23342 PH7: 6.64322, 5.35487 Blue, Luma: PH1: 0.329865, 0.33357 PH2: 1.6461, 1.63528 PH3: 2.39206, 2.26483 PH4: 3.72747, 4.09284 PH5: 6.789, 7.36151 PH6: 4.56493, 5.0171 PH7: 7.83416, 7.50669 

我想保存哈希值,然后计算2张图像之间的距离.如何将上面的输出转换为哈希并计算2个哈希之间的距离?

I want to save the hash and then compute the distance between 2 images. How can I convert the above output to a hash and calculate the distance between 2 hashes?

推荐答案

请参见>: //www.fmwconcepts.com/misc_tests/perceptual_hash_test_results_510/index.html 了解有关此感知哈希的详细信息和测试.

See http://www.fmwconcepts.com/misc_tests/perceptual_hash_test_results_510/index.html for detailed information and tests of this perceptual hash.

基本上,它会使用Sum Squared度量创建42个浮点值,需要将其与另一幅图像中的另一组42个浮点值进行比较.

Basically it creates 42 floating point values that need to be compared with another set of 42 floating point values from another image using Sum Squared metric.

这不是一个简单的二进制哈希,可以轻松地存储为1s和0x的字符串并使用汉明距离进行比较.

This is not a simple binary hash that can be easily stored as a string of 1s and 0x and compared using the Hamming distance.

但是您可以使用

compare -metric phash image1 image2 null:

如果需要,可以将phash值输出到.json文件.

You can output the phash values to a .json file if you want.

或者,我有两个bash Unix ImageMagick shell脚本(phashconvert和phashcompare).可以将42个浮点数转换为一串数字,可以将其保存在注释部分的文件中.第二个将读取两个文件的注释部分以提取字符串,将其转换回浮点数,然后使用求和平方指标求值.但是请注意,由于从浮点数到数字的来回转换,此过程只是一个近似值.

Alternately, I have two bash unix ImageMagick shell scripts (phashconvert and phashcompare). One will convert the 42 floats to a string of digits that can be saved in the file in the comment section. The second will read two file's comment sections to extract the string, convert them back to floats and then use the Sum Squared Metric to evaluate them. But note this process is only an approximation due to the conversion back and forth from floats to digits.

如果您只想提取42个浮点数,则应该这样做(从我的脚本phashconvert中提取)

If you just want to extract the 42 floats, this should do it (from my script phashconvert)

identify -quiet -verbose -moments -alpha off "x.png" | grep "PH[1-7]" | sed -n 's/.*: \(.*\)$/\1/p' | sed 's/ *//g' | tr "," "\n"

这篇关于计算感知哈希的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆