Use ZIP (Deflate) instead of LZW for TIFF exports (#238)#453
Merged
Conversation
…horizontal predictor tifffile.imwrite calls in the export and scan-capture paths now use compression='zlib' + predictor=True. Deflate/ZIP typically yields 15-25% smaller files than LZW for 16-bit image data. Update test helpers to match the new default — no test assertions depend on the specific codec, so this is a consistency change. Closes marcinz606#238
|
Yes please. LZW actually made the tiffs larger than plain uncompressed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #238 -- 16-bit TIFF exports are needlessly large because LZW compression performs poorly on photographic 16-bit data, often barely beating uncompressed.
Root cause
tifffile.imwritein the export and scan-capture codepaths hardcodedcompression="lzw". LZW is a byte-oriented algorithm designed for 8-bit palette images -- it does not exploit horizontal redundancy in 16-bit continuous-tone data, so 16-bit RGB TIFFs compress poorly.Fix
Replace
compression="lzw"withcompression="zlib"+predictor=Truein all three TIFF-writing call sites.predictor=Trueenables horizontal differencing (TIFF Predictor 2), which stores pixel-to-pixel deltas instead of absolute values. Combined with Adobe Deflate (ZIP), this yields ~20-35% smaller files for 16-bit photographic content.Both
tifffileandimagecodecsare already project dependencies -- no new imports needed.Files changed:
negpy/services/rendering/image_processor.py-- export TIFFnegpy/services/scanning/writer.py-- scan capture RGB + IR sidecartests/test_export_service.py-- test helper consistencytests/metadata/test_writer.py-- test helper consistencyVerification
Compressiontag (8 = Adobe Deflate) andPredictortag (2 = horizontal differencing)