Class ServerTools

java.lang.Object
qupath.lib.images.servers.ServerTools

public class ServerTools extends Object
Static methods helpful when dealing with ImageServers.
Author:
Pete Bankhead
  • Constructor Details

    • ServerTools

      public ServerTools()
  • Method Details

    • getDefaultShortServerName

      public static String getDefaultShortServerName(URI uri)
      Get the default shortened server name given the server's path.
      Parameters:
      uri -
      Returns:
    • getChannelIndex

      public static int getChannelIndex(ImageServer<?> server, String channelName)
      Get the index of the first channel of a server with a specified channel name.
      Parameters:
      server -
      channelName -
      Returns:
      index (0-based) of the first channel with a name matching channelName, or -1 if no channel is found
    • getPreferredResolutionLevel

      public static int getPreferredResolutionLevel(ImageServer<?> server, double requestedDownsample)
      Get the preferred resolution level to request regions from an ImageServer at a specified downsample level.
      Parameters:
      server -
      requestedDownsample -
      Returns:
      See Also:
    • getPreferredDownsampleFactor

      public static double getPreferredDownsampleFactor(ImageServer<?> server, double requestedDownsample)
      Get the downsample factor supported by the server that is the best match for the requested downsample.

      Generally, this will be <= the requested downsample (but it may be slightly more if the error introduced would be very small, i.e. if 4 is requested and 4.0001 is available, 4.0001 would be returned).

      Parameters:
      server -
      requestedDownsample -
      Returns:
      See Also:
    • getDisplayableImageName

      public static String getDisplayableImageName(ImageServer<?> server)
      Get an ImageServer name suitable for displaying. If the server is null, "No image" is returned. Otherwise, the name stored in the metadata is returned if not null, otherwise server.getShortServerName() is used.
      Parameters:
      server -
      Returns:
    • setImageName

      public static boolean setImageName(ImageServer<?> server, String name)
      Set the name property of the metadata for an ImageServer.
      Parameters:
      server - the server to update
      name - the new name to use
      Returns:
      true if the metadata was updated, false otherwise (i.e. if the name is unchanged)
    • getDownsampleFactor

      public static double getDownsampleFactor(ImageServer<?> server, double preferredPixelSizeMicrons)
      Calculate a downsample factor for a server given a preferred pixel size.
      Parameters:
      server -
      preferredPixelSizeMicrons -
      Returns:
    • getPaddedRequest

      public static BufferedImage getPaddedRequest(ImageServer<BufferedImage> server, RegionRequest request, Padding padding) throws IOException
      Get a raster, padded by the specified amount, to the left, right, above and below.

      Note that the padding is defined in terms of the destination pixels.

      In other words, a specified padding of 5 should actually result in 20 pixels being added in each dimension if the request.getDownsample() == 4.

      Parameters:
      server -
      request -
      padding -
      Returns:
      Throws:
      IOException
    • classificationLabelsToChannels

      public static List<ImageChannel> classificationLabelsToChannels(Map<Integer,PathClass> classificationLabels, boolean ignoredTransparent)
      Create a list of channels from classification labels. Note that the labels must be ≥ 0 or else an IllegalArgumentException will be thrown. It is also expected that the labels densely represent integer values from 0 up to some maximum, although this is not strictly enforced and channels will be generated from any missing labels.
      Parameters:
      classificationLabels -
      ignoredTransparent -
      Returns: