Class NumpyTools

java.lang.Object
qupath.opencv.tools.NumpyTools

public class NumpyTools extends Object
Read .npy and .npz files from NumPy.

Note that only a subset of files are supported. Specifically, each .npy file should contain a single (possibly multidimensional) array with a type supported by OpenCV.

Structured, complex and object arrays are not supported.

See https://numpy.org/devdocs/reference/generated/numpy.lib.format.html for more information about the format.

Since:
v0.4.0
Author:
Pete Bankhead
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Map<String,Mat>
    Read a all Mats from an .npy or .npz file.
    static Map<String,Mat>
    readAllMats(String path, boolean squeezeDimensions)
    Read a all Mats from an .npy or .npz file, optionally squeezing singleton dimensions.
    static Map<String,Mat>
    Read a all Mats from an .npy or .npz path.
    static Map<String,Mat>
    readAllMats(Path path, boolean squeezeDimensions)
    Read a all Mats from an .npy or .npz path, optionally squeezing singleton dimensions This will be a single Mat for .npy but may be multiple for .npz.
    static Mat
    readMat(InputStream stream, boolean squeezeDimensions)
    Read a single Mat from an input stream, which should follow the .npy file format specification.
    static Mat
    Read a single Mat from an .npy or .npz file.
    static Mat
    readMat(String path, boolean squeezeDimensions)
    Read a single Mat from an .npy or .npz file, optionally squeezing singleton dimensions.
    static Mat
    readMat(Path path)
    Read an OpenCV Mat from a Numpy .npy file.
    static Mat
    readMat(Path path, boolean squeezeDimensions)
    Read an OpenCV Mat from a Numpy .npy file, optionally squeezing singleton dimensions.

    Methods inherited from class java.lang.Object

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

    • NumpyTools

      public NumpyTools()
  • Method Details

    • readMat

      public static Mat readMat(String path) throws IOException
      Read a single Mat from an .npy or .npz file.
      Parameters:
      path -
      Returns:
      Throws:
      IOException
    • readMat

      public static Mat readMat(String path, boolean squeezeDimensions) throws IOException
      Read a single Mat from an .npy or .npz file, optionally squeezing singleton dimensions.
      Parameters:
      path - path to the .npy file
      squeezeDimensions - if true, squeeze singleton dimensions
      Returns:
      Throws:
      IOException
    • readAllMats

      public static Map<String,Mat> readAllMats(String path) throws IOException
      Read a all Mats from an .npy or .npz file. This will be a single Mat for .npy but may be multiple for .npz.
      Parameters:
      path - path to the file
      Returns:
      a map with mat names (from file/entry names) and their corresponding Mats
      Throws:
      IOException
    • readAllMats

      public static Map<String,Mat> readAllMats(String path, boolean squeezeDimensions) throws IOException
      Read a all Mats from an .npy or .npz file, optionally squeezing singleton dimensions. This will be a single Mat for .npy but may be multiple for .npz.
      Parameters:
      path - path to the file
      squeezeDimensions - if true, squeeze singleton dimensions
      Returns:
      a map with mat names (from file/entry names) and their corresponding Mats
      Throws:
      IOException
    • readAllMats

      public static Map<String,Mat> readAllMats(Path path) throws IOException
      Read a all Mats from an .npy or .npz path. This will be a single Mat for .npy but may be multiple for .npz.
      Parameters:
      path - path to the file
      Returns:
      a map with mat names (from file/entry names) and their corresponding Mats
      Throws:
      IOException
    • readAllMats

      public static Map<String,Mat> readAllMats(Path path, boolean squeezeDimensions) throws IOException
      Read a all Mats from an .npy or .npz path, optionally squeezing singleton dimensions This will be a single Mat for .npy but may be multiple for .npz.
      Parameters:
      path - path to the file
      squeezeDimensions - if true, squeeze singleton dimensions
      Returns:
      a map with mat names (from file/entry names) and their corresponding Mats
      Throws:
      IOException
    • readMat

      public static Mat readMat(Path path) throws IOException
      Read an OpenCV Mat from a Numpy .npy file.
      Parameters:
      path - path to the .npy file
      Returns:
      Throws:
      IOException - if a Mat could not be read from the given path
    • readMat

      public static Mat readMat(Path path, boolean squeezeDimensions) throws IOException
      Read an OpenCV Mat from a Numpy .npy file, optionally squeezing singleton dimensions.
      Parameters:
      path - path to the .npy file
      squeezeDimensions - if true, squeeze singleton dimensions
      Returns:
      Throws:
      IOException - if a Mat could not be read from the given path
    • readMat

      public static Mat readMat(InputStream stream, boolean squeezeDimensions) throws IOException
      Read a single Mat from an input stream, which should follow the .npy file format specification.
      Parameters:
      stream -
      squeezeDimensions -
      Returns:
      Throws:
      IOException