views:

716

answers:

6

Hi!

I would like to find a way to take JPEG (or GIF/PNG) images and reduce the amount of colors to e.g. 20. Could someone recommend some library or other reference? Also source codes in other languages are welcome.

A: 

Look for algorithms on color quantization, especially median cut. You'll find many examples with those keywords. Libraries to do this for you include ImageMagick which has bindings for many languages. JMagick is the Java flavor.

jjrv
+2  A: 

Take a look at the Java Advanced Imaging API. There are a number of algorithms implemented in that API for doing color reduction.

rcreswick
A: 

Take a look at the image filters at http://www.jhlabs.com/ip/filters/index.html. The QuantizeFilter seems to do what you want.

Andreas Holstenson
+1  A: 

JAI (Java Advanced Imaging API) would do the work but it has some drawbacks.

The API is far from being easy to use, especially if you care about memory footprint...

IMHO Java is not the best platform for imaging tasks. You might try ImageMagick, a wonderful command line tool, used by popular sites such as Flickr. You can integrate ImageMagick in your java application using the command line (Runtime.exec()) or Jmagick which a java bridge to ImageMagick

Alexandre Victoor
A: 

This seems like a simple implementation in java, based on ImageMagick:

http://gurge.com/amd/java/quantize/index.html

tfinniga
A: 

JAI API is the way to go. WIth today's JVM performance is very close to assembler code. I know I've done it.