2

嗨,我正在尝试对图像进行一些效果,例如图像边框和各种颜色,现在我正在尝试制作像这样的模糊图像

在此处输入图像描述

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

听到的是我参考的链接女巫 http://www.jhlabs.com/ip/filters/VariableBlurFilter.html

但它与这张图片不同(java中的这个lib,所以我将BufferdImage转换为位图,但现在我不在乎)任何人都可以帮助我解决这个问题..

4

2 回答 2

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 中使用了平均模糊。

希望这可以帮助!

于 2012-10-22T15:31:55.567 回答
2

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

于 2013-03-05T19:34:01.480 回答