英文:
Clipping image to transparent mask
问题
我有这些带有透明度掩码的图像,我想将掩码的 alpha 通道应用到原始图像上。例如:
图像 - https://i.imgur.com/8Nb4VJ8.png
掩码 - https://i.imgur.com/anflRUr.png
我已经查阅了文档和大量的帖子,但没有一个方法适用于我。大多数人似乎有黑白掩码图像,并且他们想要使用亮度作为掩码,但在我的情况下,我只想简单地复制掩码的 alpha 通道。我想我可能遗漏了一些简单的选项,但我一直无法弄清楚。我将感激您的帮助。
谢谢。
英文:
I have these images with associated masks that have transparency, and I want to apply the alpha of the mask onto the original image. For instance:
Image - https://i.imgur.com/8Nb4VJ8.png
Mask - https://i.imgur.com/anflRUr.png
I've gone through the documentation and loads of threads but nothing has worked for me. Most people seem to have black and white mask images and they want to use the brightness as the mask, but in my case I want to simply copy the alpha channel of the mask. I imagine I'm missing some simple option, but I haven't been able to figure it out. I would appreciate some assistance.
Thank you.
答案1
得分: 1
如果您想将遮罩应用于图像的 alpha 通道,那么以下操作可以实现您的需求。您需要提取遮罩的 alpha 通道,并将其应用于图像,操作如下:
图像:
遮罩:
在 Unix 下,使用 Imagemagick 6 的语法:
convert image.png \( mask.png -alpha extract \) -alpha off -compose copy_opacity -composite image_masked.png
如果使用 Windows,去掉括号中的反斜杠。如果使用 Imagemagick 7,将 "convert" 改为 "magick"。
英文:
I am not positive I understand what you want. But if you want to apply the mask to the alpha channel of the image, then this should do what you want. You need to extract the alpha channel of the mask and apply that to the image as follows:
Image:
Mask:
Unix Syntax for Imagemagick 6:
convert image.png \( mask.png -alpha extract \) -alpha off -compose copy_opacity -composite image_masked.png
If using Windows, remove the \ from the parentheses. If using Imagemagick 7, change convert to magick
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论