Reputation: 6005
I have a image which contains white clusters on black background. The clusters of white portions are not joined together, however I want to draw a contour around entire enclosure instead of around each cluster. The image is attached.
When i tried to form contour it does it around individual cluster. Can I get some tip, help, or code on how to form one general contour.
Upvotes: 2
Views: 1302
Reputation: 921
You could use HoughLines
to find lines in the image.
The outer edges of you imgae should be the longest lines.
Maybe combine this with user2151446's idea of dilation to get better results.
Upvotes: 1
Reputation: 11941
The opencv convex hull function does almost exactly what you want. It "Finds the convex hull of a point set." See:
I said "almost", because you might not want to cut straight across the lower left.
Another approach would to do morphological dilation, N times, until you only have one contiguous white area. You would need to think about how you can you effiently check that there is only one white area remaining. Then erode N times to get back to something about the same as the original (but just one contiguous shape). Then find contours. If you did this you would need to embed the image within a bigger black background so that there is room for the dilation. See:
Upvotes: 3
Reputation: 348
perhaps, you can try to divide the image into many small patches, then you can calculate how many pixels are white in each patches, if the pixels number is more than a threshold, set all this patch pixels as white color. then maybe you can find one general contour.
Upvotes: 0