Class TLcdPixelTransformOp

java.lang.Object
com.luciad.imaging.operator.ALcdImageOperator
com.luciad.imaging.operator.TLcdPixelTransformOp

public final class TLcdPixelTransformOp extends ALcdImageOperator
Adjusts the pixel values of an image by applying an affine transform defined by a 2-dimensional matrix and a 1-dimensional offset vector.

This operation is equivalent to the following pseudo-code:


    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}.

Example

Convert from RGB to YCbCr:

 // 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);
 
Input
Output
(Y, Cb and Cr are visualized here as red, green and blue for illustration purposes)
Since:
2014.0
  • Field Details

    • NAME

      public static final String NAME
      Name of the operator.
      See Also:
    • INPUT_IMAGE

      public static final TLcdDataProperty INPUT_IMAGE
      The input image.
    • MATRIX

      public static final TLcdDataProperty MATRIX
      The matrix to apply to the input pixel values.
    • OFFSETS

      public static final TLcdDataProperty OFFSETS
      The offset to apply to the input values transformed with the matrix

      Note that this offset applies to normalized input values. So for example to add 1 to each pixel of an image with 8-bit unsigned integers you would use an offset of 1.0 / 255.0.

    • PIXEL_TRANSFORM_FILTER_TYPE

      public static final TLcdDataType PIXEL_TRANSFORM_FILTER_TYPE
      Input data type of the operator.
  • Constructor Details

    • TLcdPixelTransformOp

      public TLcdPixelTransformOp()
      Default constructor.
  • Method Details

    • apply

      public ALcdImage apply(ILcdDataObject aParameters)
      Description copied from class: ALcdImageOperator
      Applies this operator to the given input parameters. The parameters are stored in a data object which must be of the type given by ALcdImageOperator.getParameterDataType().
      Specified by:
      apply in class ALcdImageOperator
      Parameters:
      aParameters - the parameters for the operator
      Returns:
      the image produced by the operator
    • pixelTransform

      public static ALcdImage pixelTransform(ALcdImage aSource, double[] aMatrix, double[] aOffsets)
      Creates a pixel transform operator for a given input image. The operator takes arrays of representing the matrix (in row-major order) and offsets vectors. The length of aOffsets should be equal to the number of bands in the image. The length of aMatrix should be the square of the number of bands in the image.
      Parameters:
      aSource - the image to be processed
      aMatrix - the matrix to be applied to each of the images pixels
      aOffsets - the offsets to be added
      Returns:
      an image with the same number of bands as the input image, where each pixel is the result of the affine transform defined by the matrix and offsets vector.