Page 1 of 1

issue applying LZW compression

Posted: 2016-12-09T10:50:13-07:00
by eengland
Hello, I am new to ImageMagick and am using it primarily for converting images from NEF. I am having trouble applying LZW compression when converting to TIFF. The file size is actually getting bigger when I apply LZW compression, as opposed to just converting to TIFF without LZW.

I am using:
ImageMagick version: Version: ImageMagick 7.0.3-9 Q16 x86_64 2016-12-8 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP
Delegates (built-in): bzlib fontconfig freetype jbig jng jpeg lzma pangocairo png tiff x xml zlib

LIBTIFF version 4.0.3

Code: Select all

 convert [pathtofile].nef –compress LZW [outputfile].tiff 
the 14 MB NEF is converted to a 61 MB TIFF. When I look at the file in ExifTool, it says there is LZW compression.

Code: Select all

 convert [pathtofile].nef [outputfile].tiff 
the 14.0 MB NEF is converted to a 53 MB TIFF.

Any ideas would be appreciated! Thank you!

Re: issue applying LZW compression

Posted: 2016-12-09T11:01:13-07:00
by fmw42
Post an example NEF image to some place such as dropbox.com and put the URL here, so we can test with it.

What is your platform?

Re: issue applying LZW compression

Posted: 2016-12-09T11:18:08-07:00
by eengland

Re: issue applying LZW compression

Posted: 2016-12-09T12:03:17-07:00
by fmw42
According to IM identify -verbose, your 16-bit per channel NEF file (48-bits) with zip compression has Filesize: 54.38MB

Using IM 6.9.6.7 Q16 Mac OSX:

Code: Select all

convert RWK5836.NEF -compress none RWK5836_none.tif
convert RWK5836.NEF -compress lzw RWK5836_lzw.tif
convert RWK5836.NEF -compress zip RWK5836_zip.tif
identify RWK5836.NEF RWK5836_none.tif RWK5836_lzw.tif RWK5836_zip.tif
RWK5836.NEF=>/var/tmp/magick-2465nmT5RIDjXb6.png NEF 4308x2860 4308x2860+0+0 16-bit sRGB 54.38MB 0.020u 0:00.020
RWK5836_none.tif TIFF 4308x2860 4308x2860+0+0 16-bit sRGB 73.93MB 0.000u 0:00.009
RWK5836_lzw.tif TIFF 4308x2860 4308x2860+0+0 16-bit sRGB 64.92MB 0.000u 0:00.009
RWK5836_zip.tif TIFF 4308x2860 4308x2860+0+0 16-bit sRGB 55.75MB 0.000u 0:00.000


Using IM 7.0.3.9 Q16 Mac OSX:

Code: Select all

magick RWK5836.NEF -compress none RWK5836_none.tif
magick RWK5836.NEF -compress lzw RWK5836_lzw.tif
magick RWK5836.NEF -compress zip RWK5836_zip.tif
magick identify RWK5836.NEF RWK5836_none.tif RWK5836_lzw.tif RWK5836_zip.tif
RWK5836.NEF=>/var/tmp/magick-2465nmT5RIDjXb6.png NEF 4308x2860 4308x2860+0+0 16-bit sRGB 54.38MB 0.020u 0:00.020
RWK5836_none.tif TIFF 4308x2860 4308x2860+0+0 16-bit sRGB 73.93MB 0.000u 0:00.009
RWK5836_lzw.tif TIFF 4308x2860 4308x2860+0+0 16-bit sRGB 64.92MB 0.000u 0:00.009
RWK5836_zip.tif TIFF 4308x2860 4308x2860+0+0 16-bit sRGB 55.75MB 0.000u 0:00.000

So my results do not show that lzw is larger than none!

According to EXIFTOOL, your NEF file is - FileSize: 13999013


Looking at the identify, it appears that IM is converting NEF to PNG to get filesize.

I am not an expert on NEF, so cannot say what is going on or how NEF is compressed.

Re: issue applying LZW compression

Posted: 2016-12-09T12:31:45-07:00
by snibgo
NEF compression is proprietary to Nikon, and can be either lossy or lossless. The lossless compression gives smaller sizes than any method IM has. (I guess Nikon have a bigger budget.)

If LZW compression makes a result that is larger than no compression, the solution is: don't use LZW compression.

Personally, I use Zip compression for tiff files from NEF.