JPEG -quality & -sampling-factor

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

JPEG -quality & -sampling-factor

Post by GreenKoopa »

http://www.imagemagick.org/script/comma ... hp#quality
When the quality is greater than 90, then the chroma channels are not downsampled.

http://www.imagemagick.org/Usage/formats/#jpg_write
However when "quality" is 90 or higher, the channels are not sub-sampled.

The documentation does not make clear that -quality does reset -sampling-factor if it has been set previously. This is least clear when it is set implicitly by an input image. Here the sampling factor is determined by in.jpg, not -quality:
convert in.jpg -quality ## out.jpg

For images not in Y'CBCR, this is a huge problem. Here out.jpg is blurry:
convert wizard: in.jpg
convert in.jpg -colorspace CMYK out.jpg
For a user who hasn't set -quality and has never used -sampling-factor, this resulting blur is difficult to understand.

Bug or documentation issue, let me know and I'll respond to these users appropriately. These two forum topics brought this issue to attention:

bizarre drop in quality on no-op convert on small JPEG - by bugbear
viewtopic.php?f=1&t=21934&p=93593

RGB JPEG to CMYK JEPEG looks much too dark and blurry - by dschroeder
viewtopic.php?f=1&t=23474


ImageMagick 6.8.5-6 2013-05-10 Q16 on Windows 7
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: JPEG -quality & -sampling-factor

Post by snibgo »

Thanks for this, GK. With a bit of experimentation, it seems the general advice should be:

"If you get blurring in an output JPG file, insert "-sampling-factor 1x1" immediately before the output filename. However, this will also increase the file size."

Is that good advice? If so, perhaps Anthony can add it to documentation.
snibgo's IM pages: im.snibgo.com
Post Reply