I want to get the contours of a continues area, but without having very narrow places in the output.
The input image can look like this image (after applying the threshold):
By just calling OpenCVs findContours method, I get following result:
My problem is that I don't want to have the narrow (white) peaks in the result. Just blurring the image will not work, because I must not include the black peak(s). So the wanted output should look like this green line:
Is it possible the tell OpenCV (findContours) a minimum "thickness" of the area?
Erosion can be thought as adding the boundary pixels to the background. Thus, it gets rid of such narrow pieces in your input. However, since it distorts all the boundaries, you need to apply dilation afterwards, to undo the effect of erosion on the actual boundary. The erosion+dilation process is called opening.
The code portion below generates the desired output. Play with
k_size
according to your image size. Then applyfindContours
.The output: