opencv 2中的LUT函数为 :
void LUT(InputArray src, InputArray lut, OutputArray dst,int interpolation);
src表示的是输入图像(可以是单通道也可是3通道);lut表示查找表(查找表也可以是单通道,也可以是3通道,如果输入图像为单通道,那查找表必须为单通道, 若输入图像为3通道,查找表可以为单通道,也可以为3通道,若为单通道则表示对图像3个 通道都应用这个表,若为3通道则分别应用 );dst表示输出图像。
#include<iostream>
#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<vector>
#include<opencv2/core/core.hpp>
using namespace std;
using namespace cv;
//LUT函数对图像元素进行查找、扫描和操作图像
int main()
{
double time0 = static_cast<double>(getTickCount());//记录起始时间
Mat src = imread("D:\\VC\\c++\\opencv源码\\opencv源码\\12.bmp");
cout << "result.size()=" << src.size() << "\tresult.channels()=" << src.channels() << endl;
Mat dst = src.clone();
int channel = src.channels();
int num = 50;//图像缩减程度
//单通道图像
if (channel == 1)
{
//定义函数lut
uchar table[256];
for (int i = 0; i < 256; i++)
{
table[i] = i / num * num;
}
Mat lut(1, 256, CV_8UC1, table);
LUT(src, lut, dst);
}
//BGR图像
if (channel == 3)
{
//定义函数lut
uchar table[256*3];
for (int i = 0; i < 256; i++)
{
table[3*i] = i / num * num;
table[3 * i+1] = i / num * num;
table[3 * i+2] = i / num * num;
}
Mat lut(1, 256, CV_8UC3, table);
LUT(src, lut, dst);
}
imshow("原图", src);
imshow("缩减后的图", dst);
time0 = ((double)getTickCount() - time0) / getTickFrequency();
cout << "此方法运行时间:" << time0 << "秒" << endl;//输出运行时间
waitKey(0);
system("pause");
return 0;
}