【问题标题】:how to search an image for subimages on linux如何在Linux上搜索图像的子图像
【发布时间】:2022-01-19 02:29:49
【问题描述】:

我已经看到 Mark Setchell (https://stackoverflow.com/users/2836621/mark-setchell) 的答案,它似乎已经过时并且不再起作用了。 How to search an image for subimages using linux console?

https://stackoverflow.com/a/31874879/17686212 How to search an image for subimages using linux console?

下载针头并创建干草堆图像并将针头“隐藏”在其中工作正常。 Needle Image

convert -size 256x256 gradient:lime-blue haystack.png
convert haystack.png needle.png -geometry +30+5 -composite haystack.png 
convert haystack.png needle.png -geometry +100+150 -composite haystack.png 

运行指定的比较图像命令会导致错误:

compare -metric RMSE -subimage-search haystack.png needle.png locations.png
compare: images too dissimilar `haystack.png' @ error/compare.c/CompareImagesCommand/1166.

我尝试应用 -similarity-threshold 和 -dissimilarity-threshold 并更改/降低了转换位置阈值,但没有成功,也就是这样的糟糕结果:

compare -similarity-threshold 0 -dissimilarity-threshold 1 -metric RMSE -subimage-search haystack.png needle.png locations.png
convert locations-1.png -threshold 95% txt: | grep white

locations-0.png locations-1.png

我在 gentoo 上使用了 imagemagick 版本 7.1.0.14,在 kali Linux 上使用了 6.9.11.60+dfsg-1.3

希望你能帮我解决这个问题。

【问题讨论】:

  • 如果使用 IM 7,则使用 magick compare 而不是 compare
  • 使用 IM 7,您可以进行蒙版比较,如果您为针状图像创建蒙版,这样大量的白色不会与大海捞针图像的绿色和蓝色不匹配。见legacy.imagemagick.org/discourse-server/…

标签: imagemagick


【解决方案1】:

这是如何在 ImageMagick 7 中进行蒙版合成。

模板:

图片:

创建蒙版:

magick needle.png -transparent white -alpha extract mask.png

magick compare -metric rmse -subimage-search -dissimilarity-threshold 1 haystack.png \( -read-mask mask.png needle.png \) compare.png

9031.97 (0.137819) @ 100,150

比较-0(差异):

Compare-1(匹配分数):

如果你想找到最好的匹配,你需要使用我的脚本,maxima

maxima -t 80 -n 10 compare-1.png

max=1 100,150 gray=56540,220,86.2745%
max=2 30,5 gray=54484,212,83.137%

你不会从 ImageMagick 6 中得到一个好的结果

compare -metric rmse -subimage-search -dissimilarity-threshold 1 haystack.png needle.png compare.png

26789 (0.408773) @ 96,114

因为你的针图像中有太多的白色,它会与大海捞针图像中的绿色和蓝色不匹配。不幸的是,您不能在 ImageMagick 6 中进行蒙版比较。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-26
    • 2012-12-02
    • 1970-01-01
    相关资源
    最近更新 更多