Package qupath.lib.images.servers
Class TransformedServerBuilder
java.lang.Object
qupath.lib.images.servers.TransformedServerBuilder
Helper class for creating an
ImageServer
that applies one or more transforms to another (wrapped) ImageServer
.
Note: This is an early-stage experimental class, which may well change!
-
Constructor Summary
ConstructorsConstructorDescriptionTransformedServerBuilder
(ImageServer<BufferedImage> baseServer) Create a transformedImageServer
. -
Method Summary
Modifier and TypeMethodDescriptionapplyColorTransforms
(Collection<? extends ColorTransforms.ColorTransform> transforms) Apply color transforms to the image.applyColorTransforms
(ColorTransforms.ColorTransform... transforms) Apply color transforms to the image.Perform an average (mean) projection of the channels.build()
Get theImageServer
that applies the requested transforms sequentially.concatChannels
(Collection<ImageServer<BufferedImage>> additionalChannels) Concatenate a collection of additional servers along the 'channels' dimension (iteration order is used).concatChannels
(ImageServer<BufferedImage>... additionalChannels) Concatenate additional servers along the 'channels' dimension.concatToZStack
(List<ImageServer<BufferedImage>> servers) Concatenate a list of additional servers along the 'z' dimension (iteration order is used).concatToZStack
(List<ImageServer<BufferedImage>> servers, Number zSpacingMicrons) Concatenate a list of additional servers along the 'z' dimension (iteration order is used).convertType
(PixelType pixelType) Convert to the specified pixel type.crop
(ImageRegion region) Crop a specified region based on a bounding box.deconvolveStains
(ColorDeconvolutionStains stains, int... stainNumbers) Apply color deconvolution to the brightfield image, so that deconvolved stains behave as separate channels.extractChannels
(int... channels) Extract specified channels for an image.extractChannels
(String... names) Extract specified channels for an image.Perform a maximum projection of the channels.Perform a minimum projection of the channels.normalize
(BufferedImageNormalizer normalizer) Normalize the image using the provided normalizer.reorderRGB
(String order) Rearrange the channel order of an RGB image.rotate
(RotatedImageServer.Rotation rotation) Rotate the image, using an increment of 90 degrees.scaleChannels
(double... scales) Scale all channels by a constant factor.slice
(int zStart, int zEnd, int tStart, int tEnd) Slice a specific region along the z or the t axis.slice
(int zStart, int zEnd, int zStep, int tStart, int tEnd, int tStep) Slice a specific region along the z or the t axis with a step.stainNormalize
(ColorDeconvolutionStains stainsInput, ColorDeconvolutionStains stainsOutput, double... scales) Normalize stains using color deconvolution and reconvolution.subtractOffset
(double... offsets) Subtract a constant offset from all channels, without clipping.subtractOffsetAndClipZero
(double... offsets) Subtract a constant offset from all channels, clipping the result to be ≥ 0.subtractOffsetAndScale
(double[] offsets, double[] scales) Subtract a constant offset from all channels, then multiply the result by a scale factor.transform
(AffineTransform transform) Apply anAffineTransform
to the server.zProject
(ZProjectedImageServer.Projection projection) Apply a Z-projection.zProject
(ZProjectedImageServer.Projection projection, int offset) Apply a Z-projection, either from all slices or using a running projection from adjacent slices.Apply a maximum Z-projection to the image.zProjectMax
(int offset) Apply a running maximum Z-projection to the image.Apply a mean Z-projection to the image.zProjectMean
(int offset) Apply a running mean Z-projection to the image.Apply a median Z-projection to the image.zProjectMedian
(int offset) Apply a running median Z-projection to the image.Apply a minimum Z-projection to the image.zProjectMin
(int offset) Apply a running minimum Z-projection to the image.Apply a standard deviation Z-projection to the image.zProjectStandardDeviation
(int offset) Apply a running standard deviation Z-projection to the image.Apply a sum Z-projection to the image.
-
Constructor Details
-
TransformedServerBuilder
Create a transformedImageServer
.- Parameters:
baseServer
- the initial server that will be transformed.
-
-
Method Details
-
crop
Crop a specified region based on a bounding box.- Parameters:
region
- the region to crop- Returns:
- this builder
-
slice
Slice a specific region along the z or the t axis.- Parameters:
zStart
- the inclusive 0-based index of the first slice to considerzEnd
- the exclusive 0-based index of the last slide to considertStart
- the inclusive 0-based index of the first timepoint to considertEnd
- the exclusive 0-based index of the last timepoint to consider- Returns:
- this builder
- Throws:
IllegalArgumentException
- when a start index is greater than its corresponding end index
-
slice
public TransformedServerBuilder slice(int zStart, int zEnd, int zStep, int tStart, int tEnd, int tStep) Slice a specific region along the z or the t axis with a step.- Parameters:
zStart
- the inclusive 0-based index of the first slice to considerzEnd
- the exclusive 0-based index of the last slide to considerzStep
- a step to indicate which slides to considertStart
- the inclusive 0-based index of the first timepoint to considertEnd
- the exclusive 0-based index of the last timepoint to considertStep
- a step to indicate which timepoints to consider- Returns:
- this builder
- Throws:
IllegalArgumentException
- when a start index is greater than its corresponding end index, or when a step is less than or equal to 0
-
zProjectMean
Apply a mean Z-projection to the image. The projection will be calculated from all z-slices, and the resulting image will have a single z-slice.- Returns:
- this builder
-
zProjectMin
Apply a minimum Z-projection to the image. The projection will be calculated from all z-slices, and the resulting image will have a single z-slice.- Returns:
- this builder
-
zProjectMax
Apply a maximum Z-projection to the image. The projection will be calculated from all z-slices, and the resulting image will have a single z-slice.- Returns:
- this builder
-
zProjectSum
Apply a sum Z-projection to the image. The projection will be calculated from all z-slices, and the resulting image will have a single z-slice.- Returns:
- this builder
-
zProjectStandardDeviation
Apply a standard deviation Z-projection to the image. The projection will be calculated from all z-slices, and the resulting image will have a single z-slice.- Returns:
- this builder
-
zProjectMedian
Apply a median Z-projection to the image. The projection will be calculated from all z-slices, and the resulting image will have a single z-slice.- Returns:
- this builder
-
zProject
Apply a Z-projection. The projection will be calculated from all z-slices, and the resulting image will have a single z-slice.- Parameters:
projection
- a type of projection to convert the multiple z-stacks into one- Returns:
- this builder
-
zProject
Apply a Z-projection, either from all slices or using a running projection from adjacent slices.If
offset
isZProjectedImageServer.NO_RUNNING_OFFSET
, this is equivalent tozProject(ZProjectedImageServer.Projection)
and the resulting image will have a single z-slice.Otherwise, if
offset
is greater than 0, the resulting image will have the same number of z-slices as the input, where each slice is a projection using up tooffset
slices both above and below the current slice. This means that offset x 2 + 1 slices will be used for each projection, except at the edges where fewer slices will be used.- Parameters:
projection
- a type of projection to convert the multiple z-stacks into oneoffset
- the number of slices to use for the running projection (ignored for non-running projections).- Returns:
- this builder
-
zProjectMax
Apply a running maximum Z-projection to the image.- Parameters:
offset
- the number of slices to use for the running projection, orZProjectedImageServer.NO_RUNNING_OFFSET
to create a single projection from all slices.- Returns:
- this builder
- See Also:
-
zProjectMin
Apply a running minimum Z-projection to the image.- Parameters:
offset
- the number of slices to use for the running projection, orZProjectedImageServer.NO_RUNNING_OFFSET
to create a single projection from all slices.- Returns:
- this builder
- See Also:
-
zProjectMean
Apply a running mean Z-projection to the image.- Parameters:
offset
- the number of slices to use for the running projection, orZProjectedImageServer.NO_RUNNING_OFFSET
to create a single projection from all slices.- Returns:
- this builder
- See Also:
-
zProjectMedian
Apply a running median Z-projection to the image.- Parameters:
offset
- the number of slices to use for the running projection, orZProjectedImageServer.NO_RUNNING_OFFSET
to create a single projection from all slices.- Returns:
- this builder
- See Also:
-
zProjectStandardDeviation
Apply a running standard deviation Z-projection to the image.- Parameters:
offset
- the number of slices to use for the running projection, orZProjectedImageServer.NO_RUNNING_OFFSET
to create a single projection from all slices.- Returns:
- this builder
- See Also:
-
concatToZStack
Concatenate a list of additional servers along the 'z' dimension (iteration order is used).- Parameters:
servers
- the servers to concatenate- Returns:
- this builder
- Throws:
IllegalArgumentException
- if the provided images are not similar (seeZConcatenatedImageServer(List, Number)
), or if one of them have more than one z-stack
-
concatToZStack
public TransformedServerBuilder concatToZStack(List<ImageServer<BufferedImage>> servers, Number zSpacingMicrons) Concatenate a list of additional servers along the 'z' dimension (iteration order is used).- Parameters:
servers
- the servers to concatenatezSpacingMicrons
- the spacing in microns there should be between the combined images. Can be null to use the default value- Returns:
- this builder
- Throws:
IllegalArgumentException
- if the provided images are not similar (seeZConcatenatedImageServer(List, Number)
), or if one of them have more than one z-stack
-
transform
Apply anAffineTransform
to the server. Note that the transform must be invertible, otherwise andIllegalArgumentException
will be thrown.- Parameters:
transform
- the transform to apply to the image- Returns:
- this builder
-
deconvolveStains
public TransformedServerBuilder deconvolveStains(ColorDeconvolutionStains stains, int... stainNumbers) Apply color deconvolution to the brightfield image, so that deconvolved stains behave as separate channels.- Parameters:
stains
- the stains to apply for color deconvolutionstainNumbers
- the indices of the stains that should be use (an array compressing values that are 1, 2 or 3); if not specified, all 3 stains will be used.- Returns:
- this builder
-
reorderRGB
Rearrange the channel order of an RGB image. This is intended for cases where an image has wrongly been interpreted as RGB or BGR.- Parameters:
order
- a text containing the letters R, G, and B in any order- Returns:
- this builder
-
rotate
Rotate the image, using an increment of 90 degrees.- Parameters:
rotation
- the rotation to apply- Returns:
- this image
-
extractChannels
Extract specified channels for an image.- Parameters:
channels
- indices (0-based) of channels to extract.- Returns:
- this builder
-
extractChannels
Extract specified channels for an image.- Parameters:
names
- names of channels to extract.- Returns:
- this builder
-
maxChannelProject
Perform a maximum projection of the channels.- Returns:
- this builder
-
averageChannelProject
Perform an average (mean) projection of the channels.- Returns:
- this builder
-
minChannelProject
Perform a minimum projection of the channels.- Returns:
- this builder
-
concatChannels
public TransformedServerBuilder concatChannels(Collection<ImageServer<BufferedImage>> additionalChannels) Concatenate a collection of additional servers along the 'channels' dimension (iteration order is used).- Parameters:
additionalChannels
- additional servers that will be applied as channels; note that these should be of an appropriate type and dimension for concatenation.- Returns:
- this builder
-
concatChannels
Concatenate additional servers along the 'channels' dimension.- Parameters:
additionalChannels
- additional servers from which channels will be added; note that the servers should be of an appropriate type and dimension for concatenation.- Returns:
- this builder
-
subtractOffset
Subtract a constant offset from all channels, without clipping.- Parameters:
offsets
- a single offset to subtract from all channels, or an array of offsets to subtract from each channel.- Returns:
- Since:
- v0.6.0
-
subtractOffsetAndClipZero
Subtract a constant offset from all channels, clipping the result to be ≥ 0.- Parameters:
offsets
- a single offset to subtract from all channels, or an array of offsets to subtract from each channel.- Returns:
- Since:
- v0.6.0
-
subtractOffsetAndScale
Subtract a constant offset from all channels, then multiply the result by a scale factor.- Parameters:
offsets
- a single offset to subtract from all channels, or an array of offsets to subtract from each channel.scales
- a single scale factor to apply to all channels, or an array of scale factors to apply to each channel.- Returns:
- Since:
- v0.6.0
-
scaleChannels
Scale all channels by a constant factor.- Parameters:
scales
- a single scale factor to apply to all channels, or an array of scale factors to apply to each channel.- Returns:
- Since:
- v0.6.0
-
stainNormalize
public TransformedServerBuilder stainNormalize(ColorDeconvolutionStains stainsInput, ColorDeconvolutionStains stainsOutput, double... scales) Normalize stains using color deconvolution and reconvolution.- Parameters:
stainsInput
- stain vectors to apply to deconvolve the input image, which should relate to the original colorsstainsOutput
- stain vectors to apply for reconvolution, determining the output colorsscales
- optional array of scale factors to apply to each deconvolved channel. A scale factor of 1.0 will leave the channel unchanged, while a scale of 0.0 will suppress the channel.- Returns:
- Since:
- v0.6.0
-
normalize
Normalize the image using the provided normalizer.- Parameters:
normalizer
-- Returns:
- Since:
- v0.6.0
- Implementation Note
- To use this method to create an image that can be added to a project, the normalizers must be JSON-serializable
and registered under
ImageServers.getNormalizerFactory()
.
-
applyColorTransforms
public TransformedServerBuilder applyColorTransforms(Collection<? extends ColorTransforms.ColorTransform> transforms) Apply color transforms to the image.- Parameters:
transforms
- the transforms to apply- Returns:
- this builder
- Since:
- v0.6.0
-
applyColorTransforms
Apply color transforms to the image.- Parameters:
transforms
- the transforms to apply- Returns:
- this builder
- Since:
- v0.6.0
-
convertType
Convert to the specified pixel type.- Parameters:
pixelType
- the target pixel type- Returns:
- this builder
- Since:
- v0.6.0
-
build
Get theImageServer
that applies the requested transforms sequentially.
-