在 Skimage 中以一定的透明度在彩色 rgb 图像上应用彩色叠加层

Apply colored overlay over a colored rgb image with some transparency in Skimage

所以基本上我有一个彩色 RGB 图像,我想在 RGB 图像上添加一个彩色叠加层而不将其转换为灰度级。 例如,如果我有彩色图像 (RGB)。我想像这样在索引上添加透明的蓝色

img[200:350, 200:350] = [0, 0, 1] # Blue block

这个问题是这个问题的同级问题: Applying a coloured overlay to an image in either PIL or Imagemagik 区别在于颜色space。上面的问题是针对灰度图像而不是彩色(RGB)的。

from skimage import io, data
import numpy as np
img = data.astronaut()

请用上面的代码回答。

这是 OpenCV 中的代码:

import cv2

# load the image
image = cv2.imread("2.jpg")

# I resized the images because they were to big
image = cv2.resize(image, (0,0), fx=0.75, fy=0.75)

overlay = image.copy()
output = image.copy()

#select the region that has to be overlaid
cv2.rectangle(overlay, (420, 205), (595, 385),(0, 255, 255), -1)

#Adding the transparency parameter
alpha = 1

#Performing image overlay
cv2.addWeighted(overlay, alpha, output, 1 - alpha,0, output)

#Save the overlaid image
cv2.imwrite('Output'+str(alpha) +'.jpg', output)

cv2.waitKey(0)
cv2.destroyAllWindows()

一些结果:

当 alpha = 0.1

当 alpha = 0.5

当 alpha = 0.8

当 alpha = 1.0(叠加层不再透明而是不透明)