Class ImageData<T>

java.lang.Object
qupath.lib.images.ImageData<T>
Type Parameters:
T -
All Implemented Interfaces:
AutoCloseable, EventListener, PathObjectHierarchyListener, WorkflowListener

public class ImageData<T> extends Object implements WorkflowListener, PathObjectHierarchyListener, AutoCloseable
Class that brings together the main data in connection with the analysis of a single image.

Currently, this is really the server (to access the image & its pixels) and the object hierarchy that represents detections. In addition, there is an ImageType - as some options may change depending on this.

One particularly significant example is that of Brightfield images in pathology, for which stain vectors are often required for effective stain separation.

  • Constructor Details

    • ImageData

      public ImageData(ImageServerBuilder.ServerBuilder<T> serverBuilder, PathObjectHierarchy hierarchy, ImageData.ImageType type)
      Create a new ImageData with a lazily-loaded server, hierarchy and type. The server builder provides the ImageServer required to access pixels and metadata on demand.

      If the server is never requested, then the builder is not used - which can save time and resources.

      Parameters:
      serverBuilder - builder to create the ImageServer
      hierarchy - an object hierarchy, or null to create a new one
      type - the image type, or null to default to ImageType.UNSET
    • ImageData

      public ImageData(ImageServer<T> server, PathObjectHierarchy hierarchy, ImageData.ImageType type)
      Create a new ImageData with a specified server, hierarchy and type.
      Parameters:
      server - server to use to access pixels and metadata
      hierarchy - an object hierarchy, or null to create a new one
      type - the image type, or null to default to ImageType.UNSET
    • ImageData

      public ImageData(ImageServer<T> server, ImageData.ImageType type)
      Create a new ImageData with a specified type and creating a new object hierarchy.
      Parameters:
      server -
      type -
    • ImageData

      public ImageData(ImageServer<T> server, PathObjectHierarchy hierarchy)
      Create a new ImageData with ImageType.UNKNOWN.
      Parameters:
      server -
      hierarchy -
    • ImageData

      public ImageData(ImageServer<T> server)
      Create a new ImageData with ImageType.UNKNOWN and a new PathObjectHierarchy.
      Parameters:
      server -
  • Method Details

    • getHistoryWorkflow

      public Workflow getHistoryWorkflow()
      Get a workflow representing a history of the processing steps applied to the ImageData.
      Returns:
    • setColorDeconvolutionStains

      public void setColorDeconvolutionStains(ColorDeconvolutionStains stains)
      Set the color deconvolution stain vectors for the current image type.

      If the type is not brightfield, an IllegalArgumentException is thrown.

      Parameters:
      stains -
    • updateServerMetadata

      public void updateServerMetadata(ImageServerMetadata newMetadata)
      Update the ImageServer metadata. The benefit of using this method rather than manipulating the ImageServer directly is that it will fire a property change.
      Parameters:
      newMetadata -
    • getServerMetadata

      public ImageServerMetadata getServerMetadata()
      Get the metadata for the server.

      This is equivalent to getServer().getMetadata(), unless the server is being loaded lazily and it is possible to query the metadata without loading the server.

      Returns:
    • isBrightfield

      public boolean isBrightfield()
      Returns true if the image type is set to brightfield.
      Returns:
    • isFluorescence

      public boolean isFluorescence()
      Returns true if the image type is set to fluorescence.
      Returns:
    • setImageType

      public void setImageType(ImageData.ImageType type) throws IllegalArgumentException
      Set the image type.
      Parameters:
      type - the type of the image
      Throws:
      IllegalArgumentException - if the type is not supported by the image; specifically, brightfield types using color deconvolution stains are currently only supported for RGB images.
    • isLoaded

      public boolean isLoaded()
      Query whether the corresponding ImageServer was lazy-loaded or not, If isLoaded() returns false, then calls to getServer() will result in an attempt to load the server.
      Returns:
    • getServerBuilder

      public ImageServerBuilder.ServerBuilder<T> getServerBuilder()
      Get the ServerBuilde corresponding to the ImageServer associated with this ImageData.

      If the server has not yet been loaded, this will return a cached server builder if it is available and null otherwise.

      Returns:
      See Also:
    • getServer

      public ImageServer<T> getServer()
      Get the ImageServer, loading it if necessary.

      If no server is available and loading fails, this method may throw an unchecked exception.

      Returns:
    • getServerPath

      public String getServerPath()
      Get the path of the ImageServer.
      Returns:
    • getHierarchy

      public PathObjectHierarchy getHierarchy()
      Get the object hierarchy.
      Returns:
    • getImageType

      public ImageData.ImageType getImageType()
      Get the image type
      Returns:
    • getColorDeconvolutionStains

      public ColorDeconvolutionStains getColorDeconvolutionStains()
      Get the stains defined for this image, or null if this is not a brightfield image suitable for color deconvolution.
      Returns:
    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener listener)
      Add a new property change listener.
      Parameters:
      listener -
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener listener)
      Remove a property change listener.
      Parameters:
      listener -
    • getProperty

      public Object getProperty(String key)
      Get a specified property.
      Parameters:
      key -
      Returns:
    • setProperty

      public Object setProperty(String key, Object value)
      Set a property. Note that if properties are Serializable, they will be included in associated data files - otherwise they are stored only transiently.
      Parameters:
      key -
      value -
      Returns:
    • removeProperty

      public Object removeProperty(String key)
      Remove a specified property.
      Parameters:
      key -
      Returns:
    • getProperties

      public Map<String,Object> getProperties()
      Get an unmodifiable map representing all known properties for this ImageData.
      Returns:
    • getLastSavedPath

      public String getLastSavedPath()
      Get the last path used to save this object;
      Returns:
    • isChanged

      public boolean isChanged()
      Returns true if changes have been recorded since the last time this object was notified that it was saved.
      Returns:
      See Also:
    • setChanged

      public void setChanged(boolean isChanged)
      Set isChanged() status.
      Parameters:
      isChanged -
    • setLastSavedPath

      public void setLastSavedPath(String path, boolean resetChanged)
      Set the last path used to save this object;
      Parameters:
      path -
      resetChanged - If true, then the isChanged() flag will be reset to false;
    • hierarchyChanged

      public void hierarchyChanged(PathObjectHierarchyEvent event)
      Description copied from interface: PathObjectHierarchyListener
      Notify listeners of a change in the hierarchy or its objects.
      Specified by:
      hierarchyChanged in interface PathObjectHierarchyListener
      Parameters:
      event -
    • workflowUpdated

      public void workflowUpdated(Workflow workflow)
      Description copied from interface: WorkflowListener
      Called whenever a Workflow has been updated in some way, such as a new step added.
      Specified by:
      workflowUpdated in interface WorkflowListener
      Parameters:
      workflow -
    • close

      public void close() throws Exception
      Close the server if it has been loaded. Note that this should not be called if the server is still in use.
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • toString

      public String toString()
      Overrides:
      toString in class Object