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 emptyStack
that will not become an RGB image after adding channels.Stack
(boolean rgb) Creates a new emptyStack
and 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 aStack
with a single channel.Stack
(Dimensions dimensions, ChannelFactorySingleType factory, int numberChannels, boolean rgb) Create with a particular number of emptyChannel
s.Creates aStack
with a single unsigned-byte channel of sizechannel
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a new emptyChannel
in the final-most position in the list.final void
addChannel
(Channel channel) Appends a channel to the stack, as the new final-most channel position-wise.final void
addChannelsFrom
(Stack stack) Add the channels from another instance into this instance.boolean
Determines if all channels have an identical voxel data-type.boolean
allChannelsHaveType
(VoxelDataType voxelDataType) Determines if all channels have a specific data-type.void
assignResolution
(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.boolean
boolean
equalsDeep
(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 theStack
as a new stack.final Channel
getChannel
(int index) Returns the channel at a particular position in the stack.final int
The number of channels in the stack.int
hashCode()
boolean
Does the stack have more than one slice in the z-dimension?boolean
Is at least one channel 3D?boolean
isRGB()
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, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Stack
public Stack()Creates a new emptyStack
that will not become an RGB image after adding channels. -
Stack
public Stack(boolean rgb) Creates a new emptyStack
and whether it will become an RGB image or not.- Parameters:
rgb
- whether the stack will represent an RGB image after adding channels.
-
Stack
Creates aStack
with a single channel.- Parameters:
channel
- the channel.
-
Stack
Creates aStack
with 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 emptyChannel
s.- 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,numberChannels
should be 3).- Throws:
CreateException
- ifrgb==true
and 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==true
and there are not three channels.
-
Stack
Create aStack
from a stream ofChannel
s.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 theStack
as a new stack.- Parameters:
z
- the index in the Z-dimension of the slice to extract.- Returns:
- the extracted slice, as a new
Stack
but reusing the existing voxels.
-
projectMax
Creates a Maximum Intensity Projection of each channel.Note that if the channels do not need projections, the existing
Channel
is reused in the newly createdStack
. But if a projection is needed, it is always freshly created as a new channel. -
addBlankChannel
Adds a new emptyChannel
in 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
- ifchannel
has a mismatching size.
-
addChannelsFrom
Add the channels from another instance into this instance.- Parameters:
stack
- the stack whoseChannel
s 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
voxelDataType
as 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.
-