Pngnq is a tool for quantizing PNG images in RGBA format.
Pngnq is an adaptation by Stuart Coyle of Greg Roelf's pnqquant using Anthony Dekker's neuquant algorithm.
Pngnq exists because I needed a lot (several thousand) of png images in RGBA format to be quantized. After some searching, the only tool I could find that worked for RGBA was pngquant. I tried pngquant but found that the median cut algorithm that it uses, with or without dithering, gave inferior looking results to the neuquant algorithm. You can see the difference demonstrated on the neuquant page.
Pngnq was written to fulfill the specific needs of the small project I was working on, and as such does not have all the functionality one could want. It is developing though, I have recently (June 2006) come back to it to add functionality and make it more useful in various situations. It will stay as a command line quantization tool rather than evolve into a full compression process as I'd rather keep the program as performing one specific function. If optimal compression is needed one can use something like pngcrush after quantization.
I use Greg Roelf's png reading and writing code unchanged for the most part. The pngnq source code includes neuquant32, which is an extension of Anthony Dekker's neuquant. This has been modified to allow it to handle 4 channels of pixel data and to vary the number of colors quantized to. Thanks go to these people for developing such useful code and making it open source.
The quantizer is fairly slow compared to median cut or octree methods. It is most certainly faster than Spatial Quantization techniques. It is limited mostly to off-line uses rather than real time image delivery. Even so, I am sure Moore's Law will make that statement false at some short time in the future. I've not run any comprehensive speed comparisons with other algorithms.
The speed of the algorithm can be increased by increasing the sample factor ( -s option ). The sample factor determines what fraction of pixels are examined by the algorithm.
Pngnq seems to work best when quantizing to a fairly large number of colors (>=64). This mainly a result of the visible edges due to the lack of dithering. The amount of compression of images gained is determined largely by the level of quantization. Using a tool like pngcrush to further process these images results in slightly smaller images than with methods that dither the image. This is probably due to the lack of high frequency data in the non-dithered images.
I have run tests on the measured difference between quantized and unquantized images using pngnq, pngquant and scolorq. The error measure used is the Euclidian distance in RGBA space between pixels in the quantized and unquantized images. These have shown that the neuquant algorithm performs better than the median cut for most images, I suspect though that each reach close to the . Since reading Puzicha et. al. and running some tests, I have decided that this may not be the best measure of percieved difference in images. A better test of “percieved” image distance is in development.
I've run some comparisons here: Sample quantized images.
I have tested pngnq with these test images. No errors occur except in the deliberately corrupt test images, in which case the image loading correctly reports the corrupt image and the quantizer carries on as normal.
Things that pngnq needs work on:
I want to change the error measure to use CIE u' v' color space and see if results are visually better. Or perhaps add a perception filter model.
Limited image input formats. I am not doing much checking on the image pixel depth etc.
I might get around to a Windows port...one day. Maybe someone else will be kind enough to do it.
There seems to be few image editing programs that correctly deal with paletted RGBA png images. This is a pity since the alpha channel is so useful on the web, when browsers support it correctly. The only other quantization program I have found that does this is pngquant.
A plug in for GIMP (Problematic since GIMP does not display RGBA paletted mode although it loads and saves them alright.)
An ImageMagick library extension to do RGBA quantization.
17th June 2006. Sample Factor Bug. I have found a bug which I inadvertently introduced into the Neuquant code which causes the neuquant algorithm to scan only 3/4 of the pixels. The bug effectively causes the sample factor to be 25% too large. Whilst this gives acceptable results the image quality is improved when all pixels are scanned. The patch for this bug is available for version 0.3 and version 0.4.0. Version 0.4.1 and 0.3.1 have been patched.
0.4 Second release.
Cleaned up the code a and added some comments.
Added -n option to specify how many colours to quantize to. This can be from 2 to 256. and defualts to 256.
Added -h option to display help. Compiled Mac, Linux AMD64 and BSD binaries.
Added -V option to display version information.
Created pngcomp, a test program to compare images for testing purposes.
0.3. First release June 2004.
Please feel free to contact me with comments, contributions, patches and bug reports via: stuart AT cybertherial DOT com
Current Version is pngnq-0.4.1
This product includes software developed by Greg Roelofs and contributors for the book, "PNG: The Definitive Guide," published by O'Reilly and Associates.Home page