1 // https://docs.opencv.org/3.2.0/d2/de8/group__core__array.html#gab55b8d062b7f5587720ede032d34156f 2 3 //其实就是颜色缩减,索引图 4 #include<opencv2/opencv.hpp> 5 6 using namespace cv; 7 8 int main() 9 { 10 //<1> 构建一个Mat 表 11 Mat look_up_table(1, 256, CV_8U); 12 for (int i = 0; i < 256; i++) 13 { 14 look_up_table.ptr<uchar>(0)[i] = 10 * (i / 10); 15 } 16 //<2> 利用LUT函数查找 17 Mat srcImage = imread("lena.jpg", -1); 18 Mat dstImage; 19 LUT(srcImage, look_up_table, dstImage); 20 imshow("look_up_table", look_up_table); 21 namedWindow("srcImage", WINDOW_NORMAL); 22 imshow("srcImage", srcImage); 23 namedWindow("dstImage", WINDOW_NORMAL); 24 imshow("dstImage", dstImage); 25 waitKey(0); 26 return 1; 27 }
其实就是一句话概括如下:(类似于统计直方图)
dstImage.ptr<uchar>(y)[x] = look_up_table[0][dstImage.ptr<uchar>(y)[x]];