有没有一种方法可以使用imagemagick或其他图形库来基于另一个图像中的像素进行过滤和图像化

时间:2018-10-24 05:41:52

标签: image image-processing imagemagick

因此,我编写了一个程序来执行此操作,但是它要花很长时间才能执行。我注意到许多图形库似乎比我编写的代码执行速度更快。基本上我想做的是使用第二个图像过滤掉第一个图像中的像素。如果不匹配,请用黑色替换。我只希望能够看到图像中的墙。

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

在ImageMagick中,您可以在将颜色限制为255后从image2中提取唯一的(srgb)颜色。然后可以遍历每种颜色,并使其在第一张图像中用白色填充该颜色,并用黑色填充所有其他颜色。 。这将生成一个遮罩图像,可以将其与image1相乘以得到结果。根据需要调整模糊值。

colors=`convert image2.jpg -fuzz 10% +dither -colors 255 -unique-colors txt: | cut -d\  -f6`
list=""
for color in $colors; do
val="-fill white -opaque '$color'"
list="$list $val"
done
eval 'convert image1.png -fuzz 1% '$list' -fill black +opaque white mask.png'
convert image1.png mask.png -compose multiply -composite result.png


enter image description here

相关问题