如何在调整图片大小后最小化模糊?

3

我的调整图像大小的代码是:

from PIL import Image


ratio = 0.2
img = Image.open('/home/user/Desktop/test_pic/1-0.png')
hsize = int((float(img.size[1])*float(ratio)))
wsize = int((float(img.size[0])*float(ratio)))
img = img.resize((wsize,hsize), Image.ANTIALIAS)
img.save('/home/user/Desktop/test_pic/change.png')

我尝试过的方法是:

除了.ANTIALIAShttps://pillow.readthedocs.io/en/3.1.x/reference/Image.html#PIL.Image.Image.resize之外的不同选项

在保存时添加参数qualityimg.save('/home/user/Desktop/test_pic/change.png',quality=95)

转换为rgbimg = img.convert("RGB").resize((wsize,hsize), Image.ANTIALIAS)

问题在于我的图像原始图像中充满小文本,因此当它们被调整大小以进一步处理甚至阅读它们时,我真的需要一个很好的结果。


尝试:img = img.convert("RGB").resize(wsize,hsize).quantize() - Mick_
出现了错误 ValueError: 未知的重采样滤波器 - Jess
2个回答

0
进一步解释Patrick的答案,滤镜可以改变图像的外观,并在应用后导致图像出现伪影。以下是我推荐的两个滤镜:
from PIL import Image, ImageFilter

ratio = 0.2
img = Image.open('/home/user/Desktop/test_pic/1-0.png')
hsize = int((float(img.size[1])*float(ratio)))
wsize = int((float(img.size[0])*float(ratio)))
img = img.resize((wsize,hsize), Image.ANTIALIAS)
img.save('/home/user/Desktop/test_pic/1-0.no-filter.png')
img_sharpened = img.filter(ImageFilter.SHARPEN)
img_sharpened.save('/home/user/Desktop/test_pic/1-0.sharpened.png')

f = ImageFilter.UnsharpMask()
img_unsharp = img.filter(f)
img_unsharp.save('/home/user/Desktop/test_pic/1-0.unsharp.png')

0

调整图像大小并不是什么魔法 - 如果您的图像为4000x3000,高度为40x30(每个字符,单独的行可能有6像素厚度),并将其调整为0.2,则结果图像为800x600,文本字符为8x6,其中包含1(.2)像素厚度的线条。

文本行是非常细的线条,因此它们会与周围的颜色混合在一起 - 无论您使用什么过滤器来“平均”消失像素的颜色到剩下的像素中。

您可以尝试在调整大小之前锐化图像,以使文本更加突出,希望通过双/三线性过滤获得更清晰的结果。

您也可以在调整大小后进行相同的操作,以恢复被压缩的文本颜色与周围像素之间的对比度 - 但这就是全部了。两者都会影响整张图片。

阅读:http://pillow.readthedocs.io/en/3.1.x/reference/ImageFilter.html - 有一个Sharpen滤镜可以尝试使用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接