issue applying LZW compression

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
eengland
Posts: 2
Joined: 2016-12-09T10:00:07-07:00
Authentication code: 1151

issue applying LZW compression

Post 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!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: issue applying LZW compression

Post 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?
eengland
Posts: 2
Joined: 2016-12-09T10:00:07-07:00
Authentication code: 1151

Re: issue applying LZW compression

Post by eengland »

User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: issue applying LZW compression

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: issue applying LZW compression

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply