Far*_*eed 1 python algorithm image-processing python-imaging-library imagefilter
在 Pillow 中,我们可以使用滤镜模糊图像:
模糊图像 = 原始图像.filter(ImageFilter.BLUR)
但这并不是真正的镜头效果。是否可以使用一些自定义过滤器?有什么例子吗?
(第 2 号是我需要的。第 3 号是枕头式模糊滤镜。)
要模拟镜头模糊,您必须特别注意散景效果。要创建散景效果,您必须使用二进制内核模糊方法(例如圆盘模糊,其中您对碟形中当前像素周围的所有像素进行平均)。此外,您还需要对图像进行伽玛校正,使黑暗部分变得非常黑暗,这样只有明亮的斑点才会产生散景。然后,您可以在不进行伽玛校正的情况下再次模糊图像,并获得两者的最大值。
伪代码:
gammaCorrectedImage = image ^ 3 // Or whatever power works for you.
bokeh = discBlur(gammaCorrectedImage)
bokeh = cubeRoot(bokeh) // To get back the original gamma.
blurImage = discBlur(image)
finalImage = max(bokeh, blurImage)
Run Code Online (Sandbox Code Playgroud)
我得到了一个足够接近的结果: