Removing components connected to an arbitrary border
19 次查看(过去 30 天)
显示 更早的评论
I have a binary image, which contains a border line.
Inside the border there are several objects.
I want to remove all objects how touch this border. Like imclearborder does with objects how touch the border of the image.
Please note that the border is not the same as the border of the image.
0 个评论
回答(1 个)
Puru Kathuria
2020-12-27
You can use imclearborder to suppresses structures that are lighter than their surroundings and that are connected to the image border.
Also, you can specifiy the connectivity parameter in imclearborder according to your requirements.
Example:
conn = 4;
imclearborder(image,conn)
The above code uses 4-connected neighborhood and does not consider pixel at (5,2) to be connected with the border pixel at (4,1), so it will not be cleared whereas the below code uses 8-connected neighborhood and does consider pixel at (5,2) to be connected with the border pixel at (4,1).
conn = 4;
imclearborder(image,conn);
Otherwise, if you want to remove a region around the point (x,y).
idx = img(y, x);
img(img == ind) = 0;
And if you want to exclude objects that touch the a particular border (top/left/bottom/right) then consider using imclearborder after padding the particular edge of the image first so that they are not touching the border.
Hope it helps.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!