Class GammaCorrection
- java.lang.Object
-
- net.sourceforge.jiu.ops.Operation
-
- net.sourceforge.jiu.ops.ImageToImageOperation
-
- net.sourceforge.jiu.ops.LookupTableOperation
-
- net.sourceforge.jiu.color.adjustment.GammaCorrection
-
public class GammaCorrection extends LookupTableOperation
Corrects the gamma of an image. Works withGrayIntegerImage
,RGBIntegerImage
andPaletted8Image
. Only the palette is manipulated for paletted images.Changes intensity values by applying the formula f(x) = MAX * (x / MAX)(1 / gamma) to each x from [0 ; MAX] to them. The MAX value is the maximum value allowed for an intensity value of the corresponding channel. It is determined by calling
IntegerImage.getMaxSample(int)
on the input image. The gamma parameter must be given to aGammaCorrection
operation before the call toprocess(net.sourceforge.jiu.data.Paletted8Image, net.sourceforge.jiu.data.Paletted8Image)
is made. The valid interval for gamma is (0.0 ;MAX_GAMMA
] (so 0.0 is not a valid value). Gamma values smaller than 1 will make the image darker, values larger than 1 will make it brighter.Usage example
GammaCorrection gamma = new GammaCorrection(); gamma.setInputImage(image); gamma.setGamma(2.2); gamma.process(); PixelImage correctedImage = gamma.getOutputImage();
- Author:
- Marco Schmidt
-
-
Constructor Summary
Constructors Constructor Description GammaCorrection()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private int[]
createLookupTable(int numSamples)
Creates a lookup table that holds all new values for samples 0 to numSamples - 1.double
getGamma()
Returns the gamma value to be used for this operation.void
process()
This method does the actual work of the operation.private void
process(Paletted8Image in, Paletted8Image out)
void
setGamma(double newGamma)
Sets a new gamma value to be used in this operation.-
Methods inherited from class net.sourceforge.jiu.ops.LookupTableOperation
getNumTables, getTable, prepareImages, setNumTables, setTable, setTables
-
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
-
MAX_GAMMA
public static final double MAX_GAMMA
The maximum allowed value for gamma.- See Also:
- Constant Field Values
-
gamma
private double gamma
-
-
Method Detail
-
createLookupTable
private final int[] createLookupTable(int numSamples)
Creates a lookup table that holds all new values for samples 0 to numSamples - 1.
-
getGamma
public double getGamma()
Returns the gamma value to be used for this operation.- Returns:
- gamma value between 0 (not included) and
MAX_GAMMA
-
process
private void process(Paletted8Image in, Paletted8Image 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 classLookupTableOperation
- 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.)
-
setGamma
public void setGamma(double newGamma)
Sets a new gamma value to be used in this operation.- Parameters:
newGamma
- the new gamma value must be > 0.0 and <= MAX_GAMMA- Throws:
IllegalArgumentException
- if the argument is not in the described interval
-
-