net.sourceforge.jiu.color.quantization

Class PopularityQuantizer

Implemented Interfaces:
RGBIndex, RGBQuantizer

public class PopularityQuantizer
extends ImageToImageOperation
implements RGBIndex, RGBQuantizer

Performs the popularity color quantization algorithm that maps an image to the colors occurring most frequently in the input image. The number of colors in the palette can be defined by the user of this operation with setPaletteSize(int).

Supported image types

The input image must implement RGB24Image, the output image must be of type Paletted8Image.

Usage example

The following code snippet uses the default settings with a palette of 256 entries.
 PopularityQuantizer quantizer = new PopularityQuantizer();
 quantizer.setInputImage(image);
 quantizer.setPaletteSize(256);
 quantizer.process();
 PixelImage quantizedImage = quantizer.getOutputImage();
 
Author:
Marco Schmidt
Since:
0.11.0
See Also:
ArbitraryPaletteQuantizer

Field Summary

private ArbitraryPaletteQuantizer
arbQuantizer
private boolean
doNotMap
private Palette
palette
private int
paletteSize

Fields inherited from class net.sourceforge.jiu.ops.ImageToImageOperation

canInAndOutBeEqual, inputImage, outputImage

Fields inherited from class net.sourceforge.jiu.ops.Operation

abort, progressListeners

Fields inherited from interface net.sourceforge.jiu.data.RGBIndex

INDEX_BLUE, INDEX_GREEN, INDEX_RED

Method Summary

Palette
createPalette()
private Palette
determinePalette()
int
getPaletteSize()
Returns the number of colors in the destination image.
int
map(int[] origRgb, int[] quantizedRgb)
void
process()
void
setMapping(boolean newValue)
Specifies whether this operation will map the image to the new palette (true) or not (false).
void
setPaletteSize(int newPaletteSize)
Sets the number of colors that this operations is supposed to reduce the original image to.

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, process, removeProgressListener, setAbort, setProgress, setProgress

Field Details

arbQuantizer

private ArbitraryPaletteQuantizer arbQuantizer

doNotMap

private boolean doNotMap

palette

private Palette palette

paletteSize

private int paletteSize

Method Details

createPalette

public Palette createPalette()
Specified by:
createPalette in interface RGBQuantizer

determinePalette

private Palette determinePalette()
            throws OperationFailedException

getPaletteSize

public int getPaletteSize()
Returns the number of colors in the destination image. If output is paletted, this is also the number of entries in the palette.
Returns:
number of colors in the destination

map

public int map(int[] origRgb,
               int[] quantizedRgb)
Specified by:
map in interface RGBQuantizer

process

public void process()
            throws MissingParameterException,
                   OperationFailedException,
                   WrongParameterException
Overrides:
process in interface Operation

setMapping

public void setMapping(boolean newValue)
Specifies whether this operation will map the image to the new palette (true) or not (false). The latter may be interesting if only the palette is required. By default, this operation does map.
Parameters:
newValue - map to new image (true) or just search palette (false)

setPaletteSize

public void setPaletteSize(int newPaletteSize)
Sets the number of colors that this operations is supposed to reduce the original image to.
Parameters:
newPaletteSize - the number of colors