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

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

Hi Bob,

Actually the images that I am wanting to perform this processing on are already in a sense "color reduced". They truly contain only a very limited number of colors, (unlike the scanned images that you and I were discussing offline previously). So, all I really need is a program that can scan through the image identifying each color that actually exists, add those colors to a palette, and output the new image using the palettized values. So, step 2 from your list below is just a one to one mapping in this case. Also, since each color could be directly added to the palette on the fly as it is encountered, it would not be necessary to scan the image twice in this special case where the actual number of colors in the image (e.g. 16) is (much) less than the number of colors that the palette can theoretically accomodate (e.g. 256).

Don't know whether there is anything out there that is specifically designed to accomodate this special secnario, but that's what I would like, at least in theory. Also, as you have surmised, some of my problems using GraphicsMagick/Imagemagick DO occur because the images are too large to load into available RAM.

Regards,

Kevin M.

Subject: Re: [Tiff] 24 bit Color to 8 bit Palettized Conversion Utility (tiffcp enhancement/variation?)

Did you try VIPS? VIPS is able to accomplish many things without loading the whole image into memory and it is usually quite fast. I don't know if its color reduction works without loading the whole image though since that would require a several-pass algorithm.

Actually, from looking at the VIPS documentation, I am not finding an algorithm for color reduction at all. Maybe it does not exist. :-( Still, a programmer could use the VIPS API to develop a muti-pass color reduction algorithm.

In order to color reduce you need to

  1. Build a color tree / histogram of the existing colors in the image. This requires reading all the image pixels.
  2. Evaluate the color tree and build a colormap which best approximates it.
  3. Re-read the image pixels and generate colormap indexes which best approximate the image given the colormap which was selected. This may include dithering.

So it can be seen that to color reduce an image using the color tree / histogram method requires reading the pixels at least twice. RAM is now about 10,000 times faster than disk so reading from disk multiple times is prohibitive unless the decoded image can not fit in RAM.