I've been playing around with opencv2 implemented in C++ for a couple of days and noticed that the lookup tables are the fastest way to apply changes to an image. However, I've been having some troubles with using them for my purposes.
The code below shows an example of inverting pixels' values:
bool apply(Image& img) {
int dim(256);
Mat lut(1, &dim, CV_8U);
for (int i=0; i<256; i++)
lut.at<uchar>(i)= 255-i;
LUT(img.final,lut,img.final);
return true;
}
class Image {
public:
const Mat& original;
Mat final;
...
};
As it's very efficient, much more efficient than changing each pixel by one (verified by my own tests), I'd like to use this method for other operations. However to do this, I have to access each layer (each color, the picture is in BGR) separately. So for example, I'd like to change blue to 255-i, green to 255-i/2 and red to 255-i/3.
I've been searching the net for a while, but couldn't come up with a correct solution. As far as I know, it's possible (documentation) but I can't find a way to implement it.