Class AbstractImageServer<T>
- Type Parameters:
T
-
- All Implemented Interfaces:
AutoCloseable
,ImageServer<T>
- Direct Known Subclasses:
AbstractTileableImageServer
,ImageJServer
,TransformingImageServer
- Author:
- Pete Bankhead
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
protected abstract String
createID()
Create a unique ID for the server, which can be returned as the default value ofgetPath()
.protected abstract ImageServerBuilder.ServerBuilder
<T> Create a ServerBuilder, which can be used to construct an identical ImageServer.protected void
finalize()
Attempt to close the server.getAssociatedImage
(String name) Get the image for a given associated image name.Get a list of 'associated images', e.g.Get a ServerBuilder capable of building a server the same as this one.protected Map
<RegionRequest, T> getCache()
Get the internal cache.getCachedTile
(TileRequest tile) Get a cached tile, or null if the tile has not been cached.getChannel
(int channel) Request information for one channel (0-based index).getDefaultThumbnail
(int z, int t) Get the default thumbnail for a specified z-slice and timepoint.double
getDownsampleForResolution
(int level) Get the downsample factor for a specified resolution level, where level 0 is the full resolution image and nResolutions() - 1 is the lowest resolution available.int
Height of the full-resolution image in pixels.Get the class of the image representation returned by this ImageServer.Get essential metadata associated with the ImageServer as a distinct object.getPath()
Default implementation lazily callscreateID()
on demand.The bit-depth and type of the image.double[]
Request the preferred downsamples from the image metadata.protected double
getThumbnailDownsampleFactor
(int maxWidth, int maxHeight) Get a TileRequestManager that can be used to identify image tiles that may be efficiently requested from this ImageServer.int
getWidth()
Width of the full-resolution image in pixels.boolean
isEmptyRegion
(RegionRequest request) Always returns false.boolean
isRGB()
True if the image has 8-bit red, green & blue channels (and nothing else), false otherwise.int
Number of channels (3 for RGB).int
Number of resolutions for the image.int
Number of time points in a time series.int
nZSlices()
Number of slices in a z-stack.void
setMetadata
(ImageServerMetadata metadata) Set the metadata to use, e.g.toString()
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface qupath.lib.images.servers.ImageServer
getOriginalMetadata, getPixelCalibration, getServerType, getURIs, readBufferedImage, readRegion, readRegion, readRegion
-
Constructor Details
-
AbstractImageServer
-
-
Method Details
-
getImageClass
Description copied from interface:ImageServer
Get the class of the image representation returned by this ImageServer.- Specified by:
getImageClass
in interfaceImageServer<T>
- Returns:
-
getCache
Get the internal cache. This may be useful to check for the existence of a cached tile any time when speed is of the essence, and if no cached tile is available a request will not be made.- Returns:
-
getThumbnailDownsampleFactor
protected double getThumbnailDownsampleFactor(int maxWidth, int maxHeight) -
createServerBuilder
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 aImageServerBuilder.ServerBuilder
.- Returns:
-
getBuilder
Description copied from interface:ImageServer
Get a ServerBuilder capable of building a server the same as this one.The purpose of this is to aid serialization of servers by switching to a simpler representation.
The default implementation returns null, indicating that rebuilding the server is not supported.
- Specified by:
getBuilder
in interfaceImageServer<T>
- Returns:
-
getDownsampleForResolution
public double getDownsampleForResolution(int level) Description copied from interface:ImageServer
Get the downsample factor for a specified resolution level, where level 0 is the full resolution image and nResolutions() - 1 is the lowest resolution available.- Specified by:
getDownsampleForResolution
in interfaceImageServer<T>
- Parameters:
level
- Resolution level, should be 0 <= level < nResolutions().- Returns:
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
nResolutions
public int nResolutions()Description copied from interface:ImageServer
Number of resolutions for the image.This is equivalent to
getPreferredDownsamples().length
.- Specified by:
nResolutions
in interfaceImageServer<T>
- Returns:
-
getPreferredDownsamples
public double[] getPreferredDownsamples()Request the preferred downsamples from the image metadata.Note that this makes a defensive copy of the array, so it is generally preferable to use
#getDownsampleForResolution(int)
where possible.- Specified by:
getPreferredDownsamples
in interfaceImageServer<T>
- Returns:
- See Also:
-
isRGB
public boolean isRGB()Description copied from interface:ImageServer
True if the image has 8-bit red, green & blue channels (and nothing else), false otherwise.- Specified by:
isRGB
in interfaceImageServer<T>
- Returns:
-
getPixelType
Description copied from interface:ImageServer
The bit-depth and type of the image. This refers to a single channel, e.g. an 8-bit RGB image will have a type ofPixelType.UINT8
.- Specified by:
getPixelType
in interfaceImageServer<T>
- Returns:
-
finalize
Attempt to close the server. While not at all a good idea to rely on this, it may help clean up after some forgotten servers. -
isEmptyRegion
Always returns false.- Specified by:
isEmptyRegion
in interfaceImageServer<T>
- Parameters:
request
-- Returns:
-
toString
-
getCachedTile
Get a cached tile, or null if the tile has not been cached.This is useful whenever it is important to return quickly rather than wait for a tile to be fetched or generated.
Warning! The cached tile is returned directly (with no defensive copying) for performance. This means that it must not be modified by the code that requests it. If there is any chance the tile may be modified (or passed to untrusted code), then make sure to make a defensive copy, e.g. using
BufferedImageTools.duplicate(java.awt.image.BufferedImage)
if using a buffered image.- Specified by:
getCachedTile
in interfaceImageServer<T>
- Parameters:
tile
-- Returns:
- the tile if it has been cached, or null if no cached tile is available for the request.
-
createID
Create a unique ID for the server, which can be returned as the default value ofgetPath()
. A suggested implementation isgetClass().getName() + ": " + URI + parameters
This will be called on demand whenevergetPath()
is first required.- Returns:
-
getPath
Default implementation lazily callscreateID()
on demand.- Specified by:
getPath
in interfaceImageServer<T>
- Returns:
- See Also:
-
getWidth
public int getWidth()Description copied from interface:ImageServer
Width of the full-resolution image in pixels.- Specified by:
getWidth
in interfaceImageServer<T>
- Returns:
-
getHeight
public int getHeight()Description copied from interface:ImageServer
Height of the full-resolution image in pixels.- Specified by:
getHeight
in interfaceImageServer<T>
- Returns:
-
nChannels
public int nChannels()Description copied from interface:ImageServer
Number of channels (3 for RGB).- Specified by:
nChannels
in interfaceImageServer<T>
- Returns:
-
nZSlices
public int nZSlices()Description copied from interface:ImageServer
Number of slices in a z-stack.- Specified by:
nZSlices
in interfaceImageServer<T>
- Returns:
-
nTimepoints
public int nTimepoints()Description copied from interface:ImageServer
Number of time points in a time series.- Specified by:
nTimepoints
in interfaceImageServer<T>
- Returns:
-
getMetadata
Description copied from interface:ImageServer
Get essential metadata associated with the ImageServer as a distinct object. This may be edited by the user.- Specified by:
getMetadata
in interfaceImageServer<T>
- Returns:
- See Also:
-
setMetadata
Description copied from interface:ImageServer
Set the metadata to use, e.g. to change the pixel size in microns.- Specified by:
setMetadata
in interfaceImageServer<T>
- Parameters:
metadata
-
-
getAssociatedImageList
Description copied from interface:ImageServer
Get a list of 'associated images', e.g. thumbnails or slide overview images.Each associated image is simply a T that does not warrant (or require) a full ImageServer, and most likely would never be analyzed.
- Specified by:
getAssociatedImageList
in interfaceImageServer<T>
- Returns:
- See Also:
-
getAssociatedImage
Description copied from interface:ImageServer
Get the image for a given associated image name.- Specified by:
getAssociatedImage
in interfaceImageServer<T>
- Parameters:
name
-- Returns:
- See Also:
-
getChannel
Description copied from interface:ImageServer
Request information for one channel (0-based index).- Specified by:
getChannel
in interfaceImageServer<T>
- Parameters:
channel
-- Returns:
- See Also:
-
getDefaultThumbnail
Description copied from interface:ImageServer
Get the default thumbnail for a specified z-slice and timepoint.This should be the lowest resolution image that is available in the case of the multiresolution image, or else the full image. For large datasets, it may be used to determine basic statistics or histograms without requiring every pixel to be visited in the full resolution image.
- Specified by:
getDefaultThumbnail
in interfaceImageServer<T>
- Parameters:
z
-t
-- Returns:
- Throws:
IOException
-
getTileRequestManager
Description copied from interface:ImageServer
Get a TileRequestManager that can be used to identify image tiles that may be efficiently requested from this ImageServer.This is useful because managing arbitrary RegionRequests can result in inefficiencies if a request straddles multiple tiles unnecessarily. Also, it can be used to help ensure consistency whenever requesting regions at different resolutions, where rounding errors might otherwise occur.
Note that the TileRequestManager is not guaranteed to remain the same for the lifecycle of the server. For example, if the image metadata is changed then a new manager may be constructed.
- Specified by:
getTileRequestManager
in interfaceImageServer<T>
- Returns:
-