Removing Labeled components based on boundary condition.

3 vues (au cours des 30 derniers jours)
Mayur
Mayur le 22 Avr 2011
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

Réponse acceptée

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

Plus de réponses (2)

Walter Roberson
Walter Roberson le 22 Avr 2011
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 commentaires
Mayur
Mayur le 22 Avr 2011
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 le 23 Avr 2011
Well, you could check the bounding box of the labeled area and see if it hits the edge of the matrix.

Connectez-vous pour commenter.


Mayur
Mayur le 23 Avr 2011
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 commentaire
Walter Roberson
Walter Roberson le 23 Avr 2011
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.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by