查找表的16位Mat有效方式? [英] LookUp Table for 16-Bit Mat Efficient way?
问题描述
我想使用opencv减少16位Mat.我尝试使用opencv LUT 函数来减少此垫子.但似乎它不支持16位Mat.使用opencv c ++减少16位Mat的有效方法是什么?感谢您的帮助!
I want to reduce a 16-Bit Mat using opencv. I tried to use opencv LUT function to reduce this mat. But it seems like it wont support 16-Bit Mat. What is the efficient way of reducing a 16-Bit Mat using opencv c++? Any help is appreciated!
例如,我要扫描&将所有像素减少 10个灰度!我想实现opencv文档中针对16位Mat的相同示例.
e.g I want to scan & reduce all the pixels by 10 Grey levels! I want to implement the same example given in the opencv documentation for 16-Bit Mat.
如何通过指针访问Mat的每个元素?
推荐答案
感谢您帮助我解决此问题! 这是我基于16位查找表的还原代码.希望这对某人有用!
Thank you for helping me to solve this problem! Here is my code for 16-Bit Look up table based reduction. hope this might be useful for someone!
main()
{
Size Img_Size(320,240);
Mat Img_Source_16(Size(320,240),CV_16UC1,Scalar::all(0));
Mat Img_Destination_16(Size(320,240),CV_16UC1,Scalar::all(0));
unsigned short LookupTable[4096];
for (int i = 0; i < 4096; i++)
{
LookupTable[i]= 4096-i;
}
int i=0;
for (int Row = 0; Row < Img_Size.height; Row++)
{
for (int Col = 0; Col < Img_Size.width; Col++)
{
Img_Source_16.at<short>(Row,Col)= i;
i++;
if(i>=4095)
i=0;
}
}
imshow("Img_Source",Img_Source_16);
t1.start();
Img_Destination_16= ScanImageAndReduceC_16UC1(Img_Source_16.clone(),LookupTable);
imshow("Img_Destination",Img_Destination_16);
t1.stop();
}
Mat& ScanImageAndReduceC_16UC1(Mat& I, const unsigned short* const table)
{
// accept only char type matrices
CV_Assert(I.depth() != sizeof(uchar));
int channels = I.channels();
int nRows = I.rows;
int nCols = I.cols * channels;
if (I.isContinuous())
{
nCols *= nRows;
nRows = 1;
}
int i,j;
unsigned short* p = (unsigned short*)I.data;
for( unsigned int i =0; i < nCols*nRows; ++i)
*p++ = table[*p];
return I;
}
这篇关于查找表的16位Mat有效方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!