Class BasicSkeletonPixelClassifier2D


public class BasicSkeletonPixelClassifier2D extends ApertureBasedSkeletonPixelClassifier

Ready classifier of pixel of 2-dimensional thinning skeletons.

There are only 3 instances of this class, returned by the methods:

These classifiers are designed for processing bit matrices, which are the final results of most popular 2-dimensional skeletonization algorithms: OctupleThinningSkeleton2D, Quadruple3x5ThinningSkeleton2D and StrongQuadruple3x5ThinningSkeleton2D. These algorithms have different "strength", so, using "stronger" classifier for "weaker" skeleton (for example, using getStrongQuadruple3x5ThinningInstance() for the resulting skeleton of OctupleThinningSkeleton2D algorithm) can lead to recognition of some skeleton pixels as "illegal".

This class is immutable and thread-safe: there are no ways to modify settings of the created instance.

Author:
Daniel Alievsky
  • Field Details

    • NEIGHBOUR_INDEX_XM_YM

      public static final int NEIGHBOUR_INDEX_XM_YM
      0: an index of the neighbour #0 of any element in terms of neighbourOffset(int) method. It is one of possible non-negative values, returned by asPixelTypes method. You can understand the sense of the name of this constant from the comments to these methods.
      See Also:
    • NEIGHBOUR_INDEX_YM

      public static final int NEIGHBOUR_INDEX_YM
      1: an index of the neighbour #1 of any element in terms of neighbourOffset(int) method. It is one of possible non-negative values, returned by asPixelTypes method. You can understand the sense of the name of this constant from the comments to these methods.
      See Also:
    • NEIGHBOUR_INDEX_XP_YM

      public static final int NEIGHBOUR_INDEX_XP_YM
      2: an index of the neighbour #2 of any element in terms of neighbourOffset(int) method. It is one of possible non-negative values, returned by asPixelTypes method. You can understand the sense of the name of this constant from the comments to these methods.
      See Also:
    • NEIGHBOUR_INDEX_XP

      public static final int NEIGHBOUR_INDEX_XP
      3: an index of the neighbour #3 of any element in terms of neighbourOffset(int) method. It is one of possible non-negative values, returned by asPixelTypes method. You can understand the sense of the name of this constant from the comments to these methods.
      See Also:
    • NEIGHBOUR_INDEX_XP_YP

      public static final int NEIGHBOUR_INDEX_XP_YP
      4: an index of the neighbour #4 of any element in terms of neighbourOffset(int) method. It is one of possible non-negative values, returned by asPixelTypes method. You can understand the sense of the name of this constant from the comments to these methods.
      See Also:
    • NEIGHBOUR_INDEX_YP

      public static final int NEIGHBOUR_INDEX_YP
      5: an index of the neighbour #5 of any element in terms of neighbourOffset(int) method. It is one of possible non-negative values, returned by asPixelTypes method. You can understand the sense of the name of this constant from the comments to these methods.
      See Also:
    • NEIGHBOUR_INDEX_XM_YP

      public static final int NEIGHBOUR_INDEX_XM_YP
      6: an index of the neighbour #6 of any element in terms of neighbourOffset(int) method. It is one of possible non-negative values, returned by asPixelTypes method. You can understand the sense of the name of this constant from the comments to these methods.
      See Also:
    • NEIGHBOUR_INDEX_XM

      public static final int NEIGHBOUR_INDEX_XM
      7: an index of the neighbour #7 of any element in terms of neighbourOffset(int) method. It is one of possible non-negative values, returned by asPixelTypes method. You can understand the sense of the name of this constant from the comments to these methods.
      See Also:
    • NEIGHBOUR_INDEX_MIN

      public static final int NEIGHBOUR_INDEX_MIN
      0: minimal non-negative value, that can be returned by asPixelTypes method in this class.
      See Also:
    • NEIGHBOUR_INDEX_MAX

      public static final int NEIGHBOUR_INDEX_MAX
      7: maximal non-negative value, that can be returned by asPixelTypes method in this class.
      See Also:
  • Method Details

    • getOctupleThinningInstance

      public static BasicSkeletonPixelClassifier2D getOctupleThinningInstance()
      Returns the instance of this class, intended for processing skeletons, which are the final result of skeletonization by OctupleThinningSkeleton2D algorithm.
      Returns:
      the classifier of pixels of OctupleThinningSkeleton2D skeletons.
    • getQuadruple3x5ThinningInstance

      public static BasicSkeletonPixelClassifier2D getQuadruple3x5ThinningInstance()
      Returns the instance of this class, intended for processing skeletons, which are the final result of skeletonization by Quadruple3x5ThinningSkeleton2D algorithm.
      Returns:
      the classifier of pixels of Quadruple3x5ThinningSkeleton2D skeletons.
    • getStrongQuadruple3x5ThinningInstance

      public static BasicSkeletonPixelClassifier2D getStrongQuadruple3x5ThinningInstance()
      Returns the instance of this class, intended for processing skeletons, which are the final result of skeletonization by StrongQuadruple3x5ThinningSkeleton2D algorithm.
      Returns:
      the classifier of pixels of StrongQuadruple3x5ThinningSkeleton2D skeletons.
    • pixelTypeOrAttachingBranch

      protected int pixelTypeOrAttachingBranch(int apertureBits)
      Description copied from class: ApertureBasedSkeletonPixelClassifier
      Calculates and returns the value of an element C' in the resulting matrix, produced by asPixelTypes method with NEIGHBOUR_INDEX_OF_ATTACHING_BRANCH value of attachmentInformation argument, on the base of bit values of all neighbours (in terms of the straight-and-diagonal connectivity kind) of the corresponding unit element C in the source skeleton bit matrix.

      More precisely, the bit values of the neighbours of this skeleton element C are passed via the low m=numberOfNeighbours() bits of apertureBits argument. The bit #k of this argument, 0≤k<m (its value is (apertureBits>>>k)&1), is equal to the value of the neighbour #k in terms of neighbourOffset(int) method. In particular, in BasicSkeletonPixelClassifier2D implementation, the order of neighbours is described by the following diagram:

       0 1 2
       7 C 3
       6 5 4

      So, 8 low bits of apertureBits contain the values of the corresponding neighbouring elements in anticlockwise order (the x-axis is directed rightward, the y-axis is directed downward).

      It is supposed that the central element (C) of the skeleton is unit (for zero elements ot the skeleton matrix, asPixelTypes method of this class returns SkeletonPixelClassifier.TYPE_ZERO without calling this method).

      Note, that the situation, when the neighbouring elements are out of ranges of the matrix coordinates, is processed according to the model of infinite pseudo-cyclical continuation — see the end of the comments to SkeletonPixelClassifier.

      Specified by:
      pixelTypeOrAttachingBranch in class ApertureBasedSkeletonPixelClassifier
      Parameters:
      apertureBits - the values of all 8 neighbours of the current unit element of the source skeleton bit matrix.
      Returns:
      the type of this pixel of the skeleton.
    • pixelTypeOrAttachedNode

      protected int pixelTypeOrAttachedNode(int apertureBits)
      Description copied from class: ApertureBasedSkeletonPixelClassifier
      Calculates and returns the value of an element C' in the resulting matrix, produced by asPixelTypes method with NEIGHBOUR_INDEX_OF_ATTACHED_NODE value of attachmentInformation argument, on the base of bit values of all neighbours (in terms of the straight-and-diagonal connectivity kind) of the corresponding unit element C in the source skeleton bit matrix.

      More precisely, the bit values of the neighbours of this skeleton element C are passed via the low m=numberOfNeighbours() bits of apertureBits argument. The bit #k of this argument, 0≤k<m (its value is (apertureBits>>>k)&1), is equal to the value of the neighbour #k in terms of neighbourOffset(int) method. In particular, in BasicSkeletonPixelClassifier2D implementation, the order of neighbours is described by the following diagram:

       0 1 2
       7 C 3
       6 5 4

      So, 8 low bits of apertureBits contain the values of the corresponding neighbouring elements in anticlockwise order (the x-axis is directed rightward, the y-axis is directed downward).

      It is supposed that the central element (C) of the skeleton is unit (for zero elements ot the skeleton matrix, asPixelTypes method of this class returns SkeletonPixelClassifier.TYPE_ZERO without calling this method).

      Note, that the situation, when the neighbouring elements are out of ranges of the matrix coordinates, is processed according to the model of infinite pseudo-cyclical continuation — see the end of the comments to SkeletonPixelClassifier.

      Specified by:
      pixelTypeOrAttachedNode in class ApertureBasedSkeletonPixelClassifier
      Parameters:
      apertureBits - the values of all 8 neighbours of the current unit element of the source skeleton bit matrix.
      Returns:
      the type of this pixel of the skeleton.