5

I'm using the NeuQuant quantization algorithm (https://code.google.com/p/android-gif-project/source/browse/trunk/GIFproject1/src/com/ui/NeuQuant.java?r=5) to reduce a jpeg to a 256-color image but it's very slow (~1 second for a 320x240 image, ~3 seconds for a 640x480). Even with multiple threads I can't get processing time to a decent level (ideally in the 100ms per image range).

Does anyone know a faster algorithm to reduce the color palette of an image to 256 colors?

Cat
  • 7,042
  • 8
  • 34
  • 36

2 Answers2

4

Extracting 256 colors is somewhat of an edge case, but you should have a look at Median Cut Quantization. Here is an implementation : github link
Another option is octree.
You should really bench both solutions though and look for ways to improve them.

Additionally, running the algorithm through a RenderScript might allow you to speed it up a lot.

Teovald
  • 4,369
  • 4
  • 26
  • 45
2

Fast pairwise nearest neighbor based algorithm producing high quality 256 color 8 bit PNG images minimizing color loss for photo having red lips and supports 256 or less colors with transparency. The time complexity of the method is O(N log N).

The demo android project is written in Java, using a button click to convert the sample image to 256 colors directly. github link

demo app screenshot

Miller Cy Chan
  • 897
  • 9
  • 19