JIU 0.12.0 Homepage

net.sourceforge.jiu.color.quantization
Class OctreeColorQuantizer

java.lang.Object
  extended bynet.sourceforge.jiu.ops.Operation
      extended bynet.sourceforge.jiu.ops.ImageToImageOperation
          extended bynet.sourceforge.jiu.color.quantization.OctreeColorQuantizer
All Implemented Interfaces:
RGBIndex, RGBQuantizer

public class OctreeColorQuantizer
extends ImageToImageOperation
implements RGBIndex, RGBQuantizer

Performs the octree color quantization algorithm for a given RGB truecolor image. The quality is usually somewhat inferior to the results of MedianCutQuantizer. Note that you can improve the quality by applying a dithering algorithm. See ErrorDiffusionDithering.

Usage example

This reduces some RGB24Image image to a 16 color paletted image:
 MemoryRGB24Image image = ...; // initialize
 OctreeColorQuantizer ocq = new OctreeColorQuantizer();
 ocq.setInputImage(image);
 ocq.setPaletteSize(16);
 ocq.process();
 PixelImage quantizedImage = ocq.getOutputImage();
 

Credits

Since:
0.6.0
Author:
Marco Schmidt

Field Summary
static int DEFAULT_PALETTE_SIZE
          The default number of colors in the palette.
 
Fields inherited from interface net.sourceforge.jiu.data.RGBIndex
INDEX_BLUE, INDEX_GREEN, INDEX_RED
 
Constructor Summary
OctreeColorQuantizer()
           
 
Method Summary
 Palette createPalette()
          Return a Palette object with the list of colors to be used in the quantization process.
 void init()
          Creates an octree and prepares this quantizer so that colors can be mapped to palette index values.
 int map(int[] origRgb, int[] quantizedRgb)
          Maps an RGB color origRgb to one of the colors in the color map; that color will be written to quantizedRgb and its palette index will be returned.
 void process()
          Initializes an octree, reduces it have as many leaves (or less) as the desired palette size and maps the original image to the newly-created palette.
 void setPaletteSize(int newPaletteSize)
           
 
Methods inherited from class net.sourceforge.jiu.ops.ImageToImageOperation
canInputAndOutputBeEqual, ensureImagesHaveSameResolution, ensureInputImageIsAvailable, ensureOutputImageResolution, getInputImage, getOutputImage, setCanInputAndOutputBeEqual, setInputImage, setOutputImage
 
Methods inherited from class net.sourceforge.jiu.ops.Operation
addProgressListener, addProgressListeners, getAbort, removeProgressListener, setAbort, setProgress, setProgress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PALETTE_SIZE

public static final int DEFAULT_PALETTE_SIZE
The default number of colors in the palette. Will be used when no other value is specified via setPaletteSize(int).

See Also:
Constant Field Values
Constructor Detail

OctreeColorQuantizer

public OctreeColorQuantizer()
Method Detail

createPalette

public Palette createPalette()
Description copied from interface: RGBQuantizer
Return a Palette object with the list of colors to be used in the quantization process. That palette may be fixed or created specifically for a given input image.

Specified by:
createPalette in interface RGBQuantizer
Returns:
Palette object for destination image

init

public void init()
          throws MissingParameterException,
                 WrongParameterException
Creates an octree and prepares this quantizer so that colors can be mapped to palette index values. If you use process() you must not call this method. On the other hand, if you want to do the mapping yourself - maybe if you want to do mapping and dithering interchangeably - call this method first, then do the mapping yourself.

Throws:
MissingParameterException - if parameters like the input image are missing
WrongParameterException - if parameters exist but are of the wrong type

map

public int map(int[] origRgb,
               int[] quantizedRgb)
Maps an RGB color origRgb to one of the colors in the color map; that color will be written to quantizedRgb and its palette index will be returned.

Specified by:
map in interface RGBQuantizer
Parameters:
origRgb - the color to be mapped to the best-possible counterpart in the palette; the array is indexed by the constants from RGBIndex
quantizedRgb - the resulting color from the palette will be written to this array; it is also indexed by the constants from RGBIndex
Returns:
index of the found color in the palette

process

public void process()
             throws MissingParameterException,
                    WrongParameterException
Initializes an octree, reduces it have as many leaves (or less) as the desired palette size and maps the original image to the newly-created palette.

Overrides:
process in class Operation
Throws:
MissingParameterException - if any mandatory parameter was not given to the operation
WrongParameterException - if at least one of the input parameters was not initialized appropriately (values out of the valid interval, etc.)

setPaletteSize

public void setPaletteSize(int newPaletteSize)

JIU 0.12.0 Homepage

Copyright © 2000, 2001, 2002, 2003, 2004 Marco Schmidt