如何在android中制作图像模糊

时间:2012-10-19 10:53:47

标签: android image-processing

我试图对图像实现一些效果,如图像边框和一些颜色各种各样 现在我试图像这样制作模糊图像

enter image description here

图像的中心部分清晰可见,其他部分模糊

听到我所指的链接 http://www.jhlabs.com/ip/filters/VariableBlurFilter.html

但它与这个图像不同(这个java中的lib所以我将BufferdImage转换为位图,但现在它已经不在我的脑海里了)任何人都可以帮助我...

2 个答案:

答案 0 :(得分:4)

很抱歉迟到的回复。我本周末忘了检查stackoverflow。

无论如何,我认为你应该做的就是这样(它已被简化为灰度,但应该很容易为RGB工作):

oim = original image
xc, yc = center point
d = distance from center point for in-focus
fval = zeros, matrix size of oim
max_blur = maximum blur radius
for all pixels (xp,yp) in oim
    dist = sqrt((xp-xc)^2+(yp-yc)^2)
    dist = dist-d // we only care about the area beyond the clear area
    if dist>0
       blur = dist
    end
    if blur>max_blur
       blur = max_blur // this can also be scaled or whatever works for your needs
    end
    blur = round(blur)
    fval(xp,yp) = blur
end
nim = oim
for b=1:max_blur
    blurred = blur_function(oim,b)
    for all pixels (xp,yp) in fval
       if fval(xp,yp) == b
          nim(xp,yp) = blurred(xp,yp)
       end
     end
end

nim现在是新形象

所以基本上这里发生的是我们首先制作一种查找表,告诉我们模糊给定像素的程度。焦点值是每个像素距离清晰区域的距离的函数。这是矩阵fval。然后,我们多次模糊图像,每次使用模糊图像中的新像素数据更新新图像,如果我们正在更新该非焦点水平,则仅更新给定像素。

blur_function可以是任何东西。当我自己测试时,我在MatLab中使用了平均模糊。

希望这有帮助!

答案 1 :(得分:2)

从以下链接下载适用于Android的JHLabs Library。这些库可以在Android上运行。