Removing Labeled components based on boundary condition.
Ältere Kommentare anzeigen
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

Akzeptierte Antwort
Weitere Antworten (2)
Walter Roberson
am 22 Apr. 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 Kommentare
Mayur
am 22 Apr. 2011
Walter Roberson
am 23 Apr. 2011
Well, you could check the bounding box of the labeled area and see if it hits the edge of the matrix.
Mayur
am 23 Apr. 2011
0 Stimmen
1 Kommentar
Walter Roberson
am 23 Apr. 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.
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!