Hello,

i want to blur specific regions (ellipses) of an image with smooth edges. What i have done so far is:

1. create mask for non blurring area (ellipse)
2. create inverted mask for blurred area
3. copy the original image and using bitwise_and with the mask get the specific areas
4. blurred the image and using bitwise_and with inverted mask
5. combined the to images

The edges are "hard" and i wanted to use a blur on the mask to feather the edges. But when i combine the blurred mask the edges become weired.

Is there a way to achieve this?

If code is needed ill provide.

edit retag close merge delete

Sort by ยป oldest newest most voted

Hi @Nirmalan! Here is my Simple algorithm to smooth with Mask!

bool MaskedSmooth(const Mat mSrc,const Mat mMask,Mat &mDst, double Sigma, double MaskRadius)
{
if(mSrc.empty())
{
return 0;
}
if(Sigma<1)
Sigma=1.0;

Mat mGSmooth;
mDst = Mat(mSrc.size(),mSrc.type());

GaussianBlur(mSrc,mGSmooth,Size(0,0),Sigma); //You can add any Smoothing algorithm here e.g Median, Billateral, etc...

for (size_t Rows = 0; Rows < mSrc.rows; Rows++)
{
for (size_t Cols = 0; Cols < mSrc.cols; Cols++)
{
Vec3b pSrc = mSrc.at<Vec3b>(Rows, Cols);
Vec3b pSSrc = mGSmooth.at<Vec3b>(Rows, Cols);
Vec3b &pDest = mDst.at<Vec3b>(Rows, Cols);

float Percent = Mask / 255.0;
pDest = (1 - Percent)* pSrc + (pSSrc * Percent);
}
}

return true;
}

{
if(mSrc.empty())
{
return 0;
}
if(Sigma<1)
Sigma=1.0;

Mat mGSmooth;

mDst = Mat(mSrc.size(),CV_32FC3);
mSrc.convertTo(mSrc,CV_32FC3,1.0/255.0);

GaussianBlur(mSrc,mGSmooth,Size(0,0),Sigma);

Mat M1,M2,M3;

multiply(M1,mSrc,M2);

return true;
}

int _tmain(int argc, _TCHAR* argv[])
{
string sSFileNameEx = "Test.png";

{
cout << "[Error]! Invalid Input Image";
return 0;
}

imshow("mSrc", mSrc);

waitKey(0);
return 0;
}


Source Image:

Source Smoothed

more

Nice but this only works if a mask is easy definable. You would be amazed how many applications do not offer that.

( 2016-10-25 02:42:41 -0500 )edit

@StevenPuttemans Yes agreed! But isn't that the OP question?

( 2016-10-25 02:45:23 -0500 )edit

Ah well, after re-reading it, that might indeed be the case and I might mis-interpret the question...

( 2016-10-25 02:46:38 -0500 )edit

In one of my publications on pedestrian detection in cycloramic images, together with a co-author/collegue, I propose a technique of softblurring. The idea is basically to relate the power of the blurring to the position related to the center of the object/region your are blurring.

This was programmed in OpenCV, so basically it should be doable.

To make a longer story short:

more

( 2016-10-24 07:12:37 -0500 )edit

high resolution images :D

( 2016-10-24 08:03:37 -0500 )edit