Class AffineTransforms

java.lang.Object
qupath.lib.awt.common.AffineTransforms

public class AffineTransforms extends Object
Helper class for working with affine transforms.

QuPath's core dependencies have two affine transform implementations: AffineTransform from Java itself and AffineTransformation from Java Topology Suite. Inconveniently, both are initialized from flattened double arrays using a different ordering (assuming columns-first or rows-first) - so it is easy to make mistakes.

QuPath primarily uses AffineTransform from Java. This class exists to make creating a transform more explicit, and facilitate conversion when needed.

Author:
Pete Bankhead
  • Constructor Details

    • AffineTransforms

      public AffineTransforms()
  • Method Details

    • from2D

      public static AffineTransform from2D(double[][] mat) throws IllegalArgumentException
      Create an affine transform from a 2x3 double array, or 3x3 if the last row has the values [0, 0, 1] only.
      Parameters:
      mat -
      Returns:
      Throws:
      IllegalArgumentException - if the input has the wrong shape
    • fromRows

      public static AffineTransform fromRows(double... mat) throws IllegalArgumentException
      Create an affine transform from a flat matrix with 6 elements, assumed to be in the order [[0, 1, 2], [3, 4, 5]].
      Parameters:
      mat -
      Returns:
      Throws:
      IllegalArgumentException - if the input has the wrong length
    • fromColumns

      public static AffineTransform fromColumns(double... mat) throws IllegalArgumentException
      Create an affine transform from a flat matrix with 6 elements, assumed to be in the order [[0, 2, 4], [1, 3, 5]].
      Parameters:
      mat -
      Returns:
      Throws:
      IllegalArgumentException - if the input has the wrong length
    • fromScale

      public static AffineTransform fromScale(double scaleX, double scaleY)
      Create an affine transform representing scaling, optionally using a different scale for x and y.
      Parameters:
      scaleX -
      scaleY -
      Returns:
    • fromScale

      public static AffineTransform fromScale(double scale)
      Create an affine transform representing scaling, using the same scale for x and y.
      Parameters:
      scale -
      Returns:
    • identity

      public static AffineTransform identity()
      Create an affine transform representing the identity transform.
      Returns:
    • fromJTS

      public static AffineTransform fromJTS(AffineTransformation transform)
      Create a Java affine transform from a Java Topology Suite representation.
      Parameters:
      transform -
      Returns:
    • toJTS

      public static AffineTransformation toJTS(AffineTransform transform)
      Create a Java Topology Suite affine transformation from a Java affine transform.
      Parameters:
      transform -
      Returns: