Class Stack
This is one of the fundamental image data structures in Anchor.
The contained channels have a particular voxel-type, but this is deliberately not exposed as a
type-parameter to Stack as data-structure, relying on the user to remain aware i.e. it is
weakly-typed.
A Channel (or any underlying voxel-buffer} should never exist more than once in a
Stack. It is assumed that each Channel has independent buffers, and if this
assumption is violated, iteration can not always proceed correctly.
- Author:
- Owen Feehan
-
Constructor Summary
ConstructorsConstructorDescriptionStack()Creates a new emptyStackthat will not become an RGB image after adding channels.Stack(boolean rgb) Creates a new emptyStackand whether it will become an RGB image or not.LikeStack(Stream)but allows explicitly setting whether it should be interpreted as RGB or not.Creates from a varying number of channels, and a flag to indicate if they represent an RGB image or not.Creates aStackwith a single channel.Stack(Dimensions dimensions, ChannelFactorySingleType factory, int numberChannels, boolean rgb) Create with a particular number of emptyChannels.Creates aStackwith a single unsigned-byte channel of sizechannel. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new emptyChannelin the final-most position in the list.final voidaddChannel(Channel channel) Appends a channel to the stack, as the new final-most channel position-wise.final voidaddChannelsFrom(Stack stack) Add the channels from another instance into this instance.booleanDetermines if all channels have an identical voxel data-type.booleanallChannelsHaveType(VoxelDataType voxelDataType) Determines if all channels have a specific data-type.voidassignResolution(Resolution resolution) Assigns a new resolution.The dimensions of all channels in the stack.Performs a deep copy of the stack, so that all channels are duplicated.Performs a shallow copy of the stack, so that all channels are reused.booleanbooleanequalsDeep(Stack other, boolean compareResolution) Are the two stack equal using a deep voxel by voxel comparison of each channel?extent()The width and height and depth of the image.extractSlice(int z) Extract a particular z-slice from theStackas a new stack.final ChannelgetChannel(int index) Returns the channel at a particular position in the stack.final intThe number of channels in the stack.inthashCode()booleanDoes the stack have more than one slice in the z-dimension?booleanIs at least one channel 3D?booleanisRGB()If true, and the stack has exactly three channels, this stack can be interpreted as a RGB image.iterator()Produces a new stack with a particular mapping applied to each channel.Produces a new stack with a particular mapping applied to each channel (with an index of the channel also available).Creates a Maximum Intensity Projection of each channel.Resolution of voxels to physical measurements.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Stack
public Stack()Creates a new emptyStackthat will not become an RGB image after adding channels. -
Stack
public Stack(boolean rgb) Creates a new emptyStackand whether it will become an RGB image or not.- Parameters:
rgb- whether the stack will represent an RGB image after adding channels.
-
Stack
Creates aStackwith a single channel.- Parameters:
channel- the channel.
-
Stack
Creates aStackwith a single unsigned-byte channel of sizechannel.- Parameters:
extent- the size of the channel to create.
-
Stack
public Stack(Dimensions dimensions, ChannelFactorySingleType factory, int numberChannels, boolean rgb) throws CreateException Create with a particular number of emptyChannels.- Parameters:
dimensions- the dimensions to use for all channels.factory- a factory to create the empty channels.numberChannels- how many channels to create.rgb- whether the channels are RGB (in which case,numberChannelsshould be 3).- Throws:
CreateException- ifrgb==trueand there are not three channels.
-
Stack
Creates from a varying number of channels, and a flag to indicate if they represent an RGB image or not.- Parameters:
rgb- true, if the channels represent an RGB image, and are in the corresponding order.channels- the channels.- Throws:
IncorrectImageSizeException- if the channels are not of uniform size.CreateException- ifrgb==trueand there are not three channels.
-
Stack
Create aStackfrom a stream ofChannels.It is assumed these channels will not represent an RGB image.
- Parameters:
stream- the stream of channels.- Throws:
IncorrectImageSizeException- if the channels are not of uniform size.
-
Stack
LikeStack(Stream)but allows explicitly setting whether it should be interpreted as RGB or not.- Parameters:
rgb- whether to interpret the stream as RGB or not, when it is three channels.stream- the stream of channels.- Throws:
IncorrectImageSizeException- if the channels are not of uniform size.
-
-
Method Details
-
mapChannel
public Stack mapChannel(CheckedUnaryOperator<Channel, OperationFailedException> mapping) throws OperationFailedExceptionProduces a new stack with a particular mapping applied to each channel.The function applied to the channel should ensure it produces uniform sizes.
- Parameters:
mapping- performs an operation on a channel and produces a modified channel (or a different one entirely).- Returns:
- a new stack (after any modification by
mapping) preserving the channel order. - Throws:
OperationFailedException- if the channels produced have non-uniform sizes.
-
mapChannelWithIndex
public Stack mapChannelWithIndex(CheckedBiFunction<Channel, Integer, throws OperationFailedExceptionChannel, OperationFailedException> mapping) Produces a new stack with a particular mapping applied to each channel (with an index of the channel also available).The function applied to the channel should ensure it produces uniform sizes.
- Parameters:
mapping- performs an operation on a channel and produces a modified channel (or a different one entirely).- Returns:
- a new stack (after any modification by
mapping) preserving the channel order. - Throws:
OperationFailedException- if the channels produced have non-uniform sizes.
-
extractSlice
Extract a particular z-slice from theStackas a new stack.- Parameters:
z- the index in the Z-dimension of the slice to extract.- Returns:
- the extracted slice, as a new
Stackbut reusing the existing voxels.
-
projectMax
Creates a Maximum Intensity Projection of each channel.Note that if the channels do not need projections, the existing
Channelis reused in the newly createdStack. But if a projection is needed, it is always freshly created as a new channel. -
addBlankChannel
Adds a new emptyChannelin the final-most position in the list.The dimensions and type of the new channel are inferred from existing channels.
- Throws:
OperationFailedException- if no existing channel exists, or the existing channels lack uniform size or type.
-
addChannel
Appends a channel to the stack, as the new final-most channel position-wise.- Parameters:
channel- the channel.- Throws:
IncorrectImageSizeException- ifchannelhas a mismatching size.
-
addChannelsFrom
Add the channels from another instance into this instance.- Parameters:
stack- the stack whoseChannels will be added to this instance.- Throws:
IncorrectImageSizeException- if any channel to be added has a mismatching size.
-
getChannel
Returns the channel at a particular position in the stack.- Parameters:
index- the index (zero-indexed).- Returns:
- the respective channel.
- Throws:
IndexOutOfBoundsException- if the index is out of range (index < 0 || index >= size())
-
getNumberChannels
public final int getNumberChannels()The number of channels in the stack.- Returns:
- the number of channels.
-
dimensions
The dimensions of all channels in the stack.- Returns:
- the dimensions.
-
resolution
Resolution of voxels to physical measurements.e.g. physical size of each voxel in a particular dimension.
- Returns:
- the resolution.
-
extent
The width and height and depth of the image.i.e. the size of each of the three possible dimensions.
- Returns:
- the extent.
-
duplicateDeep
Performs a deep copy of the stack, so that all channels are duplicated.- Returns:
- a new stack with deep-copied channels.
-
isAnyChannel3D
public boolean isAnyChannel3D()Is at least one channel 3D?- Returns:
- true if at least one channel exists with a z-size that is more than one. false otherwise (including if no channels exist).
-
duplicateShallow
Performs a shallow copy of the stack, so that all channels are reused.- Returns:
- a new stack with reused channels.
-
extractUpToThreeChannels
-
hasMoreThanOneSlice
public boolean hasMoreThanOneSlice()Does the stack have more than one slice in the z-dimension?- Returns:
- true if there is more than one z slice, false if there is 1
-
iterator
-
asListChannels
-
allChannelsHaveIdenticalType
public boolean allChannelsHaveIdenticalType()Determines if all channels have an identical voxel data-type.- Returns:
- true iff all channels have an identical voxel data-type.
-
allChannelsHaveType
Determines if all channels have a specific data-type.- Parameters:
voxelDataType- the specific data-type.- Returns:
- true iff all channels have
voxelDataTypeas their voxel data-type.
-
equals
-
equalsDeep
Are the two stack equal using a deep voxel by voxel comparison of each channel?- Parameters:
other- the stack to compare with.compareResolution- if true, the image-resolution is also compared for each channel.- Returns:
- true if they are deemed equals, false otherwise.
-
hashCode
public int hashCode() -
assignResolution
Assigns a new resolution.This is a mutable operation that replaces existing state.
- Parameters:
resolution- the resolution to assign.
-
isRGB
public boolean isRGB()If true, and the stack has exactly three channels, this stack can be interpreted as a RGB image.This is an important flag for determining how a stack is displayed visually, determining whether a stack is portrayed as a color image or composite grayscale channels.
- Returns:
- whether the stack can be interpreted as an RGB image when it has three channels.
-