Removing Labeled components based on boundary condition.

3 visualizaciones (últimos 30 días)
Mayur
Mayur el 22 de Abr. de 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

Respuesta aceptada

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

Más respuestas (2)

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

Iniciar sesión para comentar.


Mayur
Mayur el 23 de Abr. de 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 comentario
Walter Roberson
Walter Roberson el 23 de Abr. de 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.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by