The best JPEG quality: ImageMagick vs Lightroom?
JPEG is the most frequently used lossy image compression format. Based on the theories of human visualization and perception, it is able compress the image size significantly, but usually it looses some pixel details. To maintain a right balance between the size of the JPEG and the full detail of the original file (RAW, DNG or TIFF), I've started to investigate for the right tool that will be able to produce the best quality, meaning the one that is closer to the original.
Summary of my workflow
I will publish my detailed workflow later, but in essence it is the following:
- I shoot in RAW and convert it to DNG.
- I use Lightroom to edit / keyword the photos.
- If finished, I would like to have some exported, high-quality JPEG. Either directly from Lightroom, or first to TIFF than converted to JPEG.
Such investigation requires more samples, but now I've done only with one photo. The photo for my analysis was a recently taken picture of a flower. It is 18MP image, both its TIFF and PNG version is around 84MB.
Lightroom JPEG export with quality=100
Lightroom has a builtin JPEG export (not really a surprise), and it does have a slider where you are able to set the JPEG quality between 1-100. I've exported my photo and the size was: 8.6MB. Nice size, excelent quality, I am not able to see any visible difference compared to the original photo in Lightroom.
Lightroom TIFF export, then ImageMagick convert with quality=100
Lightroom has a builtin TIFF export (another expected thing), and it does as it says: it exports the photo in lossless tiff. I've used ImageMagick to convert the image into JPEG, actually two with slightly different quality settings:
convert 2011-03-29-0153.tif -quality 100 2011-03-29-0153-im.jpg convert 2011-03-29-0153.tif -quality 99 2011-03-29-0153-99.jpg
The file sizes are 13MB and 9.5MB, no visible differences either, same excellent quality.
Let's compare them
I've used ImageMagick's compose tool to create a difference image from the JPEGs and the TIFF baseline:
composite 2011-03-29-0153-lr.jpg 2011-03-29-0153.tif -compose difference diff_lr.png composite 2011-03-29-0153-im.jpg 2011-03-29-0153.tif -compose difference diff_im.png composite 2011-03-29-0153-99.jpg 2011-03-29-0153.tif -compose difference diff_99.png
As all difference file is around 70-71MB, one needs to have a statistical analysis, first for the Lightroom version:
convert diff_lr.png -type Grayscale -verbose info: [...] Channel statistics: Gray: min: 0 (0) max: 966 (0.0147402) mean: 171.279 (0.00261356) standard deviation: 95.8879 (0.00146316) kurtosis: 1.31163 skewness: 1.04533 [...]
And for the ImageMagick conversions:
convert diff_im.png -type Grayscale -verbose info: [...] Channel statistics: Gray: min: 0 (0) max: 681 (0.0103914) mean: 141.247 (0.00215529) standard deviation: 83.6611 (0.00127659) kurtosis: 1.76253 skewness: 1.26732 [...] convert diff_99.png -type Grayscale -verbose info: [...] Channel statistics: Gray: min: 0 (0) max: 818 (0.0124819) mean: 156.099 (0.00238192) standard deviation: 92.0507 (0.0014046) kurtosis: 1.02586 skewness: 1.10303 [...]
What does it mean?
It means that ImageMagick is able to produce a JPEG file that:
- has ~40% less relative maximal difference
- has ~20% less relative mean difference
- has less variance in average difference
- has less but infrequently larger deviations
- has ~50% larger file size
From the pure data point of view, ImageMagick created a JPEG version that is more closer to the original photo compared on pixel-to-pixel basis. It should be noted, that the absolute difference between them is around 0.0004%, which is a very low value.
It is not a surprise that as we have slightly lowered the ImageMagick quality, the numbers became very similar to the Lightroom's version. Still a better quality, but larger file size too.
I can see no visible difference between the JPEG file. Based purely on the numbers, ImageMagick's -quality 100 does make better output, but the difference does not justifies the 50% increase in storage size (and costs). The slightly modified version has lower storage differences, however it is pretty close to the per-pixel numbers of the Lightroom's JPEG.
At the moment I would like to keep my workflow simple, and exporting the photos directly to JPEG seems a valid and justified option. Exporting to TIFF and doing the conversion afterwards does not seem to worth the effort.