【问题标题】:How to get hash value from image using ImageMagick or GraphicsMagick Node.js?如何使用 ImageMagick 或 GraphicsMagick Node.js 从图像中获取哈希值?
【发布时间】:2019-07-01 20:25:00
【问题描述】:

翻阅这两个节点包的文档:

https://github.com/aheckmann/gm

https://github.com/rsms/node-imagemagick

试图弄清楚是否可以使用它来生成图像的感知散列。

我已经在我的项目中使用了这些包,所以如果能找到散列功能而不是像 Jimp 这样添加额外的包会很好。

非常感谢任何形式的帮助!

编辑 1:

所以在查看了你们的所有链接和建议后,我尝试关注

    gm()
    .command("convert")
    .in("testImage.jpeg")
    .in("-verbose")
    .in("-moments")
    .write( "testOutput.json", function (err) {
        if (!err) {
            console.log("DONE :)");
        }
        else {
            console.log("ERROR :(");
            console.log(err);
        }
    });

它给了我这么大的输出,但我感兴趣的部分在这里:

"channelPerceptualHash": {
      "colorspaces": [ "sRGB", "HCLp"],
      "Channel0": {
        "PH1": [0.514487, 11],
        "PH2": [3.46339, 11],
        "PH3": [4.96178, 11],
        "PH4": [5.09255, 11],
        "PH5": [10.2783, 11],
        "PH6": [7.0728, 11],
        "PH7": [10.2625, 11]
      },
      "Channel1": {
        "PH1": [0.514487, 11],
        "PH2": [3.46339, 11],
        "PH3": [4.96178, 11],
        "PH4": [5.09255, 11],
        "PH5": [10.2783, 11],
        "PH6": [7.0728, 11],
        "PH7": [10.2625, 11]
      },
      "Channel2": {
        "PH1": [0.514487, 0.514487],
        "PH2": [3.46339, 3.46339],
        "PH3": [4.96178, 4.96178],
        "PH4": [5.09255, 5.09255],
        "PH5": [10.2783, 10.2783],
        "PH6": [7.0728, 7.0728],
        "PH7": [10.2625, 10.2625]
      }
    },
    "renderingIntent": "Perceptual"

根据这个帖子http://www.imagemagick.org/discourse-server/viewtopic.php?t=30258

如果我没记错的话,我可以比较一下这些PH值,以确定图像是否相同。

【问题讨论】:

  • 如果 node-imagemagick 可以运行 bash shell 脚本,那么我有一个称为 phashes 的脚本,它可以执行多种类型的感知哈希。见fmwconcepts.com/imagemagick/index.php。与我的脚本 hamming 进行了比较。
  • @fmw42 我刚刚对我的问题进行了编辑,您能看一下吗?谢谢
  • EugeneGordin。你的链接对我不起作用。服务器出现问题。但请参阅fmwconcepts.com/misc_tests/perceptual_hash_test_results_510/…。使用compare -metric phash image1 image2 diffimage,或者如果您只想要比较值而不是差异图像,则使用compare -metric phash image1 image2 null:。但我很惊讶 gm convert 使用的是 ImageMagick 而不是 GraphicsMagick,它没有这种感知散列。但我从未使用过 gm convert,只从 ImageMagick 转换。
  • 谢谢!这非常有用!

标签: node.js npm imagemagick graphicsmagick


【解决方案1】:

感谢@fmw42 提供的建议改进了答案

AFAIK,您的 2 个链接中的第一个更相关,并且 3 年没有维护,所以我不抱希望。

在命令行中,它将是:

identify -verbose -moments image.png

所以我下载了这些包的源代码,然后像这样搜索momenthashperceptual

find . -type f -exec grep -Ei "moment|hash|perceptual" {} +

唯一的输出与感知哈希无关,只是一般图像哈希和感知渲染意图:

./test/selectFrame.js:  m.identify('%#', function (err, hash1) {
./test/selectFrame.js:    m.selectFrame(2).identify('%#', function (err, hash2) {
./test/selectFrame.js:      assert.ok(hash1.toString().trim() !== hash2.toString().trim())
./test/getterIdentify.js:        assert.equal(d['Rendering intent'], 'Perceptual');

我不抱希望,但如果有错误,我很高兴得到纠正。

【讨论】:

  • -features 1 和 -unique 不需要获得相位,只需 -moments。 identify -verbose -moments image.png
  • @fmw42 感谢您的更正,弗雷德。我已经把它变成了一个改进的答案。
  • 在 ImageMagick 中,感知散列在 identify.c 和 statistics.c 中。我通过搜索 G e t I m a g e C h a n n e l P e r c e p t u a l H a s h 的时刻找到了它
猜你喜欢
  • 1970-01-01
  • 2019-01-11
  • 2015-06-16
  • 1970-01-01
  • 2021-11-19
  • 1970-01-01
  • 2013-01-09
  • 2010-12-19
  • 1970-01-01
相关资源
最近更新 更多