Package qupath.lib.images.servers
Class ServerTools
java.lang.Object
qupath.lib.images.servers.ServerTools
Static methods helpful when dealing with ImageServers.
- Author:
- Pete Bankhead
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic List
<ImageChannel> classificationLabelsToChannels
(Map<Integer, PathClass> classificationLabels, boolean ignoredTransparent) Create a list of channels from classification labels.static int
getChannelIndex
(ImageServer<?> server, String channelName) Get the index of the first channel of a server with a specified channel name.static String
Get the default shortened server name given the server's path.static String
getDisplayableImageName
(ImageServer<?> server) Get an ImageServer name suitable for displaying.static double
getDownsampleFactor
(ImageServer<?> server, double preferredPixelSizeMicrons) Calculate a downsample factor for a server given a preferred pixel size.static BufferedImage
getPaddedRequest
(ImageServer<BufferedImage> server, RegionRequest request, Padding padding) Get a raster, padded by the specified amount, to the left, right, above and below.static double
getPreferredDownsampleFactor
(ImageServer<?> server, double requestedDownsample) Get the downsample factor supported by the server that is the best match for the requested downsample.static int
getPreferredResolutionLevel
(ImageServer<?> server, double requestedDownsample) Get the preferred resolution level to request regions from an ImageServer at a specified downsample level.static boolean
setImageName
(ImageServer<?> server, String name) Set the name property of the metadata for anImageServer
.
-
Constructor Details
-
ServerTools
public ServerTools()
-
-
Method Details
-
getDefaultShortServerName
Get the default shortened server name given the server's path.- Parameters:
uri
-- Returns:
-
getChannelIndex
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
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
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, otherwiseserver.getShortServerName()
is used.- Parameters:
server
-- Returns:
-
setImageName
Set the name property of the metadata for anImageServer
.- Parameters:
server
- the server to updatename
- the new name to use- Returns:
- true if the metadata was updated, false otherwise (i.e. if the name is unchanged)
-
getDownsampleFactor
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 anIllegalArgumentException
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:
-