opencv中LUT函数实现颜色空间缩减

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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小鹿( ﹡ˆoˆ﹡ )

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值