5/27/2018

OpenCV LUT(look up table) example code

OpenCV LUT example source code


...
int LUTexample()
{

    Mat img = imread("AbyssCGI2.jpg");

    Mat lookUpTable(1, 256, CV_8U);
    uchar* p = lookUpTable.data;
    int factor = 256 / 5;
    for (int i = 0; i < 256; ++i)
    {
        p[i] = factor * (i / factor);
        printf("[%d] = %d \n", i, p[i]);
    }



    Mat reduced;
    LUT(img, lookUpTable, reduced);

    namedWindow("img", 0);
    imshow("img", img);
    namedWindow("reduced", 0);
    imshow("reduced", reduced);


    /*
    //////////////////// gray & color test!!
    Mat img2(1, 1, CV_8UC3);
    img2.setTo(Scalar(0, 128, 255));
    Mat im_color3;
    LUT(img2, lookUpTable, im_color3);
    cout << im_color3 << endl;
    //namedWindow("im_color3", 0);
    //imshow("im_color3", im_color3);

    //different result with color!!
    Mat img2_gray;
    cvtColor(img2, img2_gray, CV_BGR2GRAY);
    Mat im_color4;
    LUT(img2_gray, lookUpTable, im_color4);
    cout << im_color4 << endl;
    //namedWindow("im_color4", 0);
    //imshow("im_color4", im_color4);
    //////////////////////*/


    waitKey(0);


    return 0;

}
...



No comments:

Post a Comment