为什么PIL产生的JPEG图像质量如此差? [英] Why is the quality of JPEG images produced by PIL so poor?

查看:641
本文介绍了为什么PIL产生的JPEG图像质量如此差?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用PIL(1.1.7)创建的JPEG图像质量很差.这是一个示例:

The JPEG images created with PIL (1.1.7) have very poor quality. Here is an example:

输入: https://s23.postimg.cc/8bks3x5p7/cover_1.jpg

输出: https://s23.postimg.cc/68ey9zva3/cover_2.jpg

使用以下代码创建输出图像:

The output image was created with the following code:

from PIL import Image
im = Image.open('/path/to/cover_1.jpg')
im.save('/path/to/cover_2.jpg', format='JPEG', quality=100)

红色文字看起来真的很糟糕.使用GIMP或Photoshop保存图像甚至不能接近PIL所产生的不良质量. 有人知道为什么会发生这种情况以及如何解决吗?

The red text looks really awful. Saving the image with GIMP or Photoshop does not even come close to the bad quality created by PIL. Does somebody know why this happens and how it can be solved?

推荐答案

JPEG质量有两个部分.第一个是quality设置,您已经将其设置为可能的最高值.

There are two parts to JPEG quality. The first is the quality setting which you have already set to the highest possible value.

JPEG还使用色度二次采样,假设色相的变化不如亮度变化重要,并且一些信息可以安全地丢弃.不幸的是,在要求苛刻的应用程序中,情况并非总是如此,您最容易在红色边缘注意到这一点. PIL不会公开记录的设置来控制此方面.

JPEG also uses chroma subsampling, assuming that color hue changes are less important than lightness changes and some information can be safely thrown away. Unfortunately in demanding applications this isn't always true, and you can most easily notice this on red edges. PIL doesn't expose a documented setting to control this aspect.

由Pascal Beyeler

我刚刚找到一个禁用子采样的选项.您可以在保存文件时设置 subsampling=0 图像,图像看起来更清晰!感谢您的帮助标记!

I just found an option which disables subsampling. You can set subsampling=0 when saving an image and the image looks way sharper! Thanks for your Help Mark!

im.save('/path/to/cover-2.jpg', format='JPEG', subsampling=0, quality=100)

这篇关于为什么PIL产生的JPEG图像质量如此差?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆