Rounding a jagged contour

asked 2018-12-06 00:54:15 -0500

Martian gravatar image

Does OpenCV have any methods for gently rounding contours in a binary (black and white) image? Often, contour detection results in some rough edges, usually as a result of noise or other anomalies. I'd like to incrementally round out the spikey sections and fill in sharper indentations without too much loss in resolution or accuracy over the rest of the contour. IOW, most of the contour lines already smooth enough.

Dilate-Erode cycles would no doubt affect the accuracy of the entire contour, not just the aberrant areas.

I've heard of CRFs (Conditional Random Fields) used for this in some apps, but haven't found anything directly usable.

(Important to note that I'm not talking about Gaussian smoothing. This is a binary image--no gray scale).

edit retag flag offensive close merge delete

Comments

i did not understand your question well ( maybe an image will be helpful) but see https://stackoverflow.com/questions/2...

sturkmen gravatar imagesturkmen ( 2018-12-06 05:10:57 -0500 )edit

Thanks for your reply and the link, Sturkmen. I probably over-explained that. I'm looking for something that would work kind of like dilate-then-erode: Simply straighten out jagged edges of a binary outline. But dilate-erode has side-effects that I'd like to avoid. The solution at your link appears to be on the right track but it looks like it blurs edges. I'm dealing with binary mask-like images. Perhaps it would be possible to convert to gray-scale, do Gaussian blur, then threshold to get back to the binary format. I'm not clear on whether that would work. I've heard of CRF-based functions that do this, but it looks like those are not yet incorporated into OpenCV.

Martian gravatar imageMartian ( 2018-12-07 05:37:56 -0500 )edit