在三维图像上覆盖具有透明度的遮罩

2024-05-15 11:01:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在一个特定的对象上覆盖颜色以进行语义分割。覆盖层应足够透明,以便能够查看覆盖层后面的对象。图像形状为(x,y,3),即没有alpha通道。由于模型的原因,我不想在源图像中添加额外的alpha层。
目前,我的做法如下:

>> image.shape
(720, 1280, 3)
>> m.shape # my original mask with boolean values
(720, 1280) 
>> mask = np.stack((m,m,m), axis=2)
>> mask.shape
(720, 1280, 3)
>> image = np.where(mask, (255,0,0), image) # Red overlay (255,0,0)

但图像中的物体是完全不透明的。有没有办法,用一些透明度覆盖颜色,最终保持原始三维图像不变


Tags: 对象模型图像imagealpha颜色mynp
1条回答
网友
1楼 · 发布于 2024-05-15 11:01:40
# First create the image with alpha channel
rgba = cv2.cvtColor(rgb_data, cv2.COLOR_RGB2RGBA)

# Then assign the mask to the last channel of the image
rgba[:, :, 3] = alpha_data

相关问题 更多 >