Class GroovyCV

java.lang.Object
qupath.opencv.tools.GroovyCV

public class GroovyCV extends Object
Category class for enhanced Groovy scripting with OpenCV.

See https://docs.groovy-lang.org/latest/html/api/groovy/lang/Category.html

Warning! This is experimental and likely to change between QuPath releases. Use with caution and discuss on http://forum.image.sc/tag/qupath

Author:
Pete Bankhead
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
     
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    static Mat
    abs(Mat mat)
    Compute the absolute value of all elements in an array.
    static Mat
    and(Mat m1, Mat m2)
    Compute the bitwise AND of two arrays.
    static <T> T
    asType(ImagePlus imp, Class<T> cls)
    Helper method to convert an ImagePlus to a Mat or ImageProcessor using Groovy's 'as' syntax.
    static <T> T
    Helper method to convert an ImageProcessor to a Mat using Groovy's 'as' syntax.
    static <T> T
    asType(BufferedImage img, Class<T> cls)
    Helper method to convert a BufferedImage to a Mat, ImageProcessor or ImagePlus using Groovy's 'as' syntax.
    static <T> T
    asType(Number n, Class<T> cls)
    Helper function to convert a Number to a Mat or Scalar using Groovy's 'as' syntax.
    static <T> T
    asType(Mat mat, Class<T> cls)
    Helper method to convert a Mat to a BufferedImage, ImagePlus, ImageProcessor, double or float array using Groovy's 'as' syntax.
    static Mat
    Compute the bitwise NOT of an array.
    static Mat
    clip(Mat mat, double min, double max)
    Clip values of a Mat to be within a specified minimum and maximum.
    static Mat
    div(Mat m1, double s)
    Divide array elements by a constant.
    static Mat
    div(Mat m1, Mat m2)
    Per-element division of two arrays.
    static Mat
    eq(Mat m1, double value)
    Create a binary image showing where an array has a specific value.
    static Mat
    eq(Mat m1, Mat m2)
    Create a binary image showing where two arrays have matching values.
    static Mat
    flatten(Mat mat)
    Flatten a Mat to give a single column.
    static Mat
    geq(Mat m1, double threshold)
    Apply a greater than or equal to threshold.
    static Mat
    geq(Mat m1, Mat m2)
    Apply a greater than or equal to threshold between two arrays.
    static Mat
    gt(Mat m1, double threshold)
    Apply a greater than threshold.
    static Mat
    gt(Mat m1, Mat m2)
    Apply a greater than threshold between two arrays.
    static Mat
    leq(Mat m1, double threshold)
    Apply a less than or equal to threshold.
    static Mat
    leq(Mat m1, Mat m2)
    Apply a less than or equal to threshold between two arrays.
    static Mat
    lt(Mat m1, double threshold)
    Apply a less than threshold.
    static Mat
    lt(Mat m1, Mat m2)
    Apply a less than threshold between two arrays.
    static double
    max(Mat mat)
    Find the maximum of all elements in a Mat, ignoring NaNs.
    static Mat
    maximum(Mat m1, double d)
    Get the per-element maximum value between an array and a scalar.
    static Mat
    maximum(Mat m1, Mat m2)
    Get the per-element maximum value for two arrays.
    static double
    mean(Mat mat)
    Calculate the mean of all elements in a Mat, ignoring NaNs.
    static double
    min(Mat mat)
    Find the minimum of all elements in a Mat, ignoring NaNs.
    static Mat
    minimum(Mat m1, double d)
    Get the per-element minimum value between an array and a scalar.
    static Mat
    minimum(Mat m1, Mat m2)
    Get the per-element minimum value for two arrays.
    static Mat
    minus(Mat m1, Number s)
    Subtract a constant from an array.
    static Mat
    minus(Mat m1, Mat m2)
    Subtract one array from another.
    static Mat
    minus(Mat m1, Scalar s)
    Subtract a scalar from an array.
    static Mat
    multiply(Mat m1, double s)
    Multiply array elements by a constant.
    static Mat
    multiply(Mat m1, Mat m2)
    Per-element multiplication of two arrays (not matrix multiplication).
    static Mat
    Multiply elements of an array by -1.
    static Mat
    or(Mat m1, Mat m2)
    Compute the bitwise OR of two arrays.
    static Mat
    plus(Mat m1, Number s)
    Add an array and a number.
    static Mat
    plus(Mat m1, Mat m2)
    Add two arrays.
    static Mat
    plus(Mat m1, Scalar s)
    Add an array and a scalar.
    static Mat
    power(Mat m1, double power)
    Raise elements of an array to a specified power.
    static long[]
    shape(Mat mat)
    Get the shape of a multidimensional Mat.
    static List<Mat>
    Split channels of an array.
    static double
    std(Mat mat)
    Calculate the standard deviation of all elements in a Mat, ignoring NaNs.
    static double
    sum(Mat mat)
    Calculate the sum of all elements in a Mat, ignoring NaNs.
    static Mat
    xor(Mat m1, Mat m2)
    Compute the bitwise XOR of two arrays.

    Methods inherited from class java.lang.Object Link icon

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details Link icon

    • GroovyCV Link icon

      public GroovyCV()
  • Method Details Link icon

    • mean Link icon

      public static double mean(Mat mat)
      Calculate the mean of all elements in a Mat, ignoring NaNs.
      Parameters:
      mat -
      Returns:
    • sum Link icon

      public static double sum(Mat mat)
      Calculate the sum of all elements in a Mat, ignoring NaNs.
      Parameters:
      mat -
      Returns:
    • std Link icon

      public static double std(Mat mat)
      Calculate the standard deviation of all elements in a Mat, ignoring NaNs.
      Parameters:
      mat -
      Returns:
    • max Link icon

      public static double max(Mat mat)
      Find the maximum of all elements in a Mat, ignoring NaNs.
      Parameters:
      mat -
      Returns:
    • min Link icon

      public static double min(Mat mat)
      Find the minimum of all elements in a Mat, ignoring NaNs.
      Parameters:
      mat -
      Returns:
    • flatten Link icon

      public static Mat flatten(Mat mat)
      Flatten a Mat to give a single column.
      Parameters:
      mat -
      Returns:
    • shape Link icon

      public static long[] shape(Mat mat)
      Get the shape of a multidimensional Mat.
      Parameters:
      mat -
      Returns:
    • clip Link icon

      public static Mat clip(Mat mat, double min, double max)
      Clip values of a Mat to be within a specified minimum and maximum.
      Parameters:
      mat -
      min -
      max -
      Returns:
    • maximum Link icon

      public static Mat maximum(Mat m1, Mat m2)
      Get the per-element maximum value for two arrays.
      Parameters:
      m1 -
      m2 -
      Returns:
    • maximum Link icon

      public static Mat maximum(Mat m1, double d)
      Get the per-element maximum value between an array and a scalar.
      Parameters:
      m1 -
      d -
      Returns:
    • minimum Link icon

      public static Mat minimum(Mat m1, double d)
      Get the per-element minimum value between an array and a scalar.
      Parameters:
      m1 -
      d -
      Returns:
    • minimum Link icon

      public static Mat minimum(Mat m1, Mat m2)
      Get the per-element minimum value for two arrays.
      Parameters:
      m1 -
      m2 -
      Returns:
    • plus Link icon

      public static Mat plus(Mat m1, Mat m2)
      Add two arrays.
      Parameters:
      m1 -
      m2 -
      Returns:
    • plus Link icon

      public static Mat plus(Mat m1, Number s)
      Add an array and a number.
      Parameters:
      m1 -
      s -
      Returns:
    • plus Link icon

      public static Mat plus(Mat m1, Scalar s)
      Add an array and a scalar.
      Parameters:
      m1 -
      s -
      Returns:
    • minus Link icon

      public static Mat minus(Mat m1, Mat m2)
      Subtract one array from another.
      Parameters:
      m1 -
      m2 -
      Returns:
    • minus Link icon

      public static Mat minus(Mat m1, Number s)
      Subtract a constant from an array.
      Parameters:
      m1 -
      s -
      Returns:
    • minus Link icon

      public static Mat minus(Mat m1, Scalar s)
      Subtract a scalar from an array.
      Parameters:
      m1 -
      s -
      Returns:
    • multiply Link icon

      public static Mat multiply(Mat m1, Mat m2)
      Per-element multiplication of two arrays (not matrix multiplication).
      Parameters:
      m1 -
      m2 -
      Returns:
    • multiply Link icon

      public static Mat multiply(Mat m1, double s)
      Multiply array elements by a constant.
      Parameters:
      m1 -
      s -
      Returns:
    • div Link icon

      public static Mat div(Mat m1, Mat m2)
      Per-element division of two arrays.
      Parameters:
      m1 -
      m2 -
      Returns:
    • div Link icon

      public static Mat div(Mat m1, double s)
      Divide array elements by a constant.
      Parameters:
      m1 -
      s -
      Returns:
    • abs Link icon

      public static Mat abs(Mat mat)
      Compute the absolute value of all elements in an array.
      Parameters:
      mat -
      Returns:
    • negative Link icon

      public static Mat negative(Mat m1)
      Multiply elements of an array by -1.
      Parameters:
      m1 -
      Returns:
    • or Link icon

      public static Mat or(Mat m1, Mat m2)
      Compute the bitwise OR of two arrays.
      Parameters:
      m1 -
      m2 -
      Returns:
    • and Link icon

      public static Mat and(Mat m1, Mat m2)
      Compute the bitwise AND of two arrays.
      Parameters:
      m1 -
      m2 -
      Returns:
    • xor Link icon

      public static Mat xor(Mat m1, Mat m2)
      Compute the bitwise XOR of two arrays.
      Parameters:
      m1 -
      m2 -
      Returns:
    • bitwiseNegate Link icon

      public static Mat bitwiseNegate(Mat m1)
      Compute the bitwise NOT of an array.
      Parameters:
      m1 -
      Returns:
    • power Link icon

      public static Mat power(Mat m1, double power)
      Raise elements of an array to a specified power.
      Parameters:
      m1 -
      power -
      Returns:
    • splitChannels Link icon

      public static List<Mat> splitChannels(Mat mat)
      Split channels of an array.
      Parameters:
      mat -
      Returns:
    • gt Link icon

      public static Mat gt(Mat m1, double threshold)
      Apply a greater than threshold. The output is an 8-bit unsigned array with values 0 and 255.
      Parameters:
      m1 -
      threshold -
      Returns:
    • gt Link icon

      public static Mat gt(Mat m1, Mat m2)
      Apply a greater than threshold between two arrays. The output is an 8-bit unsigned array with values 0 and 255.
      Parameters:
      m1 -
      m2 -
      Returns:
    • eq Link icon

      public static Mat eq(Mat m1, double value)
      Create a binary image showing where an array has a specific value. The output is an 8-bit unsigned array with values 0 and 255.
      Parameters:
      m1 -
      value -
      Returns:
    • eq Link icon

      public static Mat eq(Mat m1, Mat m2)
      Create a binary image showing where two arrays have matching values. The output is an 8-bit unsigned array with values 0 and 255.
      Parameters:
      m1 -
      m2 -
      Returns:
    • geq Link icon

      public static Mat geq(Mat m1, double threshold)
      Apply a greater than or equal to threshold. The output is an 8-bit unsigned array with values 0 and 255.
      Parameters:
      m1 -
      threshold -
      Returns:
    • geq Link icon

      public static Mat geq(Mat m1, Mat m2)
      Apply a greater than or equal to threshold between two arrays. The output is an 8-bit unsigned array with values 0 and 255.
      Parameters:
      m1 -
      m2 -
      Returns:
    • lt Link icon

      public static Mat lt(Mat m1, double threshold)
      Apply a less than threshold. The output is an 8-bit unsigned array with values 0 and 255.
      Parameters:
      m1 -
      threshold -
      Returns:
    • leq Link icon

      public static Mat leq(Mat m1, Mat m2)
      Apply a less than or equal to threshold between two arrays. The output is an 8-bit unsigned array with values 0 and 255.
      Parameters:
      m1 -
      m2 -
      Returns:
    • leq Link icon

      public static Mat leq(Mat m1, double threshold)
      Apply a less than or equal to threshold. The output is an 8-bit unsigned array with values 0 and 255.
      Parameters:
      m1 -
      threshold -
      Returns:
    • lt Link icon

      public static Mat lt(Mat m1, Mat m2)
      Apply a less than threshold between two arrays. The output is an 8-bit unsigned array with values 0 and 255.
      Parameters:
      m1 -
      m2 -
      Returns:
    • asType Link icon

      public static <T> T asType(Mat mat, Class<T> cls)
      Helper method to convert a Mat to a BufferedImage, ImagePlus, ImageProcessor, double or float array using Groovy's 'as' syntax.
      Type Parameters:
      T -
      Parameters:
      mat -
      cls -
      Returns:
    • asType Link icon

      public static <T> T asType(ImageProcessor ip, Class<T> cls)
      Helper method to convert an ImageProcessor to a Mat using Groovy's 'as' syntax.
      Type Parameters:
      T -
      Parameters:
      ip -
      cls -
      Returns:
    • asType Link icon

      public static <T> T asType(ImagePlus imp, Class<T> cls)
      Helper method to convert an ImagePlus to a Mat or ImageProcessor using Groovy's 'as' syntax.
      Type Parameters:
      T -
      Parameters:
      imp -
      cls -
      Returns:
    • asType Link icon

      public static <T> T asType(BufferedImage img, Class<T> cls)
      Helper method to convert a BufferedImage to a Mat, ImageProcessor or ImagePlus using Groovy's 'as' syntax.
      Type Parameters:
      T -
      Parameters:
      img -
      cls -
      Returns:
    • asType Link icon

      public static <T> T asType(Number n, Class<T> cls)
      Helper function to convert a Number to a Mat or Scalar using Groovy's 'as' syntax.
      Type Parameters:
      T -
      Parameters:
      n -
      cls -
      Returns: