使用Python Imaging Library模糊包含文本的图像

Eri*_*onn 3 python python-imaging-library

我有一个包含一些文本的图像(在标准文档字体大小),我试图模糊图像,使文本不再可读.

然而,PIL中的默认ImageFilter.BLUR太强了,所以图像只是空白了,除了这里和那里的单个像素.

在PIL的某个地方有一个较弱的BLUR吗?或者有更好的过滤器/更好的方法吗?

Mar*_*ers 5

BLUR只是预设ImageFilter.Kernel:

class BLUR(BuiltinFilter):
    name = "Blur"
    filterargs = (5, 5), 16, 0, (
        1,  1,  1,  1,  1,
        1,  0,  0,  0,  1,
        1,  0,  0,  0,  1,
        1,  0,  0,  0,  1,
        1,  1,  1,  1,  1
        )
Run Code Online (Sandbox Code Playgroud)

其中BuiltinFilter是内核的绕过构造一个简单的定制子类,filterargs包括size,scale,offset,kernel.换句话说,BLUR相当于:

BLUR = Kernel((5, 5), (1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1))
Run Code Online (Sandbox Code Playgroud)

比例设置为默认值(1625个权重的总和),偏移量也是如此.

您可以尝试使用较小的内核:

mildblur = Kernel((3, 3), (1, 1, 1, 1, 0, 1, 1, 1, 1))
Run Code Online (Sandbox Code Playgroud)

或者使用比例和偏移值.