Max
Max

Reputation: 347

Python: Blur specific region in an image

I'm trying to blur around specific regions in a 2D image (the data is an array of size m x n).

The points are specified by an m x n mask. cv2 and scikit avaiable.

I tried:

  1. Simply applying blur filters to the masked image. But that isn't not working.

  2. Extracting the points to blur by np.nan the rest, blurring and reassembling. Also not working, because the blur obviously needs the surrounding points to work correctly.

Any ideas?

Cheers

Upvotes: 0

Views: 2031

Answers (1)

MateuszB
MateuszB

Reputation: 320

What was the result in the first case? It sounds like a good approach. What did you expect and what you get?

You can also try something like that:

  1. Either create a copy of a whole image or just slightly bigger ROI (to include samples that will be used for blurring)
  2. Apply blur on the created image
  3. Apply masks on two images (from original image take everything except ROI and from blurred image take ROI)
  4. Add two masked images

If you want more smooth transition make sure that masks aren't binary. You can smooth them using another blurring (blur one mask and create the second one by calculating: mask2 = 1 - mask1. By doing so you will be sure that weights always add up to one).

Upvotes: 2

Related Questions