Class ReduceShadesOfGray
- java.lang.Object
-
- net.sourceforge.jiu.ops.Operation
-
- net.sourceforge.jiu.ops.ImageToImageOperation
-
- net.sourceforge.jiu.color.reduction.ReduceShadesOfGray
-
public class ReduceShadesOfGray extends ImageToImageOperation
Reduces the number of shades of gray of a grayscale image. This class uses the most simple possible algorithm. Only the most significant N bits are kept (where N is the number specified withsetBits(int)
), the others are dropped and the result is scaled back to either 8 or 16 bits to fit into the two grayscale image types.Supported image classes
This class works withGray8Image
andGray16Image
.Usage example
Reduce a grayscale image to 3 bit (23 = 8 shades of gray):ReduceShadesOfGray reduce = new ReduceShadesOfGray(); reduce.setBits(3); reduce.setInputImage(image); // some Gray8Image or Gray16Image reduce.process(); PixelImage reducedImage = reduce.getOutputImage();
- Since:
- 0.3.0
- Author:
- Marco Schmidt
-
-
Constructor Summary
Constructors Constructor Description ReduceShadesOfGray()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
createLut(int inDepth)
void
process()
This method does the actual work of the operation.private void
process(GrayIntegerImage in, int MASK, BilevelImage out)
private void
process(GrayIntegerImage in, GrayIntegerImage out)
void
setBits(int bits)
Specifies the number of bits the output image is supposed to have.-
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
-
destBits
private Integer destBits
Number of significant bits in the destination grayscale image.
-
lut
private int[] lut
Lookup table, for each possible input sample stores the corresponding output sample.
-
-
Method Detail
-
createLut
private void createLut(int inDepth)
-
process
private void process(GrayIntegerImage in, int MASK, BilevelImage out)
-
process
private void process(GrayIntegerImage in, GrayIntegerImage 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.)
-
setBits
public void setBits(int bits)
Specifies the number of bits the output image is supposed to have.- Parameters:
bits
- number of bits in output image, from 1 to 15- Throws:
IllegalArgumentException
- if bits is smaller than 1 or larger than 15
-
-