This repository contains all analysis scripts and data that were used for the following blog posts:
- JPEG Quality estimation: experiments with a modified ImageMagick heuristic
- JPEG quality estimation using simple least squares matching of quantization tables
Below scripts were tested with Python 3.8.10, with version 10.4.0 of Pillow Imaging Library. Pillow can be installed using:
pip install pillow
Important note on Pillow version: some of these scripts will either not work or give (very!) wrong results when used with older Pillow versions! This is because Pillow changed the order in which the values in the quantization tables are returned around the release of Pillow 8.3 (I think!), see details here. The below scripts are all based on the new/current behaviour!
Also the plot-goodness-fit.py script needs Pandas. Installation:
pip install pandas
The scripts are:
- jpegquality-im-original.py: computes JPEG quality for one or more files using original ImageMagick heuristic. Option
--verbose
prints out values of all variables in main loop at each iteration. - jpegquality-im-modified.py: computes JPEG quality for one or more files using modified ImageMagick heuristic. Option
--verbose
prints out values of all variables in main loop at each iteration. - jpegquality-lsm.py: computes JPEG quality for one or more files using least squares matching against standard JPEG quantization tables.
- jpegquality-compare.py: computes JPEG quality for one or more files using all of the above methods, and write results in comma-delimited format.
- generate-testimages-pillow.py: generates a set of JPEG images at 6 quality levels from a user-defined source image.
- generate-testimages-im.sh: generates a set of JPEG images at 6 quality levels from a user-defined source image using ImageMagick.
- generate-testimages-cjpeg.sh: generates 10 thousand images at all possible luminance, chrominance quality combinations using cjpeg.
- test-quantization.py: reads the quantization tables of one or more files and writes the values to 2 comma separated text files.
- plot-goodness-fit.py: creates scatterplots of image vs standard quantization tables and adds relevant measures (Q, RMSE, NSE).
- cjpeg-sensitivity.py: performs simple sensitivity analysis on cjpeg-generated test images and creates scatter plots. This uses the output of generate-testimages-cjpeg.sh.
Both ImageMagick based quality estimation scripts are derived and modified from the Python port of ImageMagick's heuristic by Eddy O (AKA "eddygeek"). In turn this port is based on ImageMagick's original code.
The directory images contains the following folders:
- im_pil: test images created with Python's Pillow library and and ImageMagick. Each image is compressed at level indicated in filename.
- source: source images for all Pillow and ImageMagick test images.
- dbnl: examples of problematic access and master JPEGs from DBNL scans.
- misc: miscellaneous images, most of these give different quality estimates depending on which tool/method is used.
- image-98.jpg, image-177.jpg: taken from sample-images
- sample-birch-400x300.jpg: taken from samplelib.com
- sample-jpg-files-sample-4.jpg: taken from toolsfairy.com
- jpeg420exif.jpg, jpeg422jfif.jpg and jpeg444.jpg taken from w3.org
- hopper_16bit_qtables.jpg: taken from Pillow test images.