Class LabeledImageServer

All Implemented Interfaces:
AutoCloseable, GeneratingImageServer<BufferedImage>, ImageServer<BufferedImage>

public class LabeledImageServer extends AbstractTileableImageServer implements GeneratingImageServer<BufferedImage>
A special ImageServer implementation that doesn't have a backing image, but rather constructs tiles from a PathObjectHierarchy where pixel values are integer labels corresponding stored and classified annotations.

Warning! This is intend for temporary use when exporting labelled images. No attempt is made to respond to changes within the hierarchy. For consistent results, the hierarchy must remain static for the time in which this server is being used.

  • Method Details

    • getInstanceLabels

      public Map<PathObject,Integer> getInstanceLabels()
      Get a mapping between objects and instance labels.
      Returns:
      the instance label map, or an empty map if no objects are available or LabeledImageServer.Builder.useInstanceLabels() was not selected.
    • getLabels

      public Map<PathClass,Integer> getLabels()
      Get an unmodifiable map of classifications and their corresponding labels. Note that multiple classifications may use the same integer label.
      Returns:
      a map of labels, or empty map if none are available or useInstanceLabels() was selected.
    • getBoundaryLabels

      public Map<PathClass,Integer> getBoundaryLabels()
      Get an unmodifiable map of classifications and their corresponding boundary labels, if available. Note that multiple classifications may use the same integer label.
      Returns:
      a map of boundary labels, or empty map if none are available or useInstanceLabels() was selected.
    • createServerBuilder

      protected ImageServerBuilder.ServerBuilder<BufferedImage> createServerBuilder()
      Returns null (does not support ServerBuilders).
      Specified by:
      createServerBuilder in class AbstractImageServer<BufferedImage>
      Returns:
    • getURIs

      public Collection<URI> getURIs()
      Description copied from interface: ImageServer
      Get the URIs for images required for this server. In the simplest case, this is a singleton list returning a URI representing a local file. However, some ImageServers may not have an associated URI at all, whereas others may depend upon multiple URIs (e.g. if concatenating images).

      Note: A URI alone may not be sufficient to recreate even a simple ImageServer; see ImageServer.getBuilder().

      Specified by:
      getURIs in interface ImageServer<BufferedImage>
      Returns:
    • createID

      protected String createID()
      Returns a UUID.
      Specified by:
      createID in class AbstractImageServer<BufferedImage>
      Returns:
    • isEmptyRegion

      public boolean isEmptyRegion(RegionRequest request)
      Returns true if there are no objects to be painted within the requested region.

      Specified by:
      isEmptyRegion in interface ImageServer<BufferedImage>
      Overrides:
      isEmptyRegion in class AbstractImageServer<BufferedImage>
      Parameters:
      request -
      Returns:
      API Note
      In v0.2 this performed a fast bounding box check only. In v0.3 it was updated to test ROIs fully for an intersection.
      Implementation Note
      Since v0.3 the request is expanded by the line thickness before testing intersection. In some edge cases, this might result in returning true even if nothing is drawn within the region. There remains a balance between returning quickly and giving an exact result.
    • getObjectsForRegion

      public List<PathObject> getObjectsForRegion(ImageRegion region)
      Get the objects to be painted that fall within a specified region. Note that this does not take into consideration line thickness, and therefore results are not guaranteed to match isEmptyRegion(RegionRequest); in other worse, an object might fall outside the region but still influence an image type because of thick lines being drawn. If thicker lines should influence the result, the region should be padded accordingly.
      Parameters:
      region -
      Returns:
      a list of objects with ROIs that intersect the specified region
    • getServerType

      public String getServerType()
      Description copied from interface: ImageServer
      A string describing the type of server, for example the name of the library used (Openslide, Bioformats...)
      Specified by:
      getServerType in interface ImageServer<BufferedImage>
      Returns:
    • getOriginalMetadata

      public ImageServerMetadata getOriginalMetadata()
      Description copied from interface: ImageServer
      Get the original metadata read during creation of the server. This may or may not be correct.
      Specified by:
      getOriginalMetadata in interface ImageServer<BufferedImage>
      Returns:
      See Also:
    • setMetadata

      public void setMetadata(ImageServerMetadata metadata)
      Throws an exception - metadata should not be set for a hierarchy image server directly. Any changes should be made to the underlying image server for which this server represents an object hierarchy.
      Specified by:
      setMetadata in interface ImageServer<BufferedImage>
      Overrides:
      setMetadata in class AbstractImageServer<BufferedImage>
      Parameters:
      metadata -
    • createDefaultRGBImage

      protected BufferedImage createDefaultRGBImage(int width, int height)
      Description copied from class: AbstractTileableImageServer
      Create the default (blank) RGB image for this server.

      By default this will have TYPE_INT_RGB but a subclass may change this if necessary (e.g. to incorporate an alpha channel).

      Overrides:
      createDefaultRGBImage in class AbstractTileableImageServer
      Parameters:
      width -
      height -
      Returns:
    • readTile

      protected BufferedImage readTile(TileRequest tileRequest) throws IOException
      Description copied from class: AbstractTileableImageServer
      Read a single image tile.
      Specified by:
      readTile in class AbstractTileableImageServer
      Parameters:
      tileRequest -
      Returns:
      Throws:
      IOException