Class OrderedDither
- java.lang.Object
-
- net.sourceforge.jiu.ops.Operation
-
- net.sourceforge.jiu.ops.ImageToImageOperation
-
- net.sourceforge.jiu.color.dithering.OrderedDither
-
- All Implemented Interfaces:
RGBIndex
public class OrderedDither extends ImageToImageOperation implements RGBIndex
This operation reduces the color depth of RGB truecolor images and grayscale images by applying ordered dithering. A relatively nice output image (for a human observer) will be created at the cost of introducing noise into the output image. The algorithm is relatively fast, but its quality is usually inferior to what can be reached by usingErrorDiffusionDithering
or similar other methods.Supported conversions
- Grayscale to bilevel maps GrayIntegerImage objects to BilevelImage objects.
- Grayscale to grayscale maps GrayIntegerImage objects to other GrayIntegerImage objects. Right now, only Gray8Image objects are supported. After reducing the number of bits, each sample is immediately scaled back to 8 bits per pixel in order to fit into another Gray8Image object.
- Truecolor to paletted maps RGBIntegerImage objects to Paletted8Image objects; the sum of the output bits must not be larger than 8
Usage example
The following code snippet demonstrates how to create a paletted image with 256 colors, using three bits for red and green and two bits for blue, from an RGB truecolor image.OrderedDither od = new OrderedDither(); od.setRgbBits(3, 3, 2); od.setInputImage(image); od.process(); Paletted8Image ditheredImage = (Paletted8Image)od.getOutputImage();
- Author:
- Marco Schmidt
-
-
Field Summary
Fields Modifier and Type Field Description private int
blueBits
private int
grayBits
private int
greenBits
private int
redBits
private int
valueHeight
private int[]
values
private int
valueWidth
-
Fields inherited from interface net.sourceforge.jiu.data.RGBIndex
INDEX_BLUE, INDEX_GREEN, INDEX_RED
-
-
Constructor Summary
Constructors Constructor Description OrderedDither()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
process()
This method does the actual work of the operation.private void
process(Gray8Image in, BilevelImage out)
private void
process(Gray8Image in, Gray8Image out)
private void
process(RGB24Image in, Paletted8Image out)
private void
process(RGB24Image in, RGB24Image out)
void
setOutputBits(int bits)
void
setRgbBits(int red, int green, int blue)
Sets the number of bits to be used for each RGB component in the output image.void
setStandardThresholdValues()
CallssetThresholdValues(int[], int, int)
with a 16 x 16 matrix.void
setThresholdValues(int[] values, int valueWidth, int valueHeight)
Defines a matrix of threshold values that will be used for grayscale dithering.-
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
-
-
-
-
Method Detail
-
process
private void process(Gray8Image in, Gray8Image out)
-
process
private void process(Gray8Image in, BilevelImage out)
-
process
private void process(RGB24Image in, Paletted8Image out)
-
process
private void process(RGB24Image in, RGB24Image out)
-
process
public void process() throws MissingParameterException, 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.)
-
setOutputBits
public void setOutputBits(int bits)
-
setRgbBits
public void setRgbBits(int red, int green, int blue)
Sets the number of bits to be used for each RGB component in the output image. Each argument must be one or larger. The values defined by this method are only used if the input image implements RGBIntegerImage. Later, inprocess(net.sourceforge.jiu.data.Gray8Image, net.sourceforge.jiu.data.Gray8Image)
, these values are checked against the actual number of bits per component in the input image. If any of the arguments of this method is equal to or larger than those actual bits per channel values, a WrongParameterException will then be thrown. Right now, there is no way how this can be checked, because the input image may not have been defined yet.- Parameters:
red
- number of bits for the red channel in the output imagegreen
- number of bits for the green channel in the output imageblue
- number of bits for the blue channel in the output image- Throws:
IllegalArgumentException
- if at least one argument is smaller than1
-
setStandardThresholdValues
public void setStandardThresholdValues()
CallssetThresholdValues(int[], int, int)
with a 16 x 16 matrix.
-
setThresholdValues
public void setThresholdValues(int[] values, int valueWidth, int valueHeight)
Defines a matrix of threshold values that will be used for grayscale dithering.- Parameters:
values
- the int values to use for comparingvalueWidth
-valueHeight
-
-
-