【问题标题】:Computing distance of perceptual hashes计算感知哈希的距离
【发布时间】:2018-03-10 17:22:15
【问题描述】:

我正在使用 Imagemagick 来获取图像的感知散列。我使用以下命令:

identify -verbose -define identify:moments x.png

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

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 个哈希之间的距离?

【问题讨论】:

    标签: imagemagick


    【解决方案1】:

    有关此感知散列的详细信息和测试,请参阅http://www.fmwconcepts.com/misc_tests/perceptual_hash_test_results_510/index.html

    基本上,它创建了 42 个浮点值,需要使用 Sum Squared 度量与来自另一个图像的另一组 42 个浮点值进行比较。

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

    但是你可以在 ImageMagick 中使用

    从它们的感知散列中比较两个图像
    compare -metric phash image1 image2 null:
    

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

    另外,我有两个 bash unix ImageMagick shell 脚本(phashconvert 和 phashcompare)。将 42 个浮点数转换为一串数字,可以保存在注释部分的文件中。第二个将读取两个文件的注释部分以提取字符串,将它们转换回浮点数,然后使用 Sum Squared Metric 来评估它们。但请注意,由于从浮点数到数字的来回转换,这个过程只是一个近似值。

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

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-23
    • 2019-03-08
    • 2019-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多