Class PopularityQuantizer
- java.lang.Object
-
- net.sourceforge.jiu.ops.Operation
-
- net.sourceforge.jiu.ops.ImageToImageOperation
-
- net.sourceforge.jiu.color.quantization.PopularityQuantizer
-
- All Implemented Interfaces:
RGBQuantizer
,RGBIndex
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 withsetPaletteSize(int)
.Supported image types
The input image must implementRGB24Image
, the output image must be of typePaletted8Image
.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();
- Since:
- 0.11.0
- Author:
- Marco Schmidt
- See Also:
ArbitraryPaletteQuantizer
-
-
Field Summary
Fields Modifier and Type Field Description private ArbitraryPaletteQuantizer
arbQuantizer
private boolean
doNotMap
private Palette
palette
private int
paletteSize
-
Fields inherited from interface net.sourceforge.jiu.data.RGBIndex
INDEX_BLUE, INDEX_GREEN, INDEX_RED
-
-
Constructor Summary
Constructors Constructor Description PopularityQuantizer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Palette
createPalette()
Return a Palette object with the list of colors to be used in the quantization process.private Palette
determinePalette()
int
getPaletteSize()
Returns the number of colors in the destination image.int
map(int[] origRgb, int[] quantizedRgb)
This method maps a triplet of intensity values to its quantized counterpart and returns the palette index of that quantized color.void
process()
This method does the actual work of the operation.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, removeProgressListener, setAbort, setProgress, setProgress
-
-
-
-
Field Detail
-
arbQuantizer
private ArbitraryPaletteQuantizer arbQuantizer
-
paletteSize
private int paletteSize
-
palette
private Palette palette
-
doNotMap
private boolean doNotMap
-
-
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 interfaceRGBQuantizer
- Returns:
- Palette object for destination image
-
determinePalette
private Palette determinePalette() throws OperationFailedException
- 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
- See Also:
setPaletteSize(int)
-
map
public int map(int[] origRgb, int[] quantizedRgb)
Description copied from interface:RGBQuantizer
This method maps a triplet of intensity values to its quantized counterpart and returns the palette index of that quantized color. The index values for the two arrays are taken from RGBIndex.- Specified by:
map
in interfaceRGBQuantizer
- Parameters:
origRgb
- the three samples red, green and blue for which a good match is searched in the palettequantizedRgb
- will hold the three samples found to be closest to origRgb after the call to this method- Returns:
- int index in the palette of the match quantizedRgb
-
process
public void process() throws MissingParameterException, OperationFailedException, WrongParameterException
Description copied from class:Operation
This method does the actual work of the operation. It must be called after all parameters have been given to the operation object.- Overrides:
process
in classOperation
- Throws:
MissingParameterException
- if any mandatory parameter was not given to the operationWrongParameterException
- if at least one of the input parameters was not initialized appropriately (values out of the valid interval, etc.)OperationFailedException
-
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- Throws:
IllegalArgumentException
- if the argument is smaller than 1 or larger than 256- See Also:
getPaletteSize()
-
-