简体   繁体   English

如何在Python中使用第二个图像作为透明二进制蒙版合并两个图像?

[英]How to merge two images using second as a transparent binary mask in Python?

For example I have a image of a cat, and second image with a mask of cat. 例如,我有只猫的图像,第二张有猫面具的图像。 And I want to add transparent red mask for pixels of a cat in first image. 我想在第一张图像中为猫的像素添加透明的红色蒙版。 Both images are numpy arrays...So how to do it? 这两个图像都是numpy数组...那么怎么做呢?

IIUC you could do something like this - IIUC您可以做这样的事情-

img[:,:,2] = np.where(mask,255,img[:,:,2])

Results - 结果-

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

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

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