从灰度图片创建彩色图片 [英] Create colour picture from greyscale picture
本文介绍了从灰度图片创建彩色图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个值从0到1000的矩阵,我可以轻松地将值缩放到0〜255范围,如果我在Python的opencv中显示矩阵,那是一张灰度图片.
I have a matrix with values from 0 to 1000, I can easily scale the values to the 0~255 range, and that is a greyscale picture if I show the matrix in opencv from Python.
问题是,如何将矩阵{Dimensions =(m,n)}转换为三层矩阵数组{Dimensions =(m,n,3)}?
The question is, how do I convert the Matrix {Dimensions = (m, n)} to a 3-layer matrix array {Dimensions = (m, n, 3)}?
这是如何将灰度图片转换为彩色图片?
This is, how to convert a greyscale picture to a colour picture?
我已经完成了此功能,但无法正常工作
I have made this function but it is not working
import matplotlib.pyplot as plt
from itertools import product
def convertPicturetoColor(self, image, cmap=plt.get_cmap('rainbow')):
'''
Converts a greyscale [0~255] picture to a color picture
'''
a, b = np.shape(image)
m = np.zeros((a, b, 3))
for i, j in product(xrange(a), xrange(b)):
m[i,j,:] = np.array(cmap(image[i,j]))[0:3]
return m
推荐答案
>>> help(cv2.applyColorMap)
Help on built-in function applyColorMap:
applyColorMap(...)
applyColorMap(src, colormap[, dst]) -> dst
这是地图枚举:
COLORMAP_AUTUMN = 0
COLORMAP_BONE = 1
COLORMAP_COOL = 8
COLORMAP_HOT = 11
COLORMAP_HSV = 9
COLORMAP_JET = 2
COLORMAP_OCEAN = 5
COLORMAP_PINK = 10
COLORMAP_RAINBOW = 4
COLORMAP_SPRING = 7
COLORMAP_SUMMER = 6
COLORMAP_WINTER = 3
所以,简单地:
dst = cv2.applyColorMap(src, cv2.COLORMAP_RAINBOW)
这篇关于从灰度图片创建彩色图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文