0

I was surprized to see that the tiff written in matlab with lzw compression (62.5 Mo) was 1.7 times larger than the same file, opened in gimp, and exported to a new file, with lzw compression (36.6 Mo). Both seems to use libTiff 4.0 for image writing

I verified, the two files contain the exact same pixel value when opened in matlab, so no loosy compression happening.

The only difference I can found between the two files, using the identify -verbose command, the only difference is:

Gimp:

  Compression: LZW
  Properties:
    tiff:document: /.../gimp.tiff
    tiff:rows-per-strip: 128
    tiff:software: GIMP 2.10.5
  Artifacts:
    filename: gimp.tiff
  Filesize: 36.55MB
  Number pixels: 24.23M

matlab:

  Compression: LZW
  Properties:
    ...
    tiff:rows-per-strip: 62
  Artifacts:
    filename: matlab.tiff
  Filesize: 62.83MB
  Number pixels: 24.23M

So the only difference seems to be tiff:rows-per-strip (128 vs 62), and the presence of tiff:document tag in the gimp file. I get the similar differences using Tiff() in matlab.

I don't really see how these could cause such difference in file size...

But my real question is how to write such small file size in matlab ?

Thanks for any help!

beesleep
  • 1,322
  • 8
  • 18
  • Are you sure both use LZW compression? – Cris Luengo May 18 '20 at 22:47
  • yep. I've added the relevant line of the identify command – beesleep May 18 '20 at 23:06
  • 1
    Maybe GIMP is using a [predictor](https://www.awaresystems.be/imaging/tiff/tifftags/predictor.html)? – cgohlke May 18 '20 at 23:12
  • Interesting suggestion! Do you know how can I check that ? – beesleep May 18 '20 at 23:16
  • 1
    Try `tiffinfo` included with libtiff or [tifffile](https://pypi.org/project/tifffile/) to check the value of the `Predictor` tag, e.g. `python -c"from tifffile import TiffFile;print(TiffFile('gimp.tiff').pages[0].tags['Predictor'])` – cgohlke May 18 '20 at 23:22
  • Thanks for the help! You were right! A predictor tag is defined for the gimp image, but not for the matlab image. I haven't found any way to set this tag on matlab though... Any idea ? – beesleep May 18 '20 at 23:30
  • After some basic check to the matlab tiff source code, doesn't seems possible without hacky stuf. Do you want to write an answer, I'll accept it! – beesleep May 18 '20 at 23:34

0 Answers0