【问题标题】:How can i minimize the blurriness after i resize my images?调整图像大小后如何最大限度地减少模糊?
【发布时间】:2018-09-15 01:55:58
【问题描述】:

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

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以外的不同选项

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

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

问题是我的图像在原始图像中充满了小文本,因此在调整它们的大小以便能够进一步处理甚至阅读它们时确实需要一个好的结果。

【问题讨论】:

  • 试试img = img.convert("RGB").resize(wsize,hsize).quantize()
  • 给出了这个错误ValueError: unknown resampling filter

标签: python python-3.x image image-processing python-imaging-library


【解决方案1】:

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

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

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

之后您可以执行相同的操作来重新获得模糊文本颜色与周围像素之间的一些对比 - 仅此而已。两者都会影响整个画面。

阅读:http://pillow.readthedocs.io/en/3.1.x/reference/ImageFilter.html - 有一个 Sharpen 过滤器,你可以试试。

【讨论】:

    【解决方案2】:

    为了扩展帕特里克的回答,过滤器会改变图像的外观,并可能在应用后导致图像中出现伪影。以下是我推荐的两个:

    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')
    

    【讨论】:

      猜你喜欢
      • 2018-11-27
      • 1970-01-01
      • 1970-01-01
      • 2021-12-20
      • 2013-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-21
      相关资源
      最近更新 更多