public class Stack extends Object implements Iterable<Channel>
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.
Constructor and Description |
---|
Stack()
Creates a new empty
Stack that will not become an RGB image after adding channels. |
Stack(boolean rgb)
Creates a new empty
Stack and whether it will become an RGB image or not. |
Stack(boolean rgb,
Channel... channels)
Creates from a varying number of channels, and a flag to indicate if they represent an RGB
image or not.
|
Stack(boolean rgb,
java.util.stream.Stream<Channel> stream)
Like
Stack(Stream) but allows explicitly setting whether it should be interpreted as
RGB or not. |
Stack(Channel channel)
Creates a
Stack with a single channel. |
Stack(Dimensions dimensions,
ChannelFactorySingleType factory,
int numberChannels,
boolean rgb)
Create with a particular number of empty
Channel s. |
Stack(Extent extent)
Creates a
Stack with a single unsigned-byte channel of size channel . |
Stack(java.util.stream.Stream<Channel> stream)
|
Modifier and Type | Method and Description |
---|---|
void |
addBlankChannel()
Adds a new empty
Channel in the final-most position in the list. |
void |
addChannel(Channel channel)
Appends a channel to the stack, as the new final-most channel position-wise.
|
void |
addChannelsFrom(Stack stack)
Add the channels from another instance into this instance.
|
boolean |
allChannelsHaveIdenticalType()
Determines if all channels have an identical voxel data-type.
|
boolean |
allChannelsHaveType(VoxelDataType voxelDataType)
Determines if all channels have a specific data-type.
|
List<Channel> |
asListChannels()
|
void |
assignResolution(Resolution resolution)
Assigns a new resolution.
|
Dimensions |
dimensions()
The dimensions of all channels in the stack.
|
Stack |
duplicateDeep()
Performs a deep copy of the stack, so that all channels are duplicated.
|
Stack |
duplicateShallow()
Performs a shallow copy of the stack, so that all channels are reused.
|
boolean |
equals(Object other) |
boolean |
equalsDeep(Stack other,
boolean compareResolution)
Are the two stack equal using a deep voxel by voxel comparison of each channel?
|
Extent |
extent()
The width and height and depth of the image.
|
Stack |
extractSlice(int z)
Extract a particular z-slice from the
Stack as a new stack. |
Stack |
extractUpToThreeChannels()
|
Channel |
getChannel(int index)
Returns the channel at a particular position in the stack.
|
int |
getNumberChannels()
The number of channels in the stack.
|
int |
hashCode() |
boolean |
hasMoreThanOneSlice()
Does the stack have more than one slice in the z-dimension?
|
boolean |
isAnyChannel3D()
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<Channel> |
iterator() |
Stack |
mapChannel(CheckedUnaryOperator<Channel,OperationFailedException> mapping)
Produces a new stack with a particular mapping applied to each channel.
|
Stack |
mapChannelWithIndex(CheckedBiFunction<Channel,Integer,Channel,OperationFailedException> mapping)
Produces a new stack with a particular mapping applied to each channel (with an index of the
channel also available).
|
Stack |
projectMax()
Creates a Maximum
Intensity Projection of each channel.
|
Optional<Resolution> |
resolution()
Resolution of voxels to physical measurements.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public Stack()
Stack
that will not become an RGB image after adding channels.public Stack(boolean rgb)
Stack
and whether it will become an RGB image or not.rgb
- whether the stack will represent an RGB image after adding channels.public Stack(Channel channel)
Stack
with a single channel.channel
- the channel.public Stack(Extent extent)
Stack
with a single unsigned-byte channel of size channel
.extent
- the size of the channel to create.public Stack(Dimensions dimensions, ChannelFactorySingleType factory, int numberChannels, boolean rgb) throws CreateException
Channel
s.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).CreateException
- if rgb==true
and there are not three channels.public Stack(boolean rgb, Channel... channels) throws IncorrectImageSizeException, CreateException
rgb
- true, if the channels represent an RGB image, and are in the corresponding order.channels
- the channels.IncorrectImageSizeException
- if the channels are not of uniform size.CreateException
- if rgb==true
and there are not three channels.public Stack(java.util.stream.Stream<Channel> stream) throws IncorrectImageSizeException
Stack
from a stream of Channel
s.
It is assumed these channels will not represent an RGB image.
stream
- the stream of channels.IncorrectImageSizeException
- if the channels are not of uniform size.public Stack(boolean rgb, java.util.stream.Stream<Channel> stream) throws IncorrectImageSizeException
Stack(Stream)
but allows explicitly setting whether it should be interpreted as
RGB or not.rgb
- whether to interpret the stream as RGB or not, when it is three channels.stream
- the stream of channels.IncorrectImageSizeException
- if the channels are not of uniform size.public Stack mapChannel(CheckedUnaryOperator<Channel,OperationFailedException> mapping) throws OperationFailedException
The function applied to the channel should ensure it produces uniform sizes.
mapping
- performs an operation on a channel and produces a modified channel (or a
different one entirely).mapping
) preserving the channel order.OperationFailedException
- if the channels produced have non-uniform sizes.public Stack mapChannelWithIndex(CheckedBiFunction<Channel,Integer,Channel,OperationFailedException> mapping) throws OperationFailedException
The function applied to the channel should ensure it produces uniform sizes.
mapping
- performs an operation on a channel and produces a modified channel (or a
different one entirely).mapping
) preserving the channel order.OperationFailedException
- if the channels produced have non-uniform sizes.public Stack extractSlice(int z)
Stack
as a new stack.z
- the index in the Z-dimension of the slice to extract.Stack
but reusing the existing voxels.public Stack projectMax()
Note that if the channels do not need projections, the existing Channel
is reused
in the newly created Stack
. But if a projection is needed, it is always freshly
created as a new channel.
public void addBlankChannel() throws OperationFailedException
Channel
in the final-most position in the list.
The dimensions and type of the new channel are inferred from existing channels.
OperationFailedException
- if no existing channel exists, or the existing channels lack
uniform size or type.public final void addChannel(Channel channel) throws IncorrectImageSizeException
channel
- the channel.IncorrectImageSizeException
- if channel
has a mismatching size.public final void addChannelsFrom(Stack stack) throws IncorrectImageSizeException
stack
- the stack whose Channel
s will be added to this instance.IncorrectImageSizeException
- if any channel to be added has a mismatching size.public final Channel getChannel(int index)
index
- the index (zero-indexed).IndexOutOfBoundsException
- if the index is out of range (index < 0 || index >=
size()
)public final int getNumberChannels()
public Dimensions dimensions()
public Optional<Resolution> resolution()
e.g. physical size of each voxel in a particular dimension.
public Extent extent()
i.e. the size of each of the three possible dimensions.
public Stack duplicateDeep()
public boolean isAnyChannel3D()
public Stack duplicateShallow()
public Stack extractUpToThreeChannels()
public boolean hasMoreThanOneSlice()
public boolean allChannelsHaveIdenticalType()
public boolean allChannelsHaveType(VoxelDataType voxelDataType)
voxelDataType
- the specific data-type.voxelDataType
as their voxel data-type.public boolean equalsDeep(Stack other, boolean compareResolution)
other
- the stack to compare with.compareResolution
- if true, the image-resolution is also compared for each channel.public void assignResolution(Resolution resolution)
This is a mutable operation that replaces existing state.
resolution
- the resolution to assign.public boolean isRGB()
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.
Copyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.