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

[Feature Request] Image compression for ome.tiff files #87

Closed
mfs4rd opened this issue Jan 27, 2025 · 5 comments · Fixed by #88
Closed

[Feature Request] Image compression for ome.tiff files #87

mfs4rd opened this issue Jan 27, 2025 · 5 comments · Fixed by #88
Labels
enhancement New feature or request

Comments

@mfs4rd
Copy link

mfs4rd commented Jan 27, 2025

Feature Description

Include the ability to use image compression when saving ome.tiff files by providing additional input arguments in OmeTiffWriter().save() that are passed on to tifffile.imsave() or tifffile.imwrite(). This feature could also be implemented for other file formats if possible.

Use Case

Using image compression to save image segmentation or intermediate images used for analysis could help to reduce storage space on hard drives and network storage. Segmentation images are often sparse and comprised of large regions of identical pixel values, making them easy to compress to a substantial degree with minimal loss. Likewise raw images can also be compressed in scenarios where loss is a negligible concern.

Solution

Image compression parameters already exist in tifffile, which OmeTiffWriter() wraps. We need only provide these same arguments as optional parameters to OmeTiffWriter().save() that are passed down to tifffile.imwrite() when writing the image to disk, and include relevant documentation explaining options to users. Additional messaging to users about this feature to help in adopting it as standard practice can be discussed.

@mfs4rd mfs4rd added the enhancement New feature or request label Jan 27, 2025
@evamaxfield
Copy link
Contributor

Hey @mfs4rd!

We do already use image compression in OME TIFF writing: https://github.com/bioio-devs/bioio/blob/main/bioio/writers/ome_tiff_writer.py#L298

Are you asking to allow users to choose which compression to use?

I don't personally see a problem with that cc @toloudis. Seems like a simple parameter addition

@toloudis
Copy link
Contributor

we have another issue for ome-zarr also I think : #36

@mfs4rd
Copy link
Author

mfs4rd commented Jan 27, 2025

@evamaxfield Derek has recently been using zlib for compression for some of his segmentations as such

tiff.imsave(output_path, cp.asnumpy(img), photometric='minisblack', compression='zlib',compressionargs={'level': 8})

He claims it gave him a 345:1 compression on segmentations that he has been working with.

I don't know how this compares to the method currently used but it might be worth giving this option to users.

@toloudis
Copy link
Contributor

toloudis commented Jan 30, 2025

we absolutely should provide this as an optional parameter for tiff as well. and consider changing the default if it makes sense to. I suspect that adobe deflate and zlib will be similar for segmentations but who knows!

@evamaxfield
Copy link
Contributor

I have opened a PR to move the compression from hard coded to a parameter on the writer. Note @mfs4rd during my quick investigation of tifffile, I found that zlib is simply a different name for our default compression scheme of "adobe_deflate": https://github.com/cgohlke/tifffile/blob/master/tifffile/tifffile.py#L1941

PR will still open up the option for people to parameterize the compression scheme but I am curious if y'all are seeing a difference in file size on disk between the two schemes and the docstring hasn't been updated on tifffile's side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants