Is there a simple method to highlight the mask?
If I have mask like
And I have a image( the size is same to the mask) like
I want to hightlight the mask in the image. If I'm in other Language,I just
As you can see, the result image have a transparent red show the mask. I hope implement this in OpenCV. So I write this code
#include <opencv.hpp>
using namespace cv;
using namespace std;
int main() {
Mat srcImg = imread("image.jpg");
Mat mask = imread("mask.jpg", IMREAD_GRAYSCALE)>200;
for(int i=0;i<srcImg.rows;i++)
for(int j=0;j<srcImg.cols;j++)
if(mask.at<uchar>(i, j)==255)
circle(srcImg, Point(j,i), 3, Scalar(0, 0, 128,128));
imshow("image",srcImg);
waitKey();
return 0;
}
But as you see, I use a alpha value in Scalar
, but it is not a transparent red
.
Maybe this is due to the srcImg
just have 3 channels. I have two question about this
- How to hightlight the mask with a transparent red(even the image just have 3 channels)?
- I have to draw
circle
pixel by pixel to do this thing?
there is no alpha channel in image processing but you can use this tutorial
@LBerger Thanks,but it is not a transparent red..Just a transprent whilte..
replace
circle(srcImg, Point(j,i), 3, Scalar(0, 0, 128,128));
withsrcImg.at<Vec3b>(i, j) = srcImg.at<Vec3b>(i, j) - Vec3b(100, 100, 0);
also take a look at this i prefer doing this kind of operations without pixel by pixel approach