Interface Transform


public interface Transform
Transformation from image to tensor.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final float[]
    The default mean value of pixel RGB after normalized to [0, 1].
    static final float[]
    The default standard deviation of pixel RGB after normalized to [0, 1].
  • Method Summary

    Modifier and Type
    Method
    Description
    static Transform
    classification(int cropSize, int resizeSize)
    Returns a transform for image classification.
    static Transform
    classification(int cropSize, int resizeSize, float[] mean, float[] std, int hints)
    Returns a transform for image classification.
    crop(BufferedImage image, int size, boolean deep)
    Crops an image.
    crop(BufferedImage image, int width, int height, boolean deep)
    Crops an image.
    Transforms images to 4-D tensor with shape [samples, channels, height, width].
    resize(BufferedImage image, int size, int hints)
    Resizes an image and keeps the aspect ratio.
    default Tensor
    toTensor(float[] mean, float[] std, BufferedImage... images)
    Returns the tensor with NCHW shape [samples, channels, height, width] of the images.
  • Field Details

    • DEFAULT_MEAN

      static final float[] DEFAULT_MEAN
      The default mean value of pixel RGB after normalized to [0, 1]. Calculated on ImageNet data.
    • DEFAULT_STD

      static final float[] DEFAULT_STD
      The default standard deviation of pixel RGB after normalized to [0, 1]. Calculated on ImageNet data.
  • Method Details

    • forward

      Tensor forward(BufferedImage... images)
      Transforms images to 4-D tensor with shape [samples, channels, height, width].
      Parameters:
      images - the input images.
      Returns:
      the 4-D tensor representation of images.
    • resize

      default BufferedImage resize(BufferedImage image, int size, int hints)
      Resizes an image and keeps the aspect ratio.
      Parameters:
      image - the input image.
      size - the image size of the shorter side.
      hints - flags to indicate the type of algorithm to use for image resampling. See SCALE_DEFAULT, SCALE_FAST, SCALE_SMOOTH, SCALE_REPLICATE, SCALE_AREA_AVERAGING of java.awt.Image class.
      Returns:
      the output image.
    • crop

      default BufferedImage crop(BufferedImage image, int size, boolean deep)
      Crops an image.
      Parameters:
      image - the image size.
      size - the cropped image size.
      deep - If false, the returned BufferedImage shares the same data array as the original image. Otherwise, returns a deep copy.
      Returns:
      the cropped image.
    • crop

      default BufferedImage crop(BufferedImage image, int width, int height, boolean deep)
      Crops an image. The returned BufferedImage shares the same data array as the original image.
      Parameters:
      image - the image size.
      width - the cropped image width.
      height - the cropped image height.
      deep - If false, the returned BufferedImage shares the same data array as the original image. Otherwise, returns a deep copy.
      Returns:
      the cropped image.
    • toTensor

      default Tensor toTensor(float[] mean, float[] std, BufferedImage... images)
      Returns the tensor with NCHW shape [samples, channels, height, width] of the images. The values of tensor are first rescaled to [0.0, 1.0] and then normalized.
      Parameters:
      mean - the normalization mean.
      std - the normalization standard deviation.
      images - the input images that should have same size.
      Returns:
      the output tensor.
    • classification

      static Transform classification(int cropSize, int resizeSize)
      Returns a transform for image classification. The images are resized using scaling hints, followed by a central crop. Finally, the values are first rescaled to [0.0, 1.0] and then normalized.
      Parameters:
      cropSize - the crop size.
      resizeSize - the scaling size.
      Returns:
      a transform for image classification.
    • classification

      static Transform classification(int cropSize, int resizeSize, float[] mean, float[] std, int hints)
      Returns a transform for image classification. The images are resized using scaling hints, followed by a central crop. Finally, the values are first rescaled to [0.0, 1.0] and then normalized.
      Parameters:
      cropSize - the crop size.
      resizeSize - the scaling size.
      mean - the normalization mean.
      std - the normalization standard deviation.
      hints - the scaling hints.
      Returns:
      a transform for image classification.