在彩色rgb图像上应用彩色叠加,在Skimage

时间:2017-03-11 10:42:24

标签: python numpy image-processing scikit-image

所以基本上我有一个彩色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 差异是色彩空间。以上问题适用于灰度图像而非彩色(RGB)。

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

请使用上面的代码回答。

1 个答案:

答案 0 :(得分:2)

以下是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

enter image description here

当alpha = 0.5

时,

enter image description here

当alpha = 0.8

enter image description here

当alpha = 1.0 时,

(叠加层不再透明但不透明)

enter image description here