Object
Mask

public class Mask extends Object
A channel whose voxel-values are restricted to two states (on and off).

This is one of Anchor's core data-objects.

Author:
Owen Feehan
  • Constructor Details

    • Mask

      public Mask(Channel channel)
      Creates a mask from an existing channel using default values for off (0) and on (255).

      The channel should have maximally two distinct intensity values, represeting off and on states.

      Precondition: no check occurs that only off and on voxels exist in a channel, so please call only with valid input.

      Parameters:
      channel - the channel to form the mask, whose voxel-buffer is reused internally in the mask
    • Mask

      public Mask(Channel channel, BinaryValuesInt binaryValues)
      Creates a mask from an existing channel.

      The channel should have maximally two distinct intensity values, represeting off and ON states.

      Precondition: no check occurs that only off and on voxels exist in a channel, so please call only with valid input.

      Parameters:
      channel - the channel to form the mask, whose voxel-buffer is reused internally in the mask
      binaryValues - how to identify the off and on states from intensity voxel-values
    • Mask

      public Mask(BinaryVoxels<UnsignedByteBuffer> voxels)
      Creates a mask from an existing binary-voxels using default image resolution.
      Parameters:
      voxels - the BinaryVoxels to be reused as the internal buffer of the mask
    • Mask

      public Mask(BinaryVoxels<UnsignedByteBuffer> voxels, Optional<Resolution> resolution)
      Creates a mask from an existing binary-voxels and a specific image resolution.
      Parameters:
      voxels - the binary-voxels to be reused as the internal buffer of the mask.
      resolution - the image-resolution to assign.
    • Mask

      public Mask(Dimensions dimensions, BinaryValuesInt binaryValues)
      Creates a new empty mask of particular dimensions and with particular BinaryValuesInt.

      Default mask values for off (0) and on (255) are employed.

      Parameters:
      dimensions - the dimensions for the newly-created mask.
      binaryValues - the binary-values to use for the newly created mask.
  • Method Details

    • dimensions

      public Dimensions dimensions()
      The size and voxel-resolution of the channel.
      Returns:
      the dimensions.
    • resolution

      public Optional<Resolution> resolution()
      Resolution of voxels to physical measurements.

      e.g. physical size of each voxel in a particular dimension.

      Returns:
      the image-resolution.
    • voxels

      public Voxels<UnsignedByteBuffer> voxels()
      The underlying voxels in the mask.
      Returns:
      the voxels.
    • binaryVoxels

      public BinaryVoxels<UnsignedByteBuffer> binaryVoxels()
      The underlying voxels in the mask, exposed as BinaryVoxels.
      Returns:
      the voxels, with associated binary-values.
    • isVoxelOn

      public boolean isVoxelOn(Point3i point)
      Does a particular voxel have the on state?
      Parameters:
      point - the point indicating which voxel to check.
      Returns:
      true if this voxel has an on state, false otherwise.
    • duplicate

      public Mask duplicate()
      Deep-copies the object.
      Returns:
      a deep-copy of the current object.
    • region

      public ObjectMask region(BoundingBox box, boolean reuseIfPossible)
      Creates an ObjectMask corresponding to the on/off state in a bounding-box.
      Parameters:
      box - the bounding-box.
      reuseIfPossible - if true, the existing boxels will be reused if possible (e.g. if the box refers to the entire image). if false, new voxel memory will always be allocated.
      Returns:
      the derived ObjectMask.
    • flattenZ

      public Mask flattenZ()
      Creates an otherwise identical Mask but a maximum-intensity-projection applied to the z-dimension.
      Returns:
      a newly created mask, as above.
    • voxelsOn

      public VoxelsPredicate voxelsOn()
      Operations on whether particular voxels are on.
      Returns:
      a newly instantiated object to perform queries on voxels who fulfill the above condition.
    • voxelsOff

      public VoxelsPredicate voxelsOff()
      Operations on whether particular voxels are off.
      Returns:
      a newly instantiated object to perform queries on voxels who fulfill the above condition.
    • scaleXY

      public Mask scaleXY(ScaleFactor scaleFactor)
      Creates a new Mask whose X- and Y- dimensions are scaled by scaleFactor.
      Parameters:
      scaleFactor - how to the scale the X- and Y- dimensions.
      Returns:
      a newly created Mask as above, except if scaleFactor is effectively 1, in which case the existing Mask is reused.
    • extractSlice

      public Mask extractSlice(int z)
      Creates a new Mask containing only one particular slice.

      The existing Voxels are reused, without creating new buffers.

      Parameters:
      z - the index of the slice to extract (index in z-dimension)
      Returns:
      a newly created Mask consisting of the slice at sliceIndex only.
    • replaceBy

      public void replaceBy(BinaryVoxels<UnsignedByteBuffer> voxels) throws IncorrectImageSizeException
      Replaces the underlying voxels in the mask with new voxels.

      The resolution and binary-values remain unchanged.

      Parameters:
      voxels - the new voxels to assign.
      Throws:
      IncorrectImageSizeException - if the size of voxels is not identical to the existing boxels.
    • assignOn

      public VoxelsAssigner assignOn()
      Interface that allows assignment of an on state to all or subsets of the voxels.
      Returns:
      the interface.
    • assignOff

      public VoxelsAssigner assignOff()
      Interface that allows assignment of an off state to all or subsets of the voxels.
      Returns:
      the interface.
    • sliceBuffer

      public UnsignedByteBuffer sliceBuffer(int z)
      A buffer corresponding to a particular z-slice.

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

      Parameters:
      z - the index (beginning at 0) of all z-slices.
      Returns:
      the corresponding buffer for z.
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • extent

      public Extent extent()
      The size of the voxels across three dimensions.
      Returns:
      the size.
    • channel

      public Channel channel()
      The underlying channel which contains the binary-values. It is always has data-type of unsigned 8-bit.
    • binaryValuesInt

      public BinaryValuesInt binaryValuesInt()
      The two states which are permitted to be assigned to the voxels, stored as unsigned ints.
    • binaryValuesByte

      public BinaryValuesByte binaryValuesByte()
      The two states which are permitted to be assigned to the voxels, stored as bytes.