在学习立体视觉过程中,视差图会以灰度图的形式表现出来,然而在论文中,为了便于观看,增强图像的效果,常常会需要转换成伪彩色。
在python中利用opencv的colormap函数完成转化 程序如下:
import cv2
import os.path
import glob
import numpy as np
from PIL import Image
def convertPNG(pngfile, outdir):
im_depth = cv2.imread(pngfile)
im_color = cv2.applyColorMap(cv2.convertScaleAbs(im_depth, alpha=1), cv2.COLORMAP_JET)
im = Image.fromarray(im_color)
im.save(os.path.join(outdir, os.path.basename(pngfile)))
for pngfile in glob.glob("C:/Users/lenovo/Desktop/2colorful/GrayscaleImage/*.png"):
convertPNG(pngfile, "C:/Users/lenovo/Desktop/2colorful/ColorMap")
在程序中有alpha这个值,会影响效果,我参考的文档设置为了15,根据我的图片,我设置为了1,甚至删了,直接按照缺省的情况,都没啥问题。
可选的颜色空间如下图所示: 
最后我选用了Middlebury Stereo数据集的深度图进行转换,选用的图片和转化的效果如下:    
|