Class ImageJServer

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

public class ImageJServer extends AbstractImageServer<BufferedImage> implements PathObjectReader
ImageServer that uses ImageJ's image-reading capabilities.
Author:
Pete Bankhead
  • Constructor Details

    • ImageJServer

      public ImageJServer(URI uri, String... args) throws IOException
      Constructor.
      Parameters:
      uri - URI representing the local file or an ImageJ-compatible URL
      args - optional arguments (not currently used)
      Throws:
      IOException
  • Method Details

    • readPathObjects

      public Collection<PathObject> readPathObjects()
      Description copied from interface: PathObjectReader
      Read a collection of objects from the source.
      Specified by:
      readPathObjects in interface PathObjectReader
      Returns:
      a collection of objects, or empty list if no objects are available.
    • dumpMetadata

      public String dumpMetadata()
      Get a String representing the image metadata.

      Currently, this reflects the contents of the ImageJ 'Show info' command, which is tied to the 'current' slice and therefore not complete for all slices of a multichannel/multidimensional image. This behavior may change in the future.

      Returns:
      a String representing image metadata in ImageJ's own form
    • 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()
      Description copied from class: AbstractImageServer
      Create a unique ID for the server, which can be returned as the default value of AbstractImageServer.getPath(). A suggested implementation is

        getClass().getName() + ": " + URI + parameters
       
      This will be called on demand whenever AbstractImageServer.getPath() is first required.
      Specified by:
      createID in class AbstractImageServer<BufferedImage>
      Returns:
    • readRegion

      public BufferedImage readRegion(RegionRequest request)
      Description copied from interface: ImageServer
      Read a 2D(+C) image region for a specified RegionRequest. Coordinates and bounding box dimensions from the request are in pixel units, at the full image resolution (i.e. when downsample = 1).

      All channels are always returned.

      No specific checking is guaranteed to ensure that the request is valid, e.g. if it extends beyond the image boundary then it is likely (but not certain) that the returned image will be cropped accordingly - but some implementations may contain empty padding instead. Therefore it is up to the caller to ensure that the requests are within range.

      However, it is expected that any returnable region will be at least 1x1 pixel in size, even if via high downsampling one might otherwise expect a 0x0 image. This is consistent with the idea of pixels representing point samples rather than little squares.

      Note: One should avoid returning null, as this cannot be stored as a value in some map implementations that may be used for caching.

      Specified by:
      readRegion in interface ImageServer<BufferedImage>
      Parameters:
      request - the region for which pixels are requested
      Returns:
      pixels for the region being requested
      See Also:
    • convertToBufferedImage

      public static BufferedImage convertToBufferedImage(ImagePlus imp2, int z, int t, ColorModel colorModel)
      Convert an ImagePlus to a BufferedImage, for a specific z-slice and timepoint.

      Note that ImageJ uses 1-based indices for z and t! Therefore these should be >= 1.

      A ColorModel can optionally be provided; otherwise, a default ColorModel will be created for the image (with may not be particularly suitable).

      Parameters:
      imp2 -
      z -
      t -
      colorModel -
      Returns:
    • 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:
    • createServerBuilder

      protected ImageServerBuilder.ServerBuilder<BufferedImage> createServerBuilder()
      Description copied from class: AbstractImageServer
      Create a ServerBuilder, which can be used to construct an identical ImageServer. This should also include the current metadata. It is permissible to return null for an ImageServer that cannot be recreated via a ImageServerBuilder.ServerBuilder.
      Specified by:
      createServerBuilder in class AbstractImageServer<BufferedImage>
      Returns:
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Overrides:
      close in class AbstractImageServer<BufferedImage>
      Throws:
      Exception