2008.11.21 16:50 "[Tiff] 24 bit Color to 8 bit Palettized Conversion Utility (tiffcp enhancement/variation?)", by Kevin Myers

2008.11.21 17:29 "Re: [Tiff] 24 bit Color to 8 bit Palettized Conversion Utility (tiffcp enhancement/variation?)", by Frank Warmerdam

I'm looking for a command line utility with a version that runs under Windows which can convert a 24 bit color TIFF image to an 8 bit palettized TIFF image. But I need something that works similar to tiffcp that does the processing without loading the whole image into memory at once. I am aware of the very useful GraphicsMagick and ImageMagick utilities, but they both load the whole image into memory, which can be quite slow and somewhat problematic for some of the extremely large images that I work with.

Kevin,

At the risk of carrying along a lot of extra baggage, you could use the rgb2pct.py script that is part of GDAL. At it's simpliest you could do:

  rgb2pct rgb.tif paletted.tif

You can also specify the number of colors to use:

  rgb2pct rgb.tif paletted.tif -n 100

It processes the image in two passes - one to build an image histogram for selecting a good palette, and a second pass to actually process the image. It should never keep more than a few scanlines in memory at a time.

The latest FWTools for Windows includes this script (available from the FWTools command line). Of course FWTools includes a lot of "stuff" and I don't claim this is lightest solution for the problem.

   http://fwtools.maptools.org/
   http://www.gdal.org/rgb2pct.html

The underlying functions in GDAL are documented at:

   http://www.gdal.org/gdal__alg_8h.html#61e48f88c3b4b3cf7957c61dc7bd1ead
   http://www.gdal.org/gdal__alg_8h.html#284dbcc27295b7e678b1f7d4fa1506cb

And the code is:
   http://svn.osgeo.org/gdal/trunk/gdal/alg/gdaldither.cpp
   http://svn.osgeo.org/gdal/trunk/gdal/alg/gdalmediancut.cpp

I'm surprised there isn't a similar libtiff utility but I can't seem to find one. I assume I derived my code from libtiff.

Best regards,
--
---------------------------------------+--------------------------------------

I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam@pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam

and watch the world go round - Rush    | Geospatial Programmer for Rent