python - 在 3 维图像上覆盖具有透明度的蒙版

标签 python

我想在特定对象上叠加颜色以进行语义分割。覆盖层应该足够透明,以便能够查看覆盖层后面的对象。图像形状为 (x,y,3),即没有 alpha channel 。由于模型的原因,我不想在源图像中添加额外的 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)

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

最佳答案

# 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

关于python - 在 3 维图像上覆盖具有透明度的蒙版,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58798248/

相关文章:

python - 哪些领域涉及提取具有相似特征的单词?

python - Matplotlib plt.show() 方法不弹出窗口

python - 如何在记录列表和数组时插入换行符?

python - 在赋值错误之前引用事件变量,我不知道如何修复它

python - sklearn 上的逻辑回归函数

python - 比 "try"和 "except"更快的方法? - Python

python - 如何在Python中使用PyQt5绘制折线?

python - 如何对 Django View 进行单元测试?

python - 使用 python 处理动态电子邮件地址

python - vim 的 python 插件,如 vim-r-plugin