I am working in a project where I have to show some portion of the image clear and make rest part of the image blur. The blur should be managed by slider. Means it can be increase or decrease. The final result image should look alike below.
During my research for this I found below links useful
http://blog.neteril.org/blog/2013/08/12/blurring-images-on-android/
http://blog.neteril.org/blog/2013/08/12/blurring-images-on-android/
But the issue in above links is they all make complete image blur. Not some part of image.
Kindly suggest some solution to achieve this. Thanks in advance.
do a masked blur few times ....
create mask
0
means blur (black) and>=1
means not blur (white). Init this part by big enough value for examplew=100
pixelscreate masked blur function
just a common convolution with some matrix like
but do it only for target pixels where mask is
==0
after image is blurred blur also the mask. This should enlarge the white area a bit (by pixel per iteration but losing magnitude on borders that is whyw>1
).loop bullet #2
N
timesN
determines blur/non-blur gradient depth thew
is only to assure that burred mask will grow... Each time the blur mask will increase its white partThat should do the trick, You can also use dilatation of the mask instead of blurring it.
[edit1] implementation
Have played with this a bit today and found out that the mask is not growing enough with smooth so I change the algo a bit (here mine code C++):
here the smooth function:
create gradient mask with circles increasing in color from
1
to255
rest is black the gradient width is
dr
and determine the smoothing sharpness.create smooth masked with mask and threshold
smooth all pixels where mask pixel is < threshold. See the function
rgb_smooth_masked
. It uses2x2
convolution matrixloop threshold from
1
to255
by some stepthe step determines the image blur strength.
And finally here some visual results this is source image I taken with my camera:
And here the output on the left and mask on the right:
the blue color means
values < 256
(B is lowest 8 bits of color)I use my own picture class for images so some members are:
xs,ys
size of image in pixelsp[y][x].dd
is pixel at(x,y)
position as 32 bit integer typeclear(color)
- clears entire imageresize(xs,ys)
- resizes image to new resolution