问题
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.
回答1:
Take a look at the Java Advanced Imaging API. There are a number of algorithms implemented in that API for doing color reduction.
回答2:
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
回答3:
This seems like a simple implementation in java, based on ImageMagick:
http://gurge.com/amd/java/quantize/index.html
回答4:
Take a look at the image filters at http://www.jhlabs.com/ip/filters/index.html. The QuantizeFilter seems to do what you want.
回答5:
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.
回答6:
JAI API is the way to go. WIth today's JVM performance is very close to assembler code. I know I've done it.
来源:https://stackoverflow.com/questions/87062/color-reduction-in-java