Class TLcdPixelReplaceOp

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

public final class TLcdPixelReplaceOp extends ALcdImageOperator
Replaces every pixel in an image which matches a given value with another value. A tolerance parameter allows the matching to be made more or less strict. A typical use case for this operator is to remove borders with a solid color around the edges of an image, by replacing this color with a fully transparent one.

Example


 // Using the static method:
 double[] srcColor = ...;
 double[] dstColor = ...;
 ALcdImage inputImage = ...;
 ALcdImage outputImage = TLcdPixelReplaceOp.pixelReplace(inputImage, srcColor, dstColor, 0.01);

 // Using a data object:
 double[] srcColor = ...;
 double[] dstColor = ...;
 ALcdImage inputImage = ...;
 TLcdPixelReplaceOp op = new TLcdPixelReplaceOp();
 ILcdDataObject params = op.getParameterDataType().newInstance();
 params.setValue(TLcdPixelReplaceOp.INPUT_IMAGE, inputImage);
 params.setValue(TLcdPixelReplaceOp.SOURCE_COLOR, srcColor);
 params.setValue(TLcdPixelReplaceOp.DESTINATION_COLOR, dstColor);
 params.setValue(TLcdPixelReplaceOp.TOLERANCE, 0.01);
 ALcdImage outputImage = op.apply(params);
 
Input

Output
Since:
2024.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.
    • SOURCE_VALUE

      public static final TLcdDataProperty SOURCE_VALUE
      Pixel value to be replaced.
    • DESTINATION_VALUE

      public static final TLcdDataProperty DESTINATION_VALUE
      Value by which the source value will be replaced.
    • TOLERANCE

      public static final TLcdDataProperty TOLERANCE
      Tolerance to be used for detecting the source value in the input image.
    • PIXEL_REPLACE_FILTER_TYPE

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

    • TLcdPixelReplaceOp

      public TLcdPixelReplaceOp()
      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
    • pixelReplace

      public static ALcdImage pixelReplace(ALcdImage aSource, double[] aSourceValue, double[] aDestinationValue, double aTolerance)
      Perform a pixel replace operation on an image. The lengths of the source and destination value parameters must match the number of bands in the image. A pixel is considered to match the source value if the difference between each of its components and the corresponding source value component is smaller than aTolerance (i.e. if abs(pixelValue[i] - aSourceValue[i]) < aTolerance for all bands in the image).
      Parameters:
      aSource - the input image.
      aSourceValue - the pixel value to be replaced
      aDestinationValue - the value with which to replace the source value
      aTolerance - the tolerance used for matching the source value in the input image
      Returns:
      an image equivalent to the input, with every occurrence of the source value replaced with the destination value