|
JIU 0.12.0 Homepage | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.jiu.ops.Operation
net.sourceforge.jiu.ops.ImageToImageOperation
net.sourceforge.jiu.color.quantization.ArbitraryPaletteQuantizer
A color quantizer that maps an RGBImage
to any given palette.
This operation is restricted to RGB24Image and palettes with up to 256 colors.
It picks the color from the palette which is closest to the
color to be quantized (with the minimum distance).
This is a rather naive implementation which, for any given color
to be quantized, computes the distance between it and each color
in the palette (read: this operation is rather slow with a large palette and input image).
It uses Manhattan distance (L1) instead of Euclidean distance (L2). This saves a square root operation per distance computation.
There are more sophisticated nearest neighbor algorithms available, left for future extensions.
This example maps an RGB truecolor image to some palette we create.
RGB24Image image = ...; // initialize this // create some Palette object that you want to map the image to Palette palette = new Palette(3); // create palette with three entries palette.put(0, 33, 00, 244); // set first color palette.put(1, 0, 240, 193); // set second color palette.put(2, 245, 126, 136); // set third color ArbitraryPaletteQuantizer quantizer = new ArbitraryPaletteQuantizer(palette); quantizer.setInputImage(image); quantizer.process(); PixelImage quantizedImage = quantizer.getOutputImage();
Field Summary |
Fields inherited from interface net.sourceforge.jiu.data.RGBIndex |
INDEX_BLUE, INDEX_GREEN, INDEX_RED |
Constructor Summary | |
ArbitraryPaletteQuantizer(Palette palette)
Creates a quantizer that will be able to map pixels (or a complete image) to the argument palette. |
Method Summary | |
Palette |
createPalette()
Returns a copy of the palette that was given to the constructor of this class. |
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. |
int |
map(int red,
int green,
int blue)
Finds the best match for the argument color in the palette and returns its index. |
void |
process()
Maps the input image to an output image, using the palette given to the constructor. |
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 |
Constructor Detail |
public ArbitraryPaletteQuantizer(Palette palette)
Method Detail |
public Palette createPalette()
createPalette
in interface RGBQuantizer
public int map(int[] origRgb, int[] quantizedRgb)
RGBQuantizer
map
in interface RGBQuantizer
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
public int map(int red, int green, int blue)
map(int[], int[])
, the quantized color is not required
and thus a few assignemnts are saved by this method.
red
- red sample of the pixel to be quantizedgreen
- green sample of the pixel to be quantizedblue
- blue sample of the pixel to be quantized
public void process() throws MissingParameterException, WrongParameterException
process
in class Operation
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.)
|
JIU 0.12.0 Homepage | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |