pensfute
pensfute

Reputation: 351

Smooth image contours using python

I applied some operations on the image to remove the white background(color clustering), but the issue is that the result is not smooth on the contours as you can see here: https://i.sstatic.net/pf0Pi.jpg.

What's your advice for smoothing the contours without blurring the entire image?

Thanks in advance!

Upvotes: 0

Views: 1502

Answers (3)

pensfute
pensfute

Reputation: 351

I found one way to solve my problem. The first step is to approximate the contours using approxPolyDp(https://docs.opencv.org/3.4.0/d3/dc0/group__imgproc__shape.html#ga0012a5fdaea70b8a9970165d98722b4c). The second step is to have a gradual transparency on the contours.

The results are not perfect for each image, but it's a lot cleaner.

Hope it helps !

Upvotes: 0

user1196549
user1196549

Reputation:

What you need is called image matting. The basic idea is to determine the amount of background color (white) present in the pixel and to replace it with black. This will anti-alias the outlines.

Upvotes: 1

marco romelli
marco romelli

Reputation: 1163

I think a simple Bilateral filter could do the job. You can also try more advanced filters like Total Variation Denoising.

Keep in mind that this process is never going to be perfect if your input images are very different from each other.

Upvotes: 0

Related Questions