JIU 0.14.3

net.sourceforge.jiu.color.quantization
Class MedianCutContourRemoval

java.lang.Object
  extended by net.sourceforge.jiu.ops.Operation
      extended by net.sourceforge.jiu.ops.ImageToImageOperation
          extended by net.sourceforge.jiu.color.quantization.MedianCutContourRemoval

public class MedianCutContourRemoval
extends ImageToImageOperation

Performs the Median Cut color quantization algorithm in combination with a contour removal algorithm.

Quantization is an operation that reduces the number of colors in an image while trying to remain as close to the original image as possible. Standard Median Cut quantization is implemented in the MedianCutQuantizer class.

This class implements an algorithm that improves the standard implementation. It repeatedly calls the original quantizer and adjusts the palette in order to reduce the amount of contouring errors.

Image types

This operation requires an RGB24Image object as input and produces a Paletted8Image as output.

Usage example

 RGB24Image inputImage = ...; // image to be processed, from a file etc. 
 MedianCutQuantizer quantizer = new MedianCutQuantizer();
 quantizer.setPaletteSize(256);
 MedianCutContourRemoval removal = new MedianCutContourRemoval();
 removal.setQuantizer(quantizer);
 removal.setInputImage(inputImage);
 removal.setTau(11.0);
 removal.setNumPasses(3);
 removal.process();
 PixelImage outputImage = removal.getOutputImage();
 

Rationale - why an extension to Median Cut?

Quantization without dithering can lead to contouring (banding) in the output image. The contours introduced that way are not only ugly but they may lead to erroneous results when processing that quantized image. Dithering, an alternative group of algorithms used in combination with quantizers to improve output quality, leads to output which is more pleasant to the human eye. However, it introduces noise that may not be acceptable when the output image is to be further processed by image processing algorithms. Instead, this algorithm attempts to adjust the palette found by the Median Cut algorithm. The adjustments aim at reducing the amount of contouring caused by a palette found in a previous Median Cut operation.

How the contour removal algorithm works

For an in-depth description of the algorithm see the journal article mentioned in the Credits section below.

Credits

The algorithm was developed by Jefferey Shufelt and described in his article Texture Analysis for Enhanced Color Image Quantization. CVGIP: Graphical Model and Image Processing 59(3): 149-163 (1997).

Author:
Marco Schmidt
See Also:
MedianCutQuantizer

Field Summary
static int DEFAULT_NUM_PASSES
          The default number of passes, used if they are not specified with setNumPasses(int).
static double DEFAULT_TAU
          The default tau value, used if none is specified with setTau(double).
 
Constructor Summary
MedianCutContourRemoval()
           
 
Method Summary
static void main(String[] args)
          Small command line application that performs a contour removal on an image.
 void process()
          This method does the actual work of the operation.
 void setNumPasses(int newValue)
          Specify the number of contour removal passes to be performed.
 void setQuantizer(MedianCutQuantizer medianCutQuantizer)
          Set the MedianCutQuantizer object to be used with this contour removal operation.
 void setTau(double newValue)
          Specify the tau value to be used by this operation.
 
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_TAU

public static final double DEFAULT_TAU
The default tau value, used if none is specified with setTau(double). Check the class documentation to find out more about the meaning of tau: MedianCutContourRemoval.

See Also:
Constant Field Values

DEFAULT_NUM_PASSES

public static final int DEFAULT_NUM_PASSES
The default number of passes, used if they are not specified with setNumPasses(int). Check the class documentation to find out more about the meaning of that number of passes: MedianCutContourRemoval.

See Also:
Constant Field Values
Constructor Detail

MedianCutContourRemoval

public MedianCutContourRemoval()
Method Detail

main

public static void main(String[] args)
                 throws Exception
Small command line application that performs a contour removal on an image. The first and only argument must be the name of image file from which the image to be quantized is loaded.

Parameters:
args - program arguments; must have length one, the only argument being the input image file name
Throws:
Exception

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 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.)
OperationFailedException

setQuantizer

public void setQuantizer(MedianCutQuantizer medianCutQuantizer)
Set the MedianCutQuantizer object to be used with this contour removal operation. This is a mandatory parameter. If process gets called before the quantizer object was specified, a MissingParameterException is thrown.

Parameters:
medianCutQuantizer - the quantizer object that will get used by this operation

setNumPasses

public void setNumPasses(int newValue)
Specify the number of contour removal passes to be performed. Check out the section How the contour removal algorithm works to learn more about the meaning of this value. If this method is not called the default value DEFAULT_NUM_PASSES is used.

Parameters:
newValue - number of passes, 1 or higher
Throws:
IllegalArgumentException - if the argument is 0 or smaller

setTau

public void setTau(double newValue)
Specify the tau value to be used by this operation. Check out the section How the contour removal algorithm works to learn more about the meaning of this value. If this method is not called the default value DEFAULT_TAU is used.

Parameters:
newValue - tau value, 0.0 or higher
Throws:
IllegalArgumentException - if the argument is smaller than 0.0

JIU 0.14.3

Copyright © 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Marco Schmidt