// STEP 2 do the gamma correction by using generic piecewise
//
////
final DefaultPiecewiseTransform1DElement mainElement = DefaultPiecewiseTransform1DElement.create(
"exponential-contrast-enhancement-transform", NumberRange.create(minimum[0],maximum[0]),
new MathTransform1DAdapter() {
/*
* (non-Javadoc)
* @see org.opengis.referencing.operation.MathTransform1D#derivative(double)
*/
public double derivative(double value)
throws TransformException {
throw new UnsupportedOperationException(Errors.format(ErrorKeys.UNSUPPORTED_OPERATION_$1));
}
public boolean isIdentity() {
return false;
}
/*
* (non-Javadoc)
* @see org.opengis.referencing.operation.MathTransform1D#transform(double)
*/
public double transform(double value)
throws TransformException {
value = correctionFactor*(Math.exp(value/normalizationFactor)-1);
return value;
}
});
final PiecewiseTransform1D<DefaultPiecewiseTransform1DElement> transform = new DefaultPiecewiseTransform1D<DefaultPiecewiseTransform1DElement> (
new DefaultPiecewiseTransform1DElement[] {mainElement},0);
final ParameterBlockJAI pbj = new ParameterBlockJAI(
GenericPiecewise.OPERATION_NAME);
pbj.addSource(inputImage);
pbj.setParameter("Domain1D", transform);
pbj.setParameter("bandIndex", Integer.valueOf(0));
return JAI.create(
GenericPiecewise.OPERATION_NAME, pbj);
}
if (type.equalsIgnoreCase("LOGARITHMIC")) {
// /////////////////////////////////////////////////////////////////////
//
// Logarithm Normalization
//
//
//
// /////////////////////////////////////////////////////////////////////
if(dataType==DataBuffer.TYPE_BYTE){
////
//
// Optimisation for byte images m we use lookup
//
////
final byte lut[] = new byte[256];
final double normalizationFactor=255.0;
final double correctionFactor=100.0;
for (int i = 1; i < lut.length; i++)
lut[i] = (byte) (0.5f + normalizationFactor * Math.log((i * correctionFactor / normalizationFactor+ 1.0)));
return LookupDescriptor.create(inputImage,
new LookupTableJAI(lut), hints);
}
////
//
// General case
//
////
//define a specific piecewise for the logarithm
////
//
// STEP 1 do the extrema
//
////
//step 1 do the extrema to get the statistics for this image
final RenderedOp statistics = ExtremaDescriptor.create(inputImage,
null, Integer.valueOf(1), Integer.valueOf(1), null,
Integer.valueOf(1), null);
final double[] minimum=(double[]) statistics.getProperty("minimum");
final double[] maximum=(double[]) statistics.getProperty("maximum");
final double normalizationFactor=maximum[0];
final double correctionFactor=100.0;
////
//
// STEP 2 do the gamma correction by using generic piecewise
//
////
final DefaultPiecewiseTransform1DElement mainElement = DefaultPiecewiseTransform1DElement.create(
"logarithmic-contrast-enhancement-transform", NumberRange.create(minimum[0],maximum[0]),
new MathTransform1DAdapter() {
/*
* (non-Javadoc)
* @see org.opengis.referencing.operation.MathTransform1D#derivative(double)
*/