Bfconvert specify JPEG quality

How do I specify the JPEG quality?

bfconvert -compression JPEG /path/to/input output-lzw.tiff

I’m afraid that there isn’t yet an option to do so but I’ll note on [gh] setting JPEG compression quality with bfconvert because it’s good when we know that many people are interested in the same feature. If you’d like to add it yourself then of course we can try to offer some guidance and comment. In the meantime it might be that one of bfconvert’s other codecs offered by -compression might happen to better fit the output you’re wanting.

What is the default JPEG compression quality and the default Color subsampling mode in the OME Tiff writer used by bfconvert and other applications?
(I could not find the settings in the bioformats/ome codecs code :confused:)

Independent from the strategy, I think supporting the configuration of JPEG quality and color subsampling mode would be an improvement.

I could imagine an option to define such settings in a config file (to be place maybe inside the corresponding jar).
‘Secondary’ applications using the OME Tiff writer could benefit from such a general configuration without explicit supporting a quality and subsampling setup and without the need for modifications in ‘secondary’ codes.

The default option for JPEG compression will use the javax.imagio implementation (JPEGImageWriter), the options can be found in JPEGImageWriterParam. This would have a default quality setting of 0.75 and the subsampling looks to be 1x1.

1 Like

Thank you @dgault for your answer.

Regarding the subsampling there is probably a misunderstanding.
I was asking for the chroma subsampling.

As a test I have exported a RGB image (2000x1946 pixel) as Jpeg file with FIJI\Bio-Formats.

The metadata (displayed with the ExifTool) shows that the chroma subsampling of the Jpeg image from Bio-Formats (8bit_RGB_saved_with_BioFormats.jpg) is

  • YCbCrSubsampling YCbCr4:2:0 (2 2)

As a comparison I have saved the test image with ImageJ as Jpeg image with quality=100 (8bit_RGB_saved_with_IJ_100%.jpg).
The chroma subsampling of this file is

  • YCbCrSubsampling YCbCr4:4:4 (1 1)

I have calculated the difference of the R|G|B channels between the test image and the Jpeg compressed images. The intensity sum are for R|G|B:

8bit_RGB_saved_with_BioFormats.jpg :  16420010	10616327	12694915
8bit_RGB_saved_with_IJ_100%.jpg    :   1871819	 1297017	 2397909

The distribution of the pixels differences can be seen in the following image:

The image saved with ImageJ with quality=75 (8bit_RGB_saved_with_IJ_75%.jpg) is identical to 8bit_RGB_saved_with_BioFormats.jpg. The pixel values are identical and YCbCrSubsampling = YCbCr4:2:0 (2 2).

The quality of the image saved with quality=100 and YCbCr4:4:4 (1 1) is much better then when saved with quality=75 and YCbCr4:2:0 (2 2).

The pixel differences between original and compressed image are in a much smaller range (1…4).

The quality of the Jpeg compressed image not only depends on the quality setting but also on the chroma subsampling.

I think it would be a real improvement to support the configuration of quality and chroma sampling in Bio-Formats in the future.