I have an image I am trying to segment by colouring each pixel either red green or blue. I have calculated a confidence score for each pixel and want to adjust the alpha transparency of the pixel to reflect confidence, i.e. low confidence means almost transparent. Is there a way to do this in OpenCV? If not can anyone suggest a minimally invasive library (C++)?
I have tries using a 4 channel 8-bit Mat
as suggested by Aurellius, here is the code:
cv::Mat m = cv::Mat(20,20, CV_8UC4);
for(int i = 0; i < m.rows; i++){
for(int j = 0; j < m.cols; j++){
Vec4b& v = m.at<Vec4b>(i,j);
v[0] = 255;
v[1] = 0;
v[2] = 0;
v[3] = 0.5;
}
}
imwrite("alpha.png", m);
namedWindow("m");
imshow("m", m);
waitKey(0);
The image shown is just all blue (no transparency) and the image just fully transparent.
See Question&Answers more detail:os