Removing the boundary after segmentation ?

asked 2017-06-14 03:09:11 -0500

Nbb gravatar image

Hey all, I am working on image segmentation. After using watershed, I get the result shown in the first image below where the black lines indicate the boundary between regions. The result I would like to get however, should look like the second image without any black pixels (boundaries).

Currently, the way I assign boundary pixels to a region is as follows

1. loop through the entire image to look for black pixels. if it is a black pixel (boundary) then,
2. check the pixels to the right, bottom, and diagonal (right-bottom)  
3. set the value of the black pixel to one of the 3 neighbors mentioned in step 2.

Would this be efficient enough ? I was hoping if could share a more efficient algorithm if the one I wrote above is not good.

image description image description

edit retag flag offensive close merge delete


Did you try looping throw the image in the way you described? I'm not an expert in this kind of things, but i have seen a code like below in tutorials before and would say its a common method.

for( int x = 0; x < src.rows; x++ ) 
  for( int y = 0; y < src.cols; y++ )
      if (<Vec3b>(x, y) == Vec3b(0,0,0) ) 
      {<Vec3b>(x, y)[0] = 255;<Vec3b>(x, y)[1] = 255;<Vec3b>(x, y)[2] = 255;

I hope i don't understand something wrong - if so feel free to remove this comment.

Franz Kaiser gravatar imageFranz Kaiser ( 2017-06-14 04:04:15 -0500 )edit

Actually it is black because of visualisation but in fact its a negative value as described in the documentation: In the function output, each pixel in markers is set to a value of the "seed" components or to -1 at boundaries between the regions. Indeed looping the image and replacing those with the best neighbor element is the way to go.

StevenPuttemans gravatar imageStevenPuttemans ( 2017-06-14 06:35:41 -0500 )edit