gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 06:56:09 24 4
gpt4 key购买 nike

我想在特定对象上叠加颜色以进行语义分割。覆盖层应该足够透明,以便能够查看覆盖层后面的对象。图像形状为 (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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com