Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -quality option to bfconvert #4171

Merged
merged 3 commits into from
Apr 15, 2024
Merged

Conversation

melissalinkert
Copy link
Member

Fixes #3370.

Builds on work in ome/ome-codecs#26 to pass a quality value (0.0 to 1.0) through to the JPEG codec. This can be tested by comparing conversions with different quality values, e.g.:

$ bfconvert -compression JPEG -quality 0.1 test.fake test_10percent.tiff
$ bfconvert -compression JPEG -quality 0.5 test.fake test_50percent.tiff
$ bfconvert -compression JPEG -quality 1.0 test.fake test_100percent.tiff

and different output formats (TIFF, OME-TIFF, DICOM). The output file size should increase as the quality increases.

Note that the JPEG writer does not currently make use of this, as it bypasses the JPEGCodec API.

Adding to 7.3.0 for now, but we can also push to 8.0.0 if this seems more suited to a major version.

This primarily affects JPEG compression with TIFF, OME-TIFF, and DICOM output.

Fixes ome#3370.
In particular, this will make use of any provided quality value.
@melissalinkert melissalinkert added this to the 7.3.0 milestone Mar 25, 2024
@sbesson sbesson self-requested a review March 29, 2024 16:03
Copy link
Member

@sbesson sbesson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the HEAD of the branch, executing the following conversion commands

./tools/bfconvert -compression JPEG test.fake test_jpg.tiff
./tools/bfconvert -compression JPEG test.fake test_jpg.ome.tiff
./tools/bfconvert -compression JPEG test.fake test_jpg.dcm
./tools/bfconvert -compression "JPEG-2000 Lossy" test.fake test_j2k.tiff
./tools/bfconvert -compression "JPEG-2000 Lossy" test.fake test_j2k.ome.tiff
./tools/bfconvert -compression JPEG -quality 0.1 test.fake test_jpg_10percent.tiff
./tools/bfconvert -compression JPEG -quality 0.5 test.fake test_jpg_50percent.tiff
./tools/bfconvert -compression JPEG -quality 1.0 test.fake test_jpg_100percent.tiff
./tools/bfconvert -compression JPEG -quality 0.1 test.fake test_jpg_10percent.ome.tiff
./tools/bfconvert -compression JPEG -quality 0.5 test.fake test_jpg_50percent.ome.tiff
./tools/bfconvert -compression JPEG -quality 1.0 test.fake test_jpg_100percent.ome.tiff
./tools/bfconvert -compression JPEG -quality 0.1 test.fake test_jpg_10percent.dcm
./tools/bfconvert -compression JPEG -quality 0.5 test.fake test_jpg_50percent.dcm
./tools/bfconvert -compression "JPEG-2000 Lossy" -quality 5.0 test.fake test_j2k_quality5.tiff
./tools/bfconvert -compression "JPEG-2000 Lossy" -quality 100.0 test.fake test_j2k_quality100.tiff
./tools/bfconvert -compression "JPEG-2000 Lossy" -quality 5.0 test.fake test_j2k_quality5.ome.tiff
./tools/bfconvert -compression "JPEG-2000 Lossy" -quality 100.0 test.fake test_j2k_quality100.ome.tiff

produced the following output

-rw-r--r--  1 sbesson  staff   132K 10 Apr 08:59 test_j2k.ome.tiff
-rw-r--r--  1 sbesson  staff   131K 10 Apr 08:59 test_j2k.tiff
-rw-r--r--  1 sbesson  staff   132K 10 Apr 08:59 test_j2k_quality100.ome.tiff
-rw-r--r--  1 sbesson  staff   131K 10 Apr 08:59 test_j2k_quality100.tiff
-rw-r--r--  1 sbesson  staff   129K 10 Apr 08:59 test_j2k_quality5.ome.tiff
-rw-r--r--  1 sbesson  staff   128K 10 Apr 08:59 test_j2k_quality5.tiff
-rw-r--r--  1 sbesson  staff    10K 10 Apr 08:59 test_jpg.dcm
-rw-r--r--  1 sbesson  staff   231K 10 Apr 08:59 test_jpg.ome.tiff
-rw-r--r--  1 sbesson  staff   230K 10 Apr 08:59 test_jpg.tiff
-rw-r--r--  1 sbesson  staff   363K 10 Apr 08:59 test_jpg_100percent.ome.tiff
-rw-r--r--  1 sbesson  staff   362K 10 Apr 08:59 test_jpg_100percent.tiff
-rw-r--r--  1 sbesson  staff   8.6K 10 Apr 08:59 test_jpg_10percent.dcm
-rw-r--r--  1 sbesson  staff   219K 10 Apr 08:59 test_jpg_10percent.ome.tiff
-rw-r--r--  1 sbesson  staff   218K 10 Apr 08:59 test_jpg_10percent.tiff
-rw-r--r--  1 sbesson  staff   9.7K 10 Apr 08:59 test_jpg_50percent.dcm
-rw-r--r--  1 sbesson  staff   227K 10 Apr 08:59 test_jpg_50percent.ome.tiff
-rw-r--r--  1 sbesson  staff   226K 10 Apr 08:59 test_jpg_50percent.tiff

For both JPEG and JPEG-2000 lossy when the target format supports it, the quality level passed to the utility is properly respected.

Additionally, the DICOM writer now allows to set options when using JPEG compression. As mentioned on Monday, the only outstanding todo is probably to document the new option in https://github.com/ome/bio-formats-documentation for the upcoming 7.3.0 release

melissalinkert added a commit to melissalinkert/bio-formats-documentation that referenced this pull request Apr 10, 2024
@dgault dgault merged commit 2a1c8b8 into ome:develop Apr 15, 2024
18 checks passed
@melissalinkert melissalinkert deleted the bfconvert-quality branch September 6, 2024 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

setting JPEG compression quality with bfconvert
3 participants