zengzhu / nQuantCpp

nQuantCpp includes top 6 color quantization algorithms for visual c++ producing high quality optimized images.

Home Page:http://imgv64.rf.gd

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nQuantCpp

nQuantCpp includes top 6 color quantization algorithms for visual c++ producing high quality optimized images. I enhance each of the algorithms to support semi transparent images.

Divisive hierarchical clustering algorithm utilizes the commonly used binary splitting strategy along with several carefully selected heuristics that ensure a good balance between effectiveness and efficiency. Fast pairwise nearest neighbor based algorithm is log linear and considerably faster than optimal thresholding, it is applicable in real-time image processing applications. NeuQuant Neural-Net Quantization Algorithm is a self-organizing Kohonen neural network for quantizing colour graphics images. Xialoin Wu's fast optimal color quantizer, which is one of the most effective color quantization methods, provides excellent results. Efficient, Edge-Aware, Combined Color Quantization and Dithering is a novel algorithm to simultaneously accomplish color quantization and dithering of images. Spatial color quantization is a novel technique for palette selection and dithering with a simple perceptual model of human vision to produce superior results for many types of images.

Fast pairwise nearest neighbor based algorithm minimized color loss for photo having red lips and supports 256 or less colors. NeuQuant Neural-Net Quantization Algorithm produces smooth photo quantization especially for natual landscape photo supports image reduction to 64 or more colors. Xialoin Wu's fast optimal color quantizer supports image reduction to 64 or more colors. Efficient, Edge-Aware, Combined Color Quantization and Dithering, Spatial color quantization supports 64 or less colors. nQuantCpp also provides a command line wrapper in case you want to use it from the command line.

Either download nQuantCpp from this site or add it to your Visual Studio project seamlessly. PNG is useful because it's the only widely supported format which can store partially transparent images. The format uses compression, but the files can still be large. Use Color quantization algorithms can be chosen by command line since version 1.10 using the /a algorithm. Only png can support semi transparent image and desired color depth. Gif can ensure the number of colors for the converted image is 256 or less. Bmp does support desired color depth. Jpg only supports 24-bit image format.

Here some examples of output:

Original image

Reduced to 256 colors by Divisive hierarchical clustering algorithm

Reduced to 256 colors by NeuQuant Neural-Net Quantization Algorithm

Reduced to 16 colors by Fast pairwise nearest neighbor based algorithm

Reduced to 16 colors by Xialoin Wu's fast optimal color Quantization Algorithm


Original photo

Reduced to 256 colors by NeuQuant Neural-Net Quantization Algorithm

Reduced to 256 colors by Fast pairwise nearest neighbor based algorithm


Original image

Fast pairwise nearest neighbor based algorithm with CIELAB color space with 16 colors
High quality and fast

Fast pairwise nearest neighbor based algorithm with CIELAB color space with 16 colors

Efficient, Edge-Aware, Combined Color Quantization and Dithering with 16 colors
Higher quality for 32 or less colors but slower
Efficient, Edge-Aware, Combined Color Quantization and Dithering with 16 colors

Spatial color quantization with 16 colors
Higher quality for 32 or less colors but the slowest
Spatial color quantization with 16 colors

If you are using the command line. Assuming you are in the same directory as nQuantCpp.exe, you would enter: nQuantCpp yourImage.jpg /m 16

nQuantCpp will quantize yourImage.jpg and create yourImage-PNNLABquant16.png in the same directory.

The readers can see coding of the error diffusion and dithering are quite similar among the above quantization algorithms. Each algorithm has its own advantages. I share the source of color quantization to invite further discussion and improvements. Such source code are written in C++ to gain best performance. It is readable and convertible to c#, java, or javascript. Welcome for C++ experts for further improvement or provide color quantization algorithms better than the above algorithms. Please use issues to track ideas, enhancements, tasks, or bugs for work on GitHub.

About

nQuantCpp includes top 6 color quantization algorithms for visual c++ producing high quality optimized images.

http://imgv64.rf.gd

License:GNU General Public License v3.0


Languages

Language:C++ 99.9%Language:C 0.1%