LookUp table for 16-bit mat. Effective way?

I want to reduce 16 bit matte using opencv. I tried using opencv LUT to reduce this mat. But it looks like it does not support 16-bit Mat. What is an effective way to reduce a 16-bit matrix using opencv c ++? Any help is appreciated!

For example, I want to scan and reduce all pixels by 10 gray levels! I want to implement the same example provided in the opencv documentation for a 16-bit Mat.

How to access each Mat element through pointers?

+1
source share
2 answers

, ! 16- . , -!

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

LUT : https://github.com/Itseez/opencv/blob/fd59551ff0648d33568d7fc63164bf86c5d3ccb6/modules/core/src/convert.cpp

OpenCV : Intel IPP ( IppLUTParallelBody_LUTCN 3 4- ). Intel IPP, ippiLUTPalette_16u_C3R ippiLUTPalette_8u_C3R + ).

OpenCL ( ), ocl_LUT (, , ).

LUTParallelBody/IppLUTParallelBody_LUTCN ( - ). LUT8u_. : . IppLUTParallelBody . ParallelLoopBody , ​​ OpenMP Intel TBB, . , - , .

+1

All Articles