try something like this
struct ParamThresh {
int threshMin;
String winName;
Mat img;
};
void AjouteGlissiere(String nomGlissiere, String nomFenetre, int minGlissiere, int maxGlissiere, int valeurDefaut, int *valGlissiere, void(*f)(int, void *), void *r)
{
createTrackbar(nomGlissiere, nomFenetre, valGlissiere, 1, f, r);
setTrackbarMin(nomGlissiere, nomFenetre, minGlissiere);
setTrackbarMax(nomGlissiere, nomFenetre, maxGlissiere);
setTrackbarPos(nomGlissiere, nomFenetre, valeurDefaut);
}
void ChooseThreshold(int x, void *r)
{
ParamThresh *pgc = (ParamThresh*)r;
if (!pgc->img.empty() )
{
Mat imgThresh;
threshold(pgc->img, imgThresh, pgc->threshMin, 255, THRESH_BINARY);
imshow("thresh", imgThresh);
imshow("original", pgc->img);
Mat imgColor, imgThreshColor;
vector<Mat> p;
p.push_back(Mat::zeros(pgc->img.size(), CV_8UC1));
p.push_back(pgc->img);
p.push_back(Mat::zeros(pgc->img.size(),CV_8UC1));
merge(p, imgColor);
cvtColor(pgc->img&imgThresh, imgThreshColor, COLOR_GRAY2BGR);
Mat dst;
addWeighted(imgColor, 0.15, imgThreshColor, 0.85, 0, dst);
imshow(pgc->winName, dst);
waitKey(50);
}
}
int main(int argc, char *argv[])
{
ParamThresh pgc;
pgc.winName = "result";
pgc.img = imread("C:/Users/Laurent.PC-LAURENT-VISI/Desktop/15138717637485638.jpg", IMREAD_GRAYSCALE);
namedWindow(pgc.winName, WINDOW_GUI_EXPANDED);
AjouteGlissiere("thresh", pgc.winName, 0, 255, 128, &pgc.threshMin, ChooseThreshold,(void*)&pgc);
char code = 0;
while(code!=27)
code=waitKey(10);
return 0;
}
If image sizes are equal then you can create color images using cvtColorwith [code] for second image(https://docs.opencv.org/trunk/d... and convert first image using three planes (two plane with zeros and last plane with mask). Then add two images
Thanks LBerger. But which color code to use for the conversion of binary to color(RGB) with cvtColor
I cropped your one image so that both images were the same size. If you're not too concerned about speed, you can try this Python code:
Does this help u...
cv2.addWeighted
maybe you can find this useful
Thanks for replying sjhalayka. But does your code result in colored overlay, the first image I have is a 2d numpy array of dtype int16
Thanks sturkmen , the link was really helpful, but I had problems with conversion of gray image to BGR color image.