0

I have an RGB image and a binary mask of same dimensions. I want to blur only those portions of the RGB image where the value of mask is 255 (white). How to do this in OpenCV Python?

I tried implementing the method given in the answer of morotspaj in Smoothing Mat of float with mask but didn't quite get the result I was expecting. Can someone explain it?

Community
  • 1
  • 1
Abdul Fatir
  • 6,159
  • 5
  • 31
  • 58
  • 1
    Could you blur the whole image, and then combine it with the original using bitwise operations (like in the last section of [this OpenCV tutorial](http://docs.opencv.org/3.1.0/d0/d86/tutorial_py_image_arithmetics.html#gsc.tab=0))? Or do you require that the masked out pixels make no contribution to the blur at all? – Dan Mašek May 20 '16 at 11:44
  • That could be done, but would it not be time consuming as I have a lot of large images to process? – Abdul Fatir May 20 '16 at 11:46
  • In what sense? Is the mask going to select only very small sections of the source image? It's not entirely clear from your question -- could you perhaps add some images to illustrate it? Also show what you're getting with your current algorithm and describe your expectation. – Dan Mašek May 20 '16 at 11:49
  • The best answer depends on many factor: the shape of the rois in your mask (if it could be modeled as a combination of rectangles, you could blur sub matrices, and that would be fast), and the density of your mask (if you have a *significant* part of the pixels in the mask "on", than Dan Masek approach is definitely the best). If performance is important, you have to develop several methods and test which is the fastest. For efficiency, in OpenCV blurring use intermediate results, and in general it's convenient to process a series of consecutive pixels, a sparse mask wouldn't work well. – Antonio May 20 '16 at 12:35

0 Answers0