Class TileExporter

java.lang.Object
qupath.lib.images.writers.TileExporter

public class TileExporter extends Object
Helper class for exporting image tiles, typically for further analysis elsewhere or for training up an AI algorithm.
Author:
Pete Bankhead
  • Constructor Details

    • TileExporter

      public TileExporter(ImageData<BufferedImage> imageData)
      Create a builder to export tiles.
      Parameters:
      imageData -
  • Method Details

    • parentObjects

      public TileExporter parentObjects(Predicate<PathObject> filter)
      Specify a filter to extract parent objects to define tiles. Tiles are either generated based upon the ROI centroid (in which case the specified tile size is respected) or the ROI bounding box (with the specified tile size ignored).
      Parameters:
      filter -
      Returns:
      this exporter
      See Also:
    • parentObjects

      public TileExporter parentObjects(Collection<? extends PathObject> parentObjects)
      Specify parent objects to define tiles. Tiles are either generated based upon the ROI centroid (in which case the specified tile size is respected) or the ROI bounding box (with the specified tile size ignored).
      Parameters:
      parentObjects -
      Returns:
      this exporter
      See Also:
    • useROIBounds

      public TileExporter useROIBounds(boolean fullROIs)
      Optionally use the full ROI for parent objects, rather than tileSize(int, int).
      Parameters:
      fullROIs - if true, use the bounding box of the ROI
      Returns:
      this exporter
      See Also:
    • fullImageTile

      public TileExporter fullImageTile()
      Specify that a single tile should be generated corresponding to the full image.
      Returns:
      this exporter
    • tileSize

      public TileExporter tileSize(int tileSize)
      Define the tile size in pixel units at the export resolution.
      Parameters:
      tileSize -
      Returns:
      this exporter
    • tileSize

      public TileExporter tileSize(int tileWidth, int tileHeight)
      Define the horizontal and vertical tile size in pixel units at the export resolution.
      Parameters:
      tileWidth -
      tileHeight -
      Returns:
      this exporter
    • channels

      public TileExporter channels(int... channels)
      Export only specified channels.

      Note: currently, this always involved conversion to 32-bit. This behavior may change in a future version of QuPath to preserve image type.

      Parameters:
      channels - channels to export (0-based indexing)
      Returns:
      this exporter
    • channels

      public TileExporter channels(String... channelNames)
      Export only specified channels, identified by name.

      Note: currently, this always involved conversion to 32-bit. This behavior may change in a future version of QuPath to preserve image type.

      Parameters:
      channelNames - channels to export
      Returns:
      this exporter
    • overlap

      public TileExporter overlap(int overlap)
      Define tile overlap (both x and y) in pixel units at the export resolution. This is ignored if 'parentObjects' are specified.
      Parameters:
      overlap -
      Returns:
      this exporter
    • overlap

      public TileExporter overlap(int overlapX, int overlapY)
      Define tile overlap (x and y separately) in pixel units at the export resolution. This is ignored if 'parentObjects' are specified.
      Parameters:
      overlapX -
      overlapY -
      Returns:
      this exporter
    • downsample

      public TileExporter downsample(double downsample)
      Define resolution as a downsample value.
      Parameters:
      downsample -
      Returns:
      this exporter
      See Also:
    • requestedPixelSize

      public TileExporter requestedPixelSize(double pixelSize)
      Define resolution as a pixel size in calibrated units. The actual units depend upon those stored within the server.
      Parameters:
      pixelSize -
      Returns:
      this exporter
    • includePartialTiles

      public TileExporter includePartialTiles(boolean includePartialTiles)
      Specify whether incomplete tiles at image boundaries should be included.

      If true, then when tiling the entire image some tiles may not have the specified tile width or height, or alternatively when creating tiles based upon object centroids then some zero-padding may be required to ensure the center is preserved along with the tile dimensions. Default is false.

      Parameters:
      includePartialTiles -
      Returns:
      this exporter
      See Also:
    • region

      public TileExporter region(RegionRequest region)
      Define the region to be processed, including downsample. Default is the full image.
      Parameters:
      region -
      Returns:
      this exporter
      See Also:
    • region

      public TileExporter region(ImageRegion region)
      Define the region to be processed. Default is the full image.
      Parameters:
      region -
      Returns:
      this exporter
      See Also:
    • zRange

      public TileExporter zRange(int minZ, int maxZ)
      Define the range of Z-slices to process. Default is all Z-slices (0 to nZSlices).

      Note: the range is from minZ (included) to maxZ (excluded). -1 can be used for maxZ to process all Z-slices without having to indicate the exact max number.

      Parameters:
      minZ - the lower value (included)
      maxZ - the higher value (excluded)
      Returns:
      this exporter
    • tRange

      public TileExporter tRange(int minT, int maxT)
      Define the range of timepoints to process. Default is all timepoints (0 to nTimepoints).

      Note: the range is from minT (included) to maxT (excluded). -1 can be used for maxT to process all timepoints without having to indicate the exact max number.

      Parameters:
      minT - the lower value (included)
      maxT - the higher value (excluded)
      Returns:
      this exporter
    • annotatedTilesOnly

      public TileExporter annotatedTilesOnly(boolean annotatedTilesOnly)
      Specify whether tiles that do not overlap with any annotations should be included. This is a weaker criterion than annotatedCentroidTilesOnly(boolean).

      Default is false.

      Parameters:
      annotatedTilesOnly -
      Returns:
      this exporter
      See Also:
    • annotatedCentroidTilesOnly

      public TileExporter annotatedCentroidTilesOnly(boolean annotatedCentroidTilesOnly)
      Specify whether tiles without any annotations over the tile centroid should be included. This is a stronger criterion than annotatedTilesOnly(boolean), i.e. it will exclude more tiles.

      Default is false.

      Parameters:
      annotatedCentroidTilesOnly -
      Returns:
      this exporter
      See Also:
    • imageExtension

      public TileExporter imageExtension(String ext)
      Specify a file extension for the original pixels, which determines the export file format.
      Parameters:
      ext -
      Returns:
      this exporter
    • labeledImageExtension

      public TileExporter labeledImageExtension(String ext)
      Specify a file extension for the labelled image, which determines the export file format.
      Parameters:
      ext -
      Returns:
      this exporter
    • labeledServer

      public TileExporter labeledServer(ImageServer<BufferedImage> server)
      Optional server providing image labels. These may be export as corresponding images alongside the 'original' pixels, e.g. to create training data for an AI algorithm.
      Parameters:
      server - the labeled server
      Returns:
      this exporter
    • imageSubDir

      public TileExporter imageSubDir(String subdir)
      Specify a subdirectory within which image tiles should be saved. By default, tiles are written to the directory specified within writeTiles(String). This option makes it possible to split images and labels into separate subdirectories.
      Parameters:
      subdir -
      Returns:
      this exporter
    • labeledImageSubDir

      public TileExporter labeledImageSubDir(String subdir)
      Specify a subdirectory within which labeled image tiles should be saved. By default, tile labels are written to the directory specified within writeTiles(String). This option makes it possible to split images and labels into separate subdirectories.

      Only relevant if labeledServer(ImageServer) is provided.

      Parameters:
      subdir -
      Returns:
      this exporter
    • labeledImageId

      public TileExporter labeledImageId(String labelId)
      Specify an identifier appended to the filename for labeled images. The labeled image name will be in the format imageName + labeledImageId + labeledImageExtension.

      This can be used to avoid name clashes with export image tiles. If not specified, QuPath will generate a default ID if required.

      Only relevant if labeledServer(ImageServer) is provided.

      Parameters:
      labelId -
      Returns:
      this exporter
    • exportJson

      public TileExporter exportJson(boolean exportJson)
      Optionally export a JSON file that includes label information and image/label pairs, where available.
      Parameters:
      exportJson -
      Returns:
      this exporter
    • writeTiles

      public void writeTiles(String dirOutput) throws IOException
      Export the image tiles to the specified directory.
      Parameters:
      dirOutput - full path to the export directory
      Throws:
      IOException - if an error occurs during export