LUT 图像查找表

LUT(Look - Up Table,图像查找表)在图像处理中是一种极为重要的工具。其本质是利用 map 算法对像素进行处理。具体来说,当像素值范围处于 0 - 255 时 ,LUT 会预先创建 256 个数组,对这些像素值进行预处理。
左侧是低对比度图像的像素值矩阵,右侧是高对比度图像的像素值矩阵。在 LUT 中,已经预先建立了从低对比度像素值到高对比度像素值的映射关系。当需要将低对比度图像转换为高对比度图像时,无需重新计算,只需将低对比度图像中像素值为 40 的元素,按照查找表的映射关系,整体改成 70(这里仅为示例示意,实际映射关系依具体 LUT 设定而定) ,即可快速实现图像对比度的调整。
cpp
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
//打开图片
Mat src = imread("D:\\souse\\opencv_tutorial_data-master\\images\\pedestrian.png", IMREAD_COLOR);
if (src.empty())
{
cout << "Could not open or find the image!" << endl;
return -1;
}
//显示原图
namedWindow("Original Image", WINDOW_AUTOSIZE);
imshow("Original Image", src);
//读入查找表
Mat color = imread("D:\\souse\\opencv_tutorial_data-master\\images\\lut.png", IMREAD_COLOR);
Mat lut(256, 1, CV_8UC3);
for(int i = 0; i < 256; i++)
{
lut.at<Vec3b>(i, 0) = color.at<Vec3b>(10, i);
}
imshow("Color", color);
imshow("LUT", lut);
Mat des;
LUT(src, lut, des);
imshow("Result Image", des);
waitKey(0);
}

颜色表使用

cpp
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
//打开图片
Mat src = imread("D:\\souse\\opencv_tutorial_data-master\\images\\pedestrian.png", IMREAD_COLOR);
if (src.empty())
{
cout << "Could not open or find the image!" << endl;
return -1;
}
//显示原图
namedWindow("Original Image", WINDOW_AUTOSIZE);
imshow("Original Image", src);
//读入查找表
Mat des;
//COLORMAP_JET:将图像转换为伪彩色图像
applyColorMap(src, des, COLORMAP_JET);
imshow("Result Image1", des);
applyColorMap(src, des, COLORMAP_COOL);
imshow("Result Image2", des);
waitKey(0);
}
