# Size filtering on binary images

I have noisy images from which I extract the contours using OpencCV's findCountours, which performs binarization internally. This results in innumerable small outlines made of three or four pixels, which I would like to avoid.

I want to discard these, either before extracting the contours, or during that step. I could binarize the image myself and use a size filter (i.e. erase the blobs tiny in area), or I could use a variant of the contouring function that implicitly discards the very short outlines.

But I can't find OpenCV functions that look like this. Any hint ?

Note that I don't want to use any denoising function, as it will degrade the signal. I don't want to erode either, for the same reason.

Example of outlines to be discarded (don't mind the annotations):

I am not asking to get rid of all noisy blobs, but of the smallest ones.

• Can a Hough transform do the job for you? Are lines you do want usually strait lines? – havakok Jul 17 '19 at 15:26
• @havakok: sorry, I want to discard the tiny blobs, and nothing else. – Yves Daoust Jul 17 '19 at 15:51
• Can't you just calculate their size and discard all blobs below a certain threshold? – T A Jul 18 '19 at 11:46
• @TA: that would be a circular solution. I want to get rid of the small blobs to avoid detecting them. – Yves Daoust Jul 18 '19 at 11:51