1 | initial version |
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;
}