首页 > 其他分享 >JPEG Image Quality in PIL

JPEG Image Quality in PIL

时间:2023-04-27 14:35:31浏览次数:30  
标签:use PIL quality Image JPEG save Quality image

JPEG Image Quality in PIL

Introduction

The other day, I was haunted by a bug and found that it was an issue with the image quality saved by Pillow after spending a few hours debugging the code.

Initially, the workflow of my code was like loading the JPEG image with PIL and after some operation, saving the image again. But I didn’t give any other parameters except the file name when using Image.save() method.

The quality parameter

After looking up the documentation, I find that PIL will save the image with quality factor 75 by default so that the image quality is decreased. The documentation for quality says:

The image quality, on a scale from 1 (worst) to 95 (best). The default is 75. Values above 95 should be avoided; 100 disables portions of the JPEG compression algorithm, and results in large files with hardly any gain in image quality.

Using a quality factor of 95 should be enough to preserve the image quality:

img.save('test.jpg', quality=95)

Subsampling

According to this post, even if you use quality=100, the saved image will still be slightly different from the original image. This is because PIL will also use subsampling technique to reduce the image size. You can use subsampling=0 to turn off this feature. Overall, to retain the content of original image, you may use:

img.save('test.jpg', quality=100, subsampling=0)

Other options for quality

For JPEG files, there are also a list of preset options you can use for the quality parameter, such web_high, high. The complete list of options can be found here. These preset options will set the subsampling factor and quantization table which is used in image quantization process.

References

标签:use,PIL,quality,Image,JPEG,save,Quality,image
From: https://www.cnblogs.com/lwp-nicol/p/17358795.html

相关文章

  • 我看看哪个靓仔还没把Github Copilot用起来?
    本人经常分享有价值的生产力工具、技术、好物与书籍,可关注同名公众......
  • Image captioning常用的指标
    1.n-gram是什么?n-gram是自然语言处理中常用的一种模型,它是指由n个连续的词组成的序列。例如,在句子"Ilovenaturallanguageprocessing"中,1-gram可以表示为{“I”,“love”,“natural”,“language”,“processing”},2-gram(也称为bigram)可以表示为{“Ilove”,“lovenatura......
  • FileBuffer-ImageBuffer代码实现
    #include"stdafx.h"#include<stdio.h>#include<windows.h>#include<malloc.h>////FileBuffer函数DWORDReadPEFile(LPVOID*ppFileBuffer){FILE*pFile=NULL;DWORDSizeFileBuffer=0;pFile=fopen("C://WINDOWS//system......
  • P43FileBuffer-ImageBuffer
    MISC可能比SizeOfRawData大可能含有一些数据未初始化RVA:相对偏移地址FOA:文件偏移地址PE加载的过程: 1、根据SizeOfImage的大小,开辟一块缓冲区(ImageBuffer). 2、根据SizeOfHeader的大小,将头信息从FileBuffer拷贝到ImageBuffer 3、根据节表中的信息......
  • python安装pillow报错
    Fatalerrorinlauncher:Unabletocreateprocessusing'"D:\ProgramFiles\Python311\python.exe" "D:\ProgramFiles\Python311\Scripts\pip.exe"installpillow':??????????? 解决:cmd窗口执行32位:python3-mpipinstall--up......
  • 2022AAAI_Semantically Contrastive Learning for Low-light Image Enhancement(SCL_L
    1.motivation利用语义对比学习2.network (1)输入的是低光图像首先经过图像增强的网络(Zero-DCE),再将它传入语义分割网络中(2)语义分割网络用的是DeepLabv3+......
  • Cycle GAN:Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial
    paper:https://arxiv.org/pdf/1703.10593.pdf[2017]code参考:https://github.com/junyanz/pytorch-CycleGAN-and-pix2pixhttps://zhuanlan.zhihu.com/p/79221194https://blog.csdn.net/fangjin_kl/article/details/128117396https://www.bilibili.com/video/BV1kb4y197P......
  • Deep-Learning-Based Spatio-Temporal-Spectral Integrated Fusion of Heterogeneous
    Deep-Learning-BasedSpatio-Temporal-SpectralIntegratedFusionofHeterogeneousRemoteSensingImagesabstract为了解决STF中的生成heterogeneousimages问题:为此,本文首次提出了一种基于新型深度残差循环生成对抗网络(GAN)的异构集成框架。所提出的网络由前向融合部......
  • Spatiotemporal Remote Sensing Image Fusion Using Multiscale Two-Stream Convoluti
    SpatiotemporalRemoteSensingImageFusionUsingMultiscaleTwo-StreamConvolutionalNeuralNetworksabstract地表反射率图像的渐变和突变是现有STF方法的主要挑战。(Gradualandabruptchangesinlandsurfacereflectanceimagesarethemainchallengesinexisting......
  • @JvmDefault is only supported since JVM target 1.8. Recompile with '-jvm-target
    问题Logcat提示’@JvmDefault’isonlysupportedsinceJVMtarget1.8.Recompilewith'-jvm-target1.8’解决在gradle中插入以下代码android{//..其他代码...kotlinOptions{jvmTarget="1.8"}}问题Logcat提示:Usageof‘@JvmDefault......