public final class TLcdPixelTransformOp extends ALcdImageOperator
pixelTransform(in_value) {
normalized_in_value = normalize(in_value)
normalized_out_value = matrix * normalized_in_value + offsets
return denormalize(normalized_out_value)
}
The normalization range is defined by the ALcdBandSemantics
of the image.
This operator for example allows scaling pixel values by using a diagonal matrix. For example, increasing the red channel of an RGB image can be done using the matrix {2, 0, 0, 0, 1, 0, 0, 0, 1} and offsets vector {0, 0, 0}. The operator also allows mixing multiple bands together. Converting for example an RGB image to a full-range YCbCr image can be done using the matrix {0.299, 0.587, 0.114, -0.169, -0.331, 0.5, 0.5, -0.419, -0.081} and the offsets vector {0, 0.5, 0.5}.
// Using the static method:
ALcdImage inputImage = ...;
ALcdImage outputImage = TLcdPixelTransformOp.pixelTransform(
inputImage,
new double[]{0.299, 0.587, 0.114, -0.169, -0.331, 0.5, 0.5, -0.419, -0.081},
new double[]{0.0, 0.5, 0.5}
);
// Using a data object:
ALcdImage inputImage = ...;
TLcdPixelTransformOp op = new TLcdPixelTransformOp();
ILcdDataObject params = op.getParameterDataType().newInstance();
params.setValue(TLcdPixelTransformOp.INPUT_IMAGE, inputImage);
params.setValue(TLcdPixelTransformOp.MATRIX, new double[]{0.299, 0.587, 0.114, -0.169, -0.331, 0.5, 0.5, -0.419, -0.081});
params.setValue(TLcdPixelTransformOp.OFFSETS, new double[]{0.0, 0.5, 0.5});
ALcdImage outputImage = op.apply(params);
ALcdImageOperator.ImageOperatorTypeBuilder
Modifier and Type | Field and Description |
---|---|
static TLcdDataProperty |
INPUT_IMAGE
The input image.
|
static TLcdDataProperty |
MATRIX
The matrix to apply to the input pixel values.
|
static String |
NAME
Name of the operator.
|
static TLcdDataProperty |
OFFSETS
The offset to apply to the input values transformed with the matrix
Note that this offset applies to normalized input values.
|
static TLcdDataType |
PIXEL_TRANSFORM_FILTER_TYPE
Input data type of the operator.
|
INPUT_IMAGE_NAME
Constructor and Description |
---|
TLcdPixelTransformOp()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
ALcdImage |
apply(ILcdDataObject aParameters)
Applies this operator to the given input parameters.
|
static ALcdImage |
pixelTransform(ALcdImage aSource,
double[] aMatrix,
double[] aOffsets)
Creates a pixel transform operator for a given input image.
|
createTypeBuilder, createTypeBuilder, equals, getParameterDataType, hashCode, toString
public static final String NAME
public static final TLcdDataProperty INPUT_IMAGE
public static final TLcdDataProperty MATRIX
public static final TLcdDataProperty OFFSETS
1.0 / 255.0
.public static final TLcdDataType PIXEL_TRANSFORM_FILTER_TYPE
public ALcdImage apply(ILcdDataObject aParameters)
ALcdImageOperator
apply
in class ALcdImageOperator
aParameters
- the parameters for the operatorpublic static ALcdImage pixelTransform(ALcdImage aSource, double[] aMatrix, double[] aOffsets)
aSource
- the image to be processedaMatrix
- the matrix to be applied to each of the images pixelsaOffsets
- the offsets to be added