Efficient, generic scan image
Hi,
Is there any generic OpenCV function/algorithm (like C++ std::transform) to perform pixel modification. I know that I can write i.e. below code. But is neither generic nor efficient.
cv::Mat image;
cv::Mat new_image;
for( int y = 0; y < image.rows; y++ )
{ for( int x = 0; x < image.cols; x++ )
{ for( int c = 0; c < 3; c++ )
{ new_image.at<Vec3b>(y,x)[c] =
saturate_cast<uchar>( alpha*( image.at<Vec3b>(y,x)[c] ) + beta ); }
}
}
I would like to use it like i.e.
cv::Mat src;
cv::Mat dst;
transform(src, dst, pixelUnaryFunctor);
cv::Mat src1;
cv::Mat src2;
cv::Mat dst;
transform(src1, src2, dst, pixelBinaryFunctor);
then , just do it:
in other words, opencv already has overloaded operators for this. if you catch yourself writing your own your own per-pixel-loops, you're doing it the wrong way.
Thank you for answer. Sorry I provided probably but example. I know that we have also converTo image.convertTo(new_image, -1, alpha, beta);
But What about below code. Join two images base on alpha channel of image2.
As @berak said, just use overloaded operators, in this case applied to the corresponding channel.
I do not know how to use operators instead of below three lines. Could you write it for me?
Thank you in advance.