OpenCV -- 伪彩 applyColorMap

opencv之伪彩变换
我们在处理红外图像时,由于红外图像都是16位的数据,灰度范围较大,对比度不明显,经常通过直方图均衡的方式将图像增强进行8位的显示。

红外图像在一定程度上反映了环境中物体的温度变化——我们可以认为较暗的图像区域表示的是温度较低的区域(蓝色来表示),更加明亮的区域认为是温度较高的区域(红色来表示),进而将灰度图转变为彩色数据便于人类的视觉系统进行可视化。

用伪彩色更好地显示数据的其他例子是高度、压力、密度、湿度等等。

applyColorMap伪彩色函数

OpenCV定义了12种colormap(色度图),可以应用于8位的灰度图像,使用函数applyColorMap产生伪彩色图像。

applyColorMap定义

1 void applyColorMap(InputArray src, OutputArray dst, int colormap);
2 // InputArray src:   输入原始图像(只支持8位灰度图像)
3 // OutputArray dst:  输出结果伪彩色图像
4 // int colormap:     色度图的种类

applyColorMap用法

1 using namespace cv;
2 Mat im_gray = imread("pluto.jpg", IMREAD_GRAYSCALE);
3 Mat im_color;
4 applyColorMap(im_gray, im_color, COLORMAP_JET);

下图显示了一个关于colormap(色度图)的视觉表示和COLORMAP_*的数值,左边的颜色模式表示较低的灰度值,右边的则表示较高的灰度值。

LUT颜色查找表

**1、定义一个映射:**色度图是从0-255值256种颜色映射。在OpenCV,我们需要创建一个大小为256×1的8位彩色图像来存储256个颜色值。

**2、对照颜色使用查找表:**在OpenCV,你可以申请一个信息存储在一个256×1的彩色图像使用查找表LUT图像。

LUT定义

1 void LUT(InputArray src, InputArray lut, OutputArray dst);
2 // src表示的是输入图像(可以是单通道也可是3通道)
3 // lut表示查找表(查找表也可以是单通道,也可以是3通道,如果输入图像为单通道,那查找表必须为单通道,若输入图像为3通道,查找表可以为单通道,也可以为3通道,若为单通道则表示对图像3个,通道都应用这个表,若为3通道则分别应用 )
4 // dst表示输出图像

LUT用法

#include<highguihighgui.hpp>
using namespace cv;
int main()
{
    uchar lutData[256 * 3];
    int j = 0;
    for (int i = 0; i<256; i++)
    {
        if (i <= 100)
        {
            lutData[i * 3] = 0;
            lutData[i * 3 + 1] = 50;
            lutData[i * 3 + 2] = 50;
        }
        if (i > 100 && i <= 200)
        {
            lutData[i * 3] = 100;
            lutData[i * 3 + 1] = 10;
            lutData[i * 3 + 2] = 200;
        }
        if (i > 200)
        {
            lutData[i * 3] = 255;
            lutData[i * 3 + 1] = 200;
            lutData[i * 3 + 2] = 100;
        }

    }
    Mat lut(1, 256, CV_8UC3, lutData);
    Mat a = imread("test.jpg", CV_LOAD_IMAGE_ANYCOLOR);
    Mat b;
    namedWindow("anjis", CV_WINDOW_AUTOSIZE);
    namedWindow("anjis1", CV_WINDOW_AUTOSIZE);
    imshow("anjis", a);
    LUT(a, lut, b);
    imshow("anjis1", b);
    waitKey();
}

附 录

0 COLORMAP_AUTUMN
在这里插入图片描述

1 COLORMAP_BONE
在这里插入图片描述

2 COLORMAP_JET
在这里插入图片描述

3 COLORMAP_WINTER
在这里插入图片描述

4 COLORMAP_RAINBOW
在这里插入图片描述

5 COLORMAP_OCEAN
在这里插入图片描述

6 COLORMAP_SUMMER
在这里插入图片描述

7 COLORMAP_SPRING
在这里插入图片描述

8 COLORMAP_COOL
在这里插入图片描述

9 COLORMAP_HSV
在这里插入图片描述

10 COLORMAP_PINK
在这里插入图片描述

11 COLORMAP_HOT
在这里插入图片描述

原文地址:https://www.cnblogs.com/zzzsj/p/14582233.html