opencv将黑白转换为绿色和蓝色

时间:2011-08-30 09:12:41

标签: opencv

我有黑白图像,想要将其转换为绿色和蓝色图像。所以黑色变成绿色,白色变成蓝色。我怎样才能用openCV做到这一点?

2 个答案:

答案 0 :(得分:2)

您可以将黑白图像用作遮罩:

Mat blackWhite = ... //image of type CV_8U 

//new green Mat
Mat bgr(blackWhite.size(), CV_8UC3, Scalar(0,255,0));
//set pixels masked by blackWhite to blue
bgr.setTo(Scalar(255,0,0), blackWhite);

答案 1 :(得分:0)

如何使用cv2.applyColorMap

import cv2
import pylab as plt

path = "lena.jpg"

img = cv2.imread(path)[:,:,::-1]
img_g = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
_ = plt.imshow(img_g, cmap='gray')

image_cm = cv2.applyColorMap(img_g, cv2.COLORMAP_SUMMER)
_ = plt.imshow(image_cm)

图1.黑&白色图像(严格来说,这是灰度) enter image description here

图2.绿色&蓝色图像

enter image description here