Class RGBStack

Object
RGBStack
All Implemented Interfaces:
Iterable<Channel>

public class RGBStack extends Object implements Iterable<Channel>
A stack with exactly three channels, respectively for red, green and blue colors.
Author:
Owen Feehan
  • Constructor Details

    • RGBStack

      public RGBStack(Extent extent)
      Creates a particularly-sized stack with unsigned byte voxel data type, with all voxels initialized to 0.
      Parameters:
      extent - size of each channel.
    • RGBStack

      public RGBStack(Extent extent, Color color)
      Creates a particularly-sized stack with unsigned byte voxel data type, with all voxels initialized to a specific Color.
      Parameters:
      extent - size of each channel.
      color - the color to assign to all voxels.
    • RGBStack

      public RGBStack(Extent extent, RGBColor color)
      Creates a particularly-sized stack with unsigned byte voxel data type, with all voxels initialized to a specific RGBColor.
      Parameters:
      extent - size of each channel.
      color - the color to assign to all voxels.
    • RGBStack

      public RGBStack(Extent extent, ChannelFactorySingleType factory)
      Creates a particularly-sized stack with all channels initialized to 0.
      Parameters:
      extent - size of each channel.
      factory - factory to create the channel.
    • RGBStack

      public RGBStack(Dimensions dimensions, ChannelFactorySingleType factory)
      Creates a particularly-sized stack with all channels initialized to 0.
      Parameters:
      dimensions - dimensions of each channel.
      factory - factory to create the channel.
    • RGBStack

      public RGBStack(Stack stack)
      Creates from an existing stack (which must have 1 or 3 channels).

      The channel order is: red, green, blue.

      A single channel is treated as grayscale, and duplicated to form red, green, blue channels.

      Parameters:
      stack - the stack.
    • RGBStack

      public RGBStack(Channel red, Channel green, Channel blue) throws IncorrectImageSizeException
      Create with Channels for each color.
      Parameters:
      red - the red channel.
      green - the green channel.
      blue - the blue channel.
      Throws:
      IncorrectImageSizeException - if the channels are not uniformly sized.
  • Method Details

    • mapChannel

      Produces 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.
    • red

      public Channel red()
      The red channel.
      Returns:
      the red channel.
    • green

      public Channel green()
      The green channel.
      Returns:
      the green channel.
    • blue

      public Channel blue()
      The blue channel.
      Returns:
      the blue channel.
    • getChannel

      public Channel getChannel(int index)
      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())
    • dimensions

      public Dimensions dimensions()
      The dimensions of all channels in the stack.
      Returns:
      the dimensions.
    • extractSlice

      public RGBStack extractSlice(int z)
      Extract a particular z-slice from the Stack 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.
    • asStack

      public Stack asStack()
      Exposes the underlying stack, storing the three RGB channels in respective order.
      Returns:
      the stack.
    • duplicate

      public RGBStack duplicate()
      A deep copy.
      Returns:
      a deep copy of the current instance.
    • allChannelsHaveType

      public boolean allChannelsHaveType(VoxelDataType channelDataType)
      Determines if all channels have a specific data-type.
      Parameters:
      channelDataType - the specific data-type.
      Returns:
      true iff all channels have channelDataType as their voxel data-type.
    • assignVoxel

      public void assignVoxel(Point3i point, RGBColor color)
      Assigns a RGBColor to a single voxel in the respective channels.
      Parameters:
      point - identifies which voxel to assign the color value to.
      color - the color.
      Throws:
      IllegalArgumentException - if the stack has a channel that is not UnsignedByteVoxelType.
    • assignAllVoxels

      public void assignAllVoxels(RGBColor color)
      Assigns a RGBColor to all voxels in the respective channels.
      Parameters:
      color - the color.
      Throws:
      IllegalArgumentException - if the stack has a channel that is not UnsignedByteVoxelType.
    • colorAtVoxel

      public RGBColor colorAtVoxel(ReadableTuple3i point)
      Gets the color at a particular voxel.

      Note that it is inefficient to call this method on voxels repeatedly, as it is heavy on memory allocation on the heap, and makes inefficient usage of buffer iteration. A new RGBColor is created with each call. Prefer iterating the voxels via getChannel(int).

      Parameters:
      point - locates the voxel (zero-indexed) in the stack.
      Returns:
      a newly created RGBColor, indicating the color at a particular voxel.
    • objectWithColor

      public Optional<ObjectMask> objectWithColor(RGBColor color) throws OperationFailedException
      Extracts an ObjectMask from a Channel of all voxels that have a particular color.

      This operation is only supported when all channels have type unsigned-byte.

      The bounding-box of the created ObjectMask will fit the voxels as maximally tightly as possible.

      Parameters:
      color - the color to search for.
      Returns:
      an ObjectMask describing all voxels with this color, if any exist. If no exist, then Optional.empty().
      Throws:
      OperationFailedException - if any channel has a data-type other than unsigned-byte.
    • extent

      public Extent extent()
      The width and height and depth of the image.

      i.e. the size of each of the three possible dimensions.

      Returns:
      the extent.
    • sliceBuffer

      public UnsignedByteBuffer sliceBuffer(int channelIndex, int zIndex)
      A buffer corresponding to a particular z-slice of a particular channel.

      This buffer is either a NIO class or another class that wraps the underlying array storing voxel intensities.

      Parameters:
      channelIndex - the index (beginning at 0) of the respective channel.
      zIndex - the index (beginning at 0) of the respective z-slice.
      Returns:
      the corresponding buffer for z.
    • iterator

      public Iterator<Channel> iterator()
      Specified by:
      iterator in interface Iterable<Channel>