将图像裁剪到透明蒙版

huangapple go评论57阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年6月9日 09:13:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76436594.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定