problem filling a contour

조회 수: 11 (최근 30일)
Silvia
Silvia 2013년 11월 20일
댓글: Image Analyst 2013년 11월 21일
Hello,
I have a problem. I have an image (a masc) which has a hole. I detect de contour of the masc and I use "fill" to fill with a colour. My problem is that the hole is also painted and I don't want that.
Is there any option to avoid filling the holes? Thanks
Silvia

답변 (1개)

Image Analyst
Image Analyst 2013년 11월 20일
If you have the coordinates of the contour, you can use poly2mask() to create binary images. For nested contours, you might have to call it twice, then subtract the binary image from the inner "hole" from the larger outer mask to make the hole zero and the torus 1.
  댓글 수: 2
Silvia
Silvia 2013년 11월 21일
Hello,
In fact I already have my mask with the hole inside. What I want to do is this: I have the mask and I have obtained the outside contour and the hole contour so I have two contours. Then, I want to fill of a color the area between these two contours.
I need help because I use the function "fill" and it fills with a colour all inside the outside contour (included the hole), I don't want the hole appears coloured.
Thanks
Image Analyst
Image Analyst 2013년 11월 21일
You need to get the hole iteself. So invert the mask of the donut, call imclearborder() and then assign:
holeMask = imclearborder(!binaryMask);
grayImage(holeMask) = whateverIntensityYouWant;

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by