Class BufferedImageOverlay

All Implemented Interfaces:
ChangeListener<ImageData<BufferedImage>>, PathOverlay

public class BufferedImageOverlay extends AbstractImageOverlay implements ChangeListener<ImageData<BufferedImage>>
An overlay used to display one or more BufferedImage objects on top of a primary image shown in a viewer.

The scaling for the BufferedImage is determined by an associated ImageRegion.

Author:
Pete Bankhead
  • Constructor Details

    • BufferedImageOverlay

      public BufferedImageOverlay(QuPathViewer viewer, BufferedImage img)
      Create an overlay to show an image rescaled to overlay the entire current image in the specified viewer.
      Parameters:
      viewer -
      img -
    • BufferedImageOverlay

      public BufferedImageOverlay(QuPathViewer viewer, Map<ImageRegion,BufferedImage> map)
      Create an overlay to show an image rescaled to overlay the entire current image in the specified viewer.
      Parameters:
      viewer -
      map -
    • BufferedImageOverlay

      public BufferedImageOverlay(OverlayOptions options)
      Create an empty overlay without any images to display.
      Parameters:
      options -
    • BufferedImageOverlay

      public BufferedImageOverlay(OverlayOptions options, ImageRegion region, BufferedImage img)
      Create an overlay to display one specified image region.
      Parameters:
      options -
      region -
      img -
    • BufferedImageOverlay

      public BufferedImageOverlay(OverlayOptions options, Map<? extends ImageRegion,BufferedImage> regions)
      Create an overlay to display multiple image regions.
      Parameters:
      options -
      regions -
    • BufferedImageOverlay

      public BufferedImageOverlay(QuPathViewer viewer, OverlayOptions options, Map<? extends ImageRegion,BufferedImage> regions)
      Create an overlay to display multiple image regions.
      Parameters:
      viewer -
      options -
      regions -
  • Method Details

    • addAllRegions

      public void addAllRegions(ImageServer<BufferedImage> server, int level) throws IOException
      Add all regions for a specific level of an ImageServer. Note that this results in all regions being read immediately. Therefore it should only be used for 'small' images that can be held in main memory.
      Parameters:
      server - the server whose tiles should be drawn on the overlay
      level - the level from which to request regions; for the highest available resolution, use 0
      Throws:
      IOException
    • setColorModel

      public void setColorModel(ColorModel colorModel)
      Optionally set a custom ColorModel. This makes it possible to display the BufferedImage with a different color model than its original model.
      Parameters:
      colorModel -
    • getColorModel

      public ColorModel getColorModel()
      Returns:
      the custom color model, if any is found.
    • changed

      public void changed(ObservableValue<? extends ImageData<BufferedImage>> observable, ImageData<BufferedImage> oldValue, ImageData<BufferedImage> newValue)
      Specified by:
      changed in interface ChangeListener<ImageData<BufferedImage>>
    • getRegionMap

      public Map<ImageRegion,BufferedImage> getRegionMap()
      Get an unmodifiable Map containing image regions to paint on this overlay.
      Returns:
    • paintOverlay

      public void paintOverlay(Graphics2D g2d, ImageRegion imageRegion, double downsampleFactor, ImageData<BufferedImage> imageData, boolean paintCompletely)
      Description copied from interface: PathOverlay
      Paint the overlay to a graphics object. The graphics object will have a transform applied to it, so the painting should make use of coordinates in the original image space.
      Specified by:
      paintOverlay in interface PathOverlay
      Overrides:
      paintOverlay in class AbstractImageOverlay
      Parameters:
      g2d - Graphics2D object to which drawing should be performed. This should have any transform already applied to it.
      imageRegion - The maximum image region that should be shown.
      downsampleFactor - The downsample factor at which the overlay will be viewed. There is no need for rescaling according to this value since it has already been applied to the Graphics2D as part of its AffineTransform, however it may optionally be needed within the method e.g. to correct line thicknesses.
      imageData - the ImageData associated with this overlay. If the overlay is being displayed on a viewer, this is the ImageData open within the viewer. Not all overlays require this, and it may be null.
      paintCompletely - If true, the method is permitted to return without completely painting everything, for performance reasons.