필터 지우기
필터 지우기

Removing Labeled components based on boundary condition.

조회 수: 1 (최근 30일)
Mayur
Mayur 2011년 4월 22일
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