Class LabelObjects<T>

Object
LabelObjects<T>
Type Parameters:
T - element-type, which must be an object-mask or an element containing an object-mask.

public class LabelObjects<T> extends Object
Writes a unique ID (successive integer IDs) for each elements's voxels into a channel, and 0 for background.

An element can be an object-mask or any other class from which an object-mask can be derived.

Author:
Owen Feehan
  • Constructor Details

    • LabelObjects

      public LabelObjects(Optional<UnaryOperator<T>> operationBeforeLabelling, Optional<Consumer<OverlappingObject<T>>> overlappingObjectConsumer, Function<T,ObjectMask> extractObject, BiFunction<T,ReadableTuple3i,T> shiftElement)
      Creates a new LabelObjects instance.
      Parameters:
      operationBeforeLabelling - An operation that is applied after any elements have been added to mapLabels but before the voxels are written with the labelled intensity values
      overlappingObjectConsumer - if set, this is called once with any overlapping object (after operationAfterMap is applied). Otherwise, an exception is thrown if an overlapping object is encountered.
      extractObject - Extracts an object-mask representation from an element
      shiftElement - Shifts the element in the positive direction.
    • LabelObjects

      public LabelObjects(Function<T,ObjectMask> extractObject, BiFunction<T,ReadableTuple3i,T> shiftElement)
      Creates a new LabelObjects instance.
      Parameters:
      extractObject - Extracts an object-mask representation from an element
      shiftElement - Shifts the element in the positive direction.
  • Method Details

    • createLabelledChannel

      public Channel createLabelledChannel(BoundedList<T> elements, Optional<Map<Integer,T>> mapLabels) throws CreateException
      Creates a channel that contains a unique integer (label) for each element's object-representation.

      Specifically, a channel is created that is exactly the same-size as the bounding-box around a collection of element, and labels the background with 0, and each element in the list with an incrementing unique integer identifier.

      Parameters:
      elements - the elements to write IDs for and a bounding-box that contains them all.
      mapLabels - if set, an entry is added for every labelled element (unscaled) to the label it is assigned.
      Returns:
      a channel of the same-size as the containing bounding-box in elements and with unique IDs for each element, and 0 for voxels not belonging to any element.
      Throws:
      CreateException - if there are more than 255 objects, or if two objects overlap when this cannot handled gracefully.
    • labelElements

      public void labelElements(Channel channel, Iterable<T> elements, Optional<Map<Integer,T>> mapLabels) throws CreateException
      Replaces the contents of the channel so that all element's voxels are labelled with successive unique integer identifiers 1,2,3 etc. and voxels in no element are 0.
      Parameters:
      channel - the channel whose voxels will be replaced
      elements - the element to write IDs for.
      mapLabels - if set, an entry is added for every labelled element (unscaled) to the label it is assigned
      Throws:
      CreateException - if there are more than 255 objects, or if two objects overlap (and overlappingObjectConsumer is not set).