Lookup table transformation

In computer vision, replacing pixels with new values based on their value from a given table that contains the required replacement is called lookup table transformation. This might sound a bit confusing at first but it's a very powerful and simple method for modifying images using lookup tables. Let's see how it's done with a hands-on example.

Let's assume we have an example image and we need to replace the bright pixels (with a value greater than 175) with absolute white, dark pixels (with a value less than 125) with absolute black, and leave the rest of the pixels as they are. To perform such a task, we can simply use a lookup table Mat object along with the LUT function in OpenCV:

Mat lut(1, 256, CV_8UC1); 
for(int i=0; i<256; i++) 
{ 
    if(i < 125) 
        lut.at<uchar>(0, i) = 0; 
    else if(i > 175) 
        lut.at<uchar>(0, i) = 255; 
    else 
        lut.at<uchar>(0, i) = i; 
} 
 
Mat result; 
LUT(image, lut, result); 

The following image depicts the result of this lookup table transformation when it is executed on our example image. As you can see, the lookup table transformation can be executed on both color (on the right) and grayscale (on the left) images:

Using the LUT function wisely can lead to many creative solutions for computer vision problems where replacing pixels with a given value is desired.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.182.66