1 | initial version |
Use a mask :
Mat img=imread(f:lena.jpg,IMREAD_COLOR);
Mat gx,gy,g;
Sobel(pgc.img,gx, CV_16S, 1, 0, 3);
Sobel(pgc.img,gy, CV_16S, 0, 1,3);
g=gx.mul(gx)+gy.mul(gy);
g.convertTo(g,CV_16U);
cvtColor(g,g,CV_BGR2GRAY);
Mat marqueur =g<20;
Mat cc;
int nb=connectedComponents(marqueur,cc,8,CV_32S);
watershed(img,cc);
Mat res;
cc.convertTo(res,CV_8UC1);
imshow("res",res);
waitKey(0);
I think now you have to merge watershed results...
2 | No.2 Revision |
Use a mask :
Mat img=imread(f:lena.jpg,IMREAD_COLOR);
img=imread("f:lena.jpg",IMREAD_COLOR);
Mat gx,gy,g;
Sobel(pgc.img,gx, CV_16S, 1, 0, 3);
Sobel(pgc.img,gy, CV_16S, 0, 1,3);
g=gx.mul(gx)+gy.mul(gy);
g.convertTo(g,CV_16U);
cvtColor(g,g,CV_BGR2GRAY);
Mat marqueur =g<20;
Mat cc;
int nb=connectedComponents(marqueur,cc,8,CV_32S);
watershed(img,cc);
Mat res;
cc.convertTo(res,CV_8UC1);
imshow("res",res);
waitKey(0);
I think now you have to merge watershed results...
3 | No.3 Revision |
Use a mask :
Mat img=imread("f:lena.jpg",IMREAD_COLOR);
Mat gx,gy,g;
Sobel(pgc.img,gx, Sobel(img,gx, CV_16S, 1, 0, 3);
Sobel(pgc.img,gy, Sobel(img,gy, CV_16S, 0, 1,3);
g=gx.mul(gx)+gy.mul(gy);
g.convertTo(g,CV_16U);
cvtColor(g,g,CV_BGR2GRAY);
Mat marqueur =g<20;
Mat cc;
int nb=connectedComponents(marqueur,cc,8,CV_32S);
watershed(img,cc);
Mat res;
cc.convertTo(res,CV_8UC1);
imshow("res",res);
Mat palette = Mat(256, 1, CV_8UC1,Scalar(255));
palette.at<uchar>(0,0)=0;
cc.convertTo(res, CV_8UC1);
LUT(res, palette, res);
imshow("res", res);
waitKey(0);
I think now you have to merge watershed results...