Ask Your Question

How to remove the element attached to the image border?

asked 2019-12-17 05:47:52 -0600

Hello, now i'm trying to delete the elements attached to the image border by using open-cv (in python). In the Matlab, we can use the clearborder to delete these elements, but in this time, i am supposed to use python and its library. I suppose that i should detect the elements which i want to delete and after it, i might use the floodfill to delete the complement.

However, i don't know how i can detect the elements attached to the image border.

If you have a time, could you give me the advice?

image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-12-17 07:59:08 -0600

kbarni gravatar image

One word: connectedComponentsWithStats

For each component you can simply check if it touches the borders (left==0 or top==0 or right==cols or bottom==rows), and then set every pixel with the corresponding label to 0 if you want to delete it.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2019-12-17 05:47:52 -0600

Seen: 2,116 times

Last updated: Dec 17 '19