【问题标题】:Apply colored overlay over a colored rgb image with some transparency in Skimage在 Skimage 中具有一定透明度的彩色 rgb 图像上应用彩色叠加
【发布时间】:2017-08-01 17:33:43
【问题描述】:

所以基本上我有一个彩色 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()

请使用以上代码回答。

【问题讨论】:

  • 先选择要添加叠加层的区域。然后将颜色添加到该区域
  • @JeruLuke 的问题是颜色不透明。我也需要看看背景。所以叠加层应该有一个合适的alpha通道。
  • 我在 OpenCV 中有确切的解决方案。你想看吗??
  • @JeruLuke,是的,当然!!!!!!
  • 看看答案

标签: python numpy image-processing scikit-image


【解决方案1】:

这是 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(叠加层不再透明而是不透明)

【讨论】:

  • 这正是我想要的。谢谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-05
  • 1970-01-01
  • 1970-01-01
  • 2015-07-09
  • 2019-02-05
  • 2015-09-26
相关资源
最近更新 更多