简体   繁体   English

从图像制作蒙版

[英]Make a mask from an image

I have two png images of complex figures of the same resolution.我有两个相同分辨率的复杂图形的 png 图像。 The second image is always the same.第二张图片总是一样的。 I want to designate a position of the black dotes on the second image and to reverse color of dotes in the area on the first image.我想在第二张图像上指定黑色点的 position,并在第一张图像上的区域中反转点的颜色。 How can I get the desired area and work with it on the first image?如何获得所需的区域并在第一张图像上使用它? I myself can only think of iterating through dots of the second image and, if condition is met, apply reversal to the dot of the same index on the first image.我自己只能考虑遍历第二张图像的点,如果满足条件,则将反转应用于第一张图像上相同索引的点。 But that is obviously inefficient.但这显然是低效的。 `` The first image The second image The desired result ``第一张图第二张图想要的结果

this is solution using ImageMagick.这是使用 ImageMagick 的解决方案。 first, -negate the background(first image) and multiply logo(second image).首先,-否定背景(第一张图片)并乘以徽标(第二张图片)。 at last negate again.最后再次否定。 then you could get res.png .那么你可以得到res.png

magick TH4C5.png -negate Y3MDy.png -compose multiply  -composite -negate tmp2.png

result结果

This works for me in ImageMagick.这在 ImageMagick 中对我有用。

convert triangle.png \( rectangle.png -negate \) -compose multiply -composite -negate result.png

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM