Removing Labeled components based on boundary condition.

3 次查看(过去 30 天)
Hey guys i have a binary image in which there are letters in white and background is black. No letter is attached to the boundary but some unwanted areas are attached to the boundary. Is there any way to remove these areas using the fact that those will always be attached to the boundary. Following is a link to a sample image.. http://www.image-upload.net/viewer.php?file=hiu4aujtlbl4pwbc3d3w.jpg

采纳的回答

Mayur
Mayur 2011-4-23
Hey one simple command solved my problem.
imclearborder(bw);
It removes the components attached to the border.

更多回答(2 个)

Walter Roberson
Walter Roberson 2011-4-22
Sure.
[r, c] = size(IMAGE);
locations = sub2ind([r c], [ones(1,c) r*ones(1,c) 1:r 1:r], [1:c 1:c ones(1,r) c*ones(1,r)]);
IMAGE = imfill(IMAGE, locations);
This is more work than needs to be done, in that once you have identified any one point on the edge that needs to be filled, it will "seed" the entire rest of the cavity. You could optimize the locations by detecting consecutive runs and leaving just one point in the run. On the other hand, once any particular cavity is painted, additional points on that cavity should return trivially as the cavity will already be full.
  2 个评论
Mayur
Mayur 2011-4-22
How can i use labeling here. We can find out the index of the unwanted area then remove it by ismember condition.
Walter Roberson
Walter Roberson 2011-4-23
Well, you could check the bounding box of the labeled area and see if it hits the edge of the matrix.

请先登录,再进行评论。


Mayur
Mayur 2011-4-23
How about introducing more white pixels along the whole boundary and then removing the area by using some threshold. How to add white pixels along the whole boundary of an binary image?
  1 个评论
Walter Roberson
Walter Roberson 2011-4-23
If you were to embed the matrix into one that had one extra row and column of white at each side, take the logical negation of the result, imfill() that starting at any one point on the outside, take the logical negation of the result, and extract the original matrix out of it.
The logical negation is in order to make the white pixels the "background" pixels to be filled.
Inserting into a larger matrix makes would give you a solid boundary around the original that you know would be filled, incidentally filling any space touching that boundary.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by