hussulinux
hussulinux

Reputation: 197

OpenCV how to smoothen boundary

I have an image and I want to create a smooth boundary. This is normally done in photoshop by smudge tool around the boundary of the image, but I'd like to do it via code.

What I want is this:

What I want is this:

My image background is alpha.

I have two solutions:

  1. Take all the boundary pixels region and apply gaussian blur on only those regions. I don't know how I can extract only boundary pixels only.

  2. Again, take all the boundary pixels and apply alpha at each pixel. Forexample I take 10px boundary around the image and then each pixel I apply 10% increased alpha, so the effect will be 10% alpha , 20%....100% and then the visible region.

Any help is appreciated. I'm trying to do it on iPhone with OpenCV

Upvotes: 3

Views: 11917

Answers (3)

rockinfresh
rockinfresh

Reputation: 2106

Gaussian Blur will do the trick. You can learn more from here: http://docs.opencv.org/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter.html

All of which are common methods of smoothing.

Upvotes: 0

Michael Burdinov
Michael Burdinov

Reputation: 4448

All you need is simple blur (Gaussian or any other). And you don't need to extract only boundary pixels because smoothing of flat region is the same flat region, so you will see smoothing only on boundaries.

Upvotes: 2

Jason
Jason

Reputation: 13986

What you are looking for is called "Anti-aliasing". Generally the way to do it is either use some built-in technique, such as sub-sampling during render time (See OpenCV docs for anti-aliasing: http://docs.opencv.org/modules/core/doc/drawing_functions.html). Or to render the image at a larger scale (say 4x the size), and then down-sample (scale the image down).

Upvotes: 1

Related Questions