OpenCV中的假彩色滤光片
我试图在OpenCV上找到一些过滤器,但对文档进行了彻底的修改,但没有任何效果。我想知道它是否在OpenCV中被称为其他东西,因为它似乎足够常见,可以在框架中实现OpenCV中的假彩色滤光片,opencv,Opencv,我试图在OpenCV上找到一些过滤器,但对文档进行了彻底的修改,但没有任何效果。我想知道它是否在OpenCV中被称为其他东西,因为它似乎足够常见,可以在框架中实现 如何应用此过滤器 如果无法实现,您可以采取更一般的方法: 将图像转换为HSV 将每个像素的色调通道设置为输入色调 您可以使用applyColorMap: #包括 cv::Mat灰度图像。。。 cv::假彩色; cv::applyColorMap(灰度图像、假彩色、cv::COLORMAP\u-JET); 它们有许多可用的假彩色贴图
如何应用此过滤器 如果无法实现,您可以采取更一般的方法:
- 将图像转换为HSV
- 将每个像素的色调通道设置为输入色调
#包括
cv::Mat灰度图像。。。
cv::假彩色;
cv::applyColorMap(灰度图像、假彩色、cv::COLORMAP\u-JET);
它们有许多可用的假彩色贴图。有几种假彩色的方法。通常,图像是三个强度图像的合成
cv::split()
另一种情况是,使用连续调色板将灰度图像放大为三种颜色,称为伪彩色。请参见@melnibon的答案。这是我用Python编写的一个方便的函数,它来自一个项目,该项目为伪彩色/假彩色应用了颜色映射,我使用热成像设备的输入很好地区分温度变化。此功能可以根据您的喜好进行改装 代码提供了一种在所有不同OpenCV过滤器之间切换的机制,以及使用自定义颜色映射的选项 将过滤器模式设置为0-11以应用OpenCV过滤器。否则,将filter_mode设置为12或13,以使用自定义1x256 RGB图像梯度作为过滤器来变换灰度图像 请参阅下面的用法
import cv2 # import OpenCV
...
def apply_colormap_filter(cv2_image, filter_mode) :
# A colormap for psudocolors/false color to distinguish hot spots in image
# input: [cv2_image] the greyscale input, [filter_mode] filter selection (0-13)
if filter_mode >= 12 : # lut image constraint: image has to be RGB of size 1x256
###### custom colormaps ######
if filter_mode == 12 :
lut = cv2.imread('thermal-colormap.png') # 1x256 RGB image
elif filter_mode == 13 :
lut = cv2.imread('lut_sky.png') # 1x256 RGB image
else :
lut = cv2.imread('lut_sky.png') # 1x256 RGB image
# APPLY CUSTOM FILTER
cv2_image = cv2.cvtColor(cv2_image, cv2.COLOR_GRAY2BGR);
final = cv2.LUT(cv2_image, lut)
###### custom colormaps ######
elif filter_mode < 12 :
###### Utilise OpenCL inbuilt filters ######
final = cv2.applyColorMap(cv2_image, filter_mode)
###### Utilise OpenCL inbuilt filters ######
return final # return the resultant False-colored image
gray = cv2.imread('grayscale-image.png') # some grayscale image of variable dimensions
thermal = apply_colormap_filter(gray, 12) # Use custom filter
cv2.imshow('Thermal Image', thermal)
导入cv2#导入OpenCV
...
def apply_colormap_过滤器(cv2_图像,过滤器模式):
#用于区分图像热点的伪彩色/假彩色颜色图
#输入:[cv2_图像]灰度输入,[filter_mode]过滤器选择(0-13)
如果过滤器模式>=12:#lut图像约束:图像必须是大小为1x256的RGB
######自定义颜色贴图######
如果过滤器_模式==12:
lut=cv2.imread('thermal-colormap.png')#1x256 RGB图像
elif过滤器_模式==13:
lut=cv2.imread('lut_sky.png')#1x256 RGB图像
其他:
lut=cv2.imread('lut_sky.png')#1x256 RGB图像
#应用自定义筛选器
cv2_图像=cv2.CVT颜色(cv2_图像,cv2.COLOR_灰度2BGR);
最终=cv2.LUT(cv2_图像,LUT)
######自定义颜色贴图######
elif过滤器模式<12:
######使用OpenCL内置过滤器######
最终=cv2.applyColorMap(cv2_图像,过滤器_模式)
######使用OpenCL内置过滤器######
返回最终结果#返回生成的假彩色图像
gray=cv2.imread('grayscale-image.png')#一些可变尺寸的灰度图像
thermal=apply_colormap_filter(灰色,12)#使用自定义过滤器
cv2.imshow(“热图像”,热图像)
<代码>解释“假颜色”会有帮助。我只是添加了一个链接到伪彩色滤镜的文档,MayBeWoW,这是非常埋没的。C++中的OpenCV API可以以类似于上面的Python代码的方式使用。我相信这个解决方案既简单又可扩展。希望这能解决这个具体问题。
import cv2 # import OpenCV
...
def apply_colormap_filter(cv2_image, filter_mode) :
# A colormap for psudocolors/false color to distinguish hot spots in image
# input: [cv2_image] the greyscale input, [filter_mode] filter selection (0-13)
if filter_mode >= 12 : # lut image constraint: image has to be RGB of size 1x256
###### custom colormaps ######
if filter_mode == 12 :
lut = cv2.imread('thermal-colormap.png') # 1x256 RGB image
elif filter_mode == 13 :
lut = cv2.imread('lut_sky.png') # 1x256 RGB image
else :
lut = cv2.imread('lut_sky.png') # 1x256 RGB image
# APPLY CUSTOM FILTER
cv2_image = cv2.cvtColor(cv2_image, cv2.COLOR_GRAY2BGR);
final = cv2.LUT(cv2_image, lut)
###### custom colormaps ######
elif filter_mode < 12 :
###### Utilise OpenCL inbuilt filters ######
final = cv2.applyColorMap(cv2_image, filter_mode)
###### Utilise OpenCL inbuilt filters ######
return final # return the resultant False-colored image
gray = cv2.imread('grayscale-image.png') # some grayscale image of variable dimensions
thermal = apply_colormap_filter(gray, 12) # Use custom filter
cv2.imshow('Thermal Image', thermal)