SIGMA Photo Pro
improving JPEG output

Written on Thursday, November 14, 2002, by Guido Vollbeding, member IJG (Independent JPEG Group),
for serious consideration by Foveon and Sigma people (update: Canon and others, too - see addendum),
inspired by digital camera image quality comparison discussion on Sigma SLR Talk Forum
(update: and JPEG distortion discussion on Canon SLR Talk Forum).

The recently introduced Foveon X3 full-color image sensor technology represents a breakthrough in digital photography and a major milestone in the history of photography in general.
Digital cameras equipped with a Foveon X3 sensor (like Sigma's SD9) offer the unique opportunity to capture and store images of unprecedented quality.
So far digital camera images suffered noticeably from serious limitations of abnormal capture and sensor technologies (notably the color mosaic filter scheme).
The inferior quality of digital camera images so far led to a negligence of careful consideration of appropriate JPEG compression configuration. Of course, if image quality suffers in the first place (sensor capture), then JPEG can't operate with optimal quality anyway, and few attention has been paid to appropriate JPEG compression control for best quality results.
Since JPEG is going on to be the most common standard for still image representation and interchange in the conceivable future, provision has to be made for appropriate JPEG compression configuration, matching the new quality standards introduced with the Foveon X3 technology.

The JPEG color subsampling issue

Despite recognizing the new appealing overall "complete picture" look, people soon started analyzing SD9 picture outputs (mostly in JPEG format according to common interchange standards) to a deeper matter, zooming in and enlarging pixelmaps.
When first seeing that the SIGMA Photo Pro software, which is delivered with the Sigma SD9 for raw image conversion, can only generate 2x2 color subsampled JPEG files (according to actual IJG compression defaults), I was a bit concerned that corresponding color artifacts might become noticeable.
The 2x2 color subsampling is usually not a problem and was chosen by IJG as default for good reason. But it depends on the circumstances.
Human color vision and perception suggests that the human eye is less sensitive to color variations than it is to luminance variations. The JPEG 2x2 color subsampling mode exploits this perception and thereby achieves a considerable data reduction effect in the first stage of the compression process (removing 3/4 of color data amount, or 1/2 of full image data!). Essentially the pixel resolution is halfed in both dimensions in the color of the image in this 2x2 subsampling mode. This effect has turned out to be hardly noticeable under normal viewing conditions (that means, full image screen display, for which JPEG was initially optimized).
Since my personal favorite image application is indeed screen display, it wasn't quite a problem for me, because I therefore downsample the SD9 high images by half in each direction for full screen display. That way I have no problem at all with the Sigma 2x2 mode (the IJG decoder which I use for display in my Jpegcrop program has an optimized downsampling mode which can thus directly derive the final output resolution without any color resampling!).
But now that people start zooming in and upscaling, certain artifacts become clearly visible in image comparisons and thus, unfortunately, SD9/Foveon images compare unfavorably in some aspects with the competition:

Sample comparison courtesy Geir Rune from Sigma SLR Talk Forum,
based upon comparison images on

Note that the JPEG internal colorspace separates luminance (Y) from Color component blue (Cb) and Color component red (Cr), hence the extra sensibility in blue/red transitions.

See also the Probing JPEG Chroma Sampling page courtesy Martin Brown.
Here is an excerpt from his page showing the clear difference between Photoshop Q 4 and 5 in the first table where color subsampling jumps from 2x2 to 1x1. (Note: The transition point [Q value] may vary between Photoshop versions!)

Compression Size /bytes Actual size 4x zoom
PhotoShop Q = 4 1141 (2,510) comb_p4.jpg comb_p4.jpg
PhotoShop Q = 5 1029 (2,398) comb_p5.jpg comb_p5.jpg

The effect (artifact) was also called posterization in the dpreview discussion.
See also the stairs in the red/shadow, red/background transitions in the following comparisons with different format output of the same SD9 raw image with SIGMA Photo Pro:

Sample comparisons courtesy Geir Rune from Sigma SLR Talk Forum

Another demonstration can be found here: Chroma subsampling in JPG courtesy Rick Matthews.


We have seen that, under certain circumstances, artifacts become clearly visible in SIGMA Photo Pro generated JPEG images due to the unalterable 2x2 color subsampling setting.
I strongly recommend that Foveon and Sigma put an option in their software to alter the color subsampling setting of their JPEG output!
Foveon and Sigma people, listen: It can't be in your interest that people blame the sensor or camera for a problem which is only related to insufficient control of JPEG compression in your conversion software.
The software seems quite nice otherwise, but this flaw may turn out as a major fault, and it can be fixed. Working around the problem by saving as TIFF and then process by another JPEG compressor is no good solution because probably losing the valuable Exif information.

Note: When compressing JPEG images, there are two major settings to consider: 1. The quantization table adjustment, which is usually handled by a quality scale factor, and 2. The color subsampling option. The IJG encoder uses a 2x2 default color subsampling which may not be appropriate for best quality output. Most other digital cameras use a 2x1 horizontal only color subsampling due to common video and television standards (still image quality less important there!). For best quality output a 1x1 (no) subsampling must be selected. With the IJG cjpeg JPEG compression tool I can easily select the appropriate parameters with the "-quality" and "-sample" options.
SIGMA Photo Pro has a quality selector, that's good. But it has only a fix 2x2 subsampling setting, and that's bad.
One possible solution would be to switch automatically to 1x1 subsampling in higher quality settings according to Photoshop.
A better solution, and my recommendation, is an independent control of color subsampling according to cjpeg. This is more flexible than Photoshop for different user and application requirements.

As a member of the Independent JPEG Group and strong believer in the full-color capture technology I hereby offer my support and assistence for improving the SIGMA Photo Pro JPEG output.
The following image shows my suggestion for extending the SIGMA Photo Pro "Save Images As" dialog with a "JPEG Color Subsampling" selector. Left is the old dialog, right the new.

Default may be 2x2, so this is compatible with the old behavior. Now you can also select 2x1, 1x2, and 1x1. 2x1 is compatible with other digital camera images, 1x2 is compatible with losslessly rotated 2x1 digital camera images, and 1x1 is compatible with higher quality Photoshop settings and provides maximum quality (no color subsampling reduction).
Addition: Perhaps adding a short user-friendly description would be advisable:

2x2 - Good quality / Small filesize
2x1 - Better quality (vertical) / Medium filesize
1x2 - Better quality (horizontal) / Medium filesize
1x1 - Best quality / Large filesize

For implementation, you introduce a variable jpeg_color_subsampling which gets values 0 (initial), 1, 2, or 3 according to the dialog selection (2x2, 2x1, 1x2, and 1x1, respectively).
Now I refer to the example compression code of the IJG distribution. Function "write_JPEG_file()" in file "example.c" contains:
    /* Step 3: set parameters for compression */

    /* First we supply a description of the input image.
     * Four fields of the cinfo struct must be filled in:
    cinfo.image_width = image_width; /* image width and height, in pixels */
    cinfo.image_height = image_height;
    cinfo.input_components = 3; /* # of color components per pixel */
    cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
    /* Now use the library's routine to set default compression parameters.
     * (You must set at least cinfo.in_color_space before calling this,
     * since the defaults depend on the source color space.)
    /* Now you can set any non-default parameters you wish to.
     * Here we just illustrate the use of quality (quantization table) scaling:
    jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
Now just add the following code hereafter:
    switch (jpeg_color_subsampling)
    /* Note: jpeg_set_defaults sets
     * cinfo.comp_info[0].v_samp_factor = cinfo.comp_info[0].h_samp_factor = 2
    case 1:
      cinfo.comp_info[0].v_samp_factor = 1;
    case 2:
      cinfo.comp_info[0].h_samp_factor = 1;
    case 3:
      cinfo.comp_info[0].v_samp_factor = 1;
      cinfo.comp_info[0].h_samp_factor = 1;
I haven't actually tried the code. If it shouldn't work, let me know. It is also possible to look at the "-sample" option evaluation in the cjpeg code.

Note: I'm currently developing a new JPEG compression feature which allows smoother control of color data reduction with similar compression effect *without* the destructing color subsampling!
This new kind of compression configuration will use adaptive color quantization with always 1x1 (no) subsampling, thus removing the need for other subsampling settings altogether.



You can easily check the actual subsampling setting of a given image by loading it into Jpegcrop and turning on the "View/Block Grid" option (just hit the grid-button in the toolbar).

Block size (MCU size) = 16x16 pixel.
This is the actual setting used in SIGMA Photo Pro.

Block size (MCU size) = 16x8 pixel.
This setting is used in almost all other straight out-of-camera JPEG images.

Block size (MCU size) = 8x16 pixel.
This setting results from lossless rotation of 2x1 JPEG images.

Block size (MCU size) = 8x8 pixel.
This is the setting used in higher quality Photoshop JPEG images.

2.)   (added on Sunday, Mar 02, 2003)

Looking in the Canon SLR Talk Forum after Canons new EOS 10D entry I came across a very familiar report about JPEG compression artifacts:

Image sample courtesy Noel Carboni from Canon SLR Talk Forum,
based upon sample images

I didn't realize until now that the limited color subsampling would also noticeably hurt mosaic sensor images due to their inherent reduced color resolution (especially in Red and Blue).
Now it appears that the limited color subsampling of current digital cameras JPEG output begins to strike the conventional mosaic sensor users, too.

Time to rethink the JPEG compression configuration for the traditional digital camera makers!

The user report clearly states that the observed effect is due to camera-specific JPEG compression and was noticed similarly in other high-end cameras. This observation was confirmed by other users:

"I have to say it's disappointing to see that Canon, for all their "Digic" and software improvement efforts, allows such an obvious error in their JPEG compression logic to continue to be propagated into their latest products."
So here is my word to Canon and other digital camera makers:
I strongly advice to move away from suboptimal JPEG compression configuration, namely the 2x1 color subsampling setting!

Use a 1x1 setting for higher quality modes instead!
Note: I'm currently developing a new JPEG compression feature which allows smoother control of color data reduction with similar compression effect *without* the destructing color subsampling!
This new kind of compression configuration will use adaptive color quantization with always 1x1 (no) subsampling, thus removing the need for other subsampling settings altogether.