Class BinaryImageOps

java.lang.Object
boofcv.alg.filter.binary.BinaryImageOps

public class BinaryImageOps
extends Object

Contains a standard set of operations performed on binary images. A pixel has a value of false if it is equal to zero or true equal to one.

NOTE: If an element's value is not zero or one then each function's behavior is undefined.

  • Constructor Details

    • BinaryImageOps

      public BinaryImageOps()
  • Method Details

    • logicAnd

      public static GrayU8 logicAnd​(GrayU8 inputA, GrayU8 inputB, GrayU8 output)
      For each pixel it applies the logical 'and' operator between two images.
      Parameters:
      inputA - First input image. Not modified.
      inputB - Second input image. Not modified.
      output - Output image. Can be same as either input. If null a new instance will be declared, Modified.
      Returns:
      Output of logical operation.
    • logicOr

      public static GrayU8 logicOr​(GrayU8 inputA, GrayU8 inputB, GrayU8 output)
      For each pixel it applies the logical 'or' operator between two images.
      Parameters:
      inputA - First input image. Not modified.
      inputB - Second input image. Not modified.
      output - Output image. Can be same as either input. If null a new instance will be declared, Modified.
      Returns:
      Output of logical operation.
    • logicXor

      public static GrayU8 logicXor​(GrayU8 inputA, GrayU8 inputB, GrayU8 output)
      For each pixel it applies the logical 'xor' operator between two images.
      Parameters:
      inputA - First input image. Not modified.
      inputB - Second input image. Not modified.
      output - Output image. Can be same as either input. If null a new instance will be declared, Modified.
      Returns:
      Output of logical operation.
    • invert

      public static GrayU8 invert​(GrayU8 input, GrayU8 output)
      Inverts each pixel from true to false and vis-versa.
      Parameters:
      input - Input image. Not modified.
      output - Output image. Can be same as input. If null a new instance will be declared, Modified.
      Returns:
      Output of logical operation.
    • erode4

      public static GrayU8 erode4​(GrayU8 input, int numTimes, GrayU8 output)

      Erodes an image according to a 4-neighborhood. Unless a pixel is connected to all its neighbors its value is set to zero.

      Parameters:
      input - Input image. Not modified.
      numTimes - How many times the operation will be applied to the image.
      output - If not null, the output image. If null a new image is declared and returned. Modified.
      Returns:
      Output image.
    • dilate4

      public static GrayU8 dilate4​(GrayU8 input, int numTimes, GrayU8 output)

      Dilates an image according to a 4-neighborhood. If a pixel is connected to any other pixel then its output value will be one.

      Parameters:
      input - Input image. Not modified.
      numTimes - How many times the operation will be applied to the image.
      output - If not null, the output image. If null a new image is declared and returned. Modified.
      Returns:
      Output image.
    • edge4

      public static GrayU8 edge4​(GrayU8 input, GrayU8 output, boolean outsideZero)

      Binary operation which is designed to remove all pixels but ones which are on the edge of an object. The edge is defined as lying on the object and not being surrounded by a pixel along a 4-neighborhood.

      NOTE: There are many ways to define an edge, this is just one of them.

      Parameters:
      input - Input image. Not modified.
      output - If not null, the output image. If null a new image is declared and returned. Modified.
      outsideZero - if true then pixels outside the image are treated as zero, otherwise one
      Returns:
      Output image.
    • erode8

      public static GrayU8 erode8​(GrayU8 input, int numTimes, GrayU8 output)

      Erodes an image according to a 8-neighborhood. Unless a pixel is connected to all its neighbors its value is set to zero.

      Parameters:
      input - Input image. Not modified.
      numTimes - How many times the operation will be applied to the image.
      output - If not null, the output image. If null a new image is declared and returned. Modified.
      Returns:
      Output image.
    • dilate8

      public static GrayU8 dilate8​(GrayU8 input, int numTimes, GrayU8 output)

      Dilates an image according to a 8-neighborhood. If a pixel is connected to any other pixel then its output value will be one.

      Parameters:
      input - Input image. Not modified.
      numTimes - How many times the operation will be applied to the image.
      output - If not null, the output image. If null a new image is declared and returned. Modified.
      Returns:
      Output image.
    • edge8

      public static GrayU8 edge8​(GrayU8 input, GrayU8 output, boolean outsideZero)

      Binary operation which is designed to remove all pixels but ones which are on the edge of an object. The edge is defined as lying on the object and not being surrounded by 8 pixels.

      NOTE: There are many ways to define an edge, this is just one of them.

      Parameters:
      input - Input image. Not modified.
      output - If not null, the output image. If null a new image is declared and returned. Modified.
      outsideZero - if true then pixels outside the image are treated as zero, otherwise one
      Returns:
      Output image.
    • removePointNoise

      public static GrayU8 removePointNoise​(GrayU8 input, GrayU8 output)
      Binary operation which is designed to remove small bits of spurious noise. An 8-neighborhood is used. If a pixel is connected to less than 2 neighbors then its value zero. If connected to more than 6 then its value is one. Otherwise it retains its original value.
      Parameters:
      input - Input image. Not modified.
      output - If not null, the output image. If null a new image is declared and returned. Modified.
      Returns:
      Output image.
    • thin

      public static GrayU8 thin​(GrayU8 input, int maxIterations, GrayU8 output)
      Applies a morphological thinning operation to the image. Also known as skeletonization.
      Parameters:
      input - Input image. Not modified.
      maxIterations - Maximum number of cycles it will thin for. -1 for the maximum required
      output - If not null, the output image. If null a new image is declared and returned. Modified.
      Returns:
      Output image.
      See Also:
      BinaryThinning
    • contour

      public static List<Contour> contour​(GrayU8 input, ConnectRule rule, GrayS32 output)

      Given a binary image, connect together pixels to form blobs/clusters using the specified connectivity rule. The found blobs will be labeled in an output image and also described as a set of contours. Pixels in the contours are consecutive order in a clockwise or counter-clockwise direction, depending on the implementation. The labeled image will assign background pixels a label of 0 and each blob will be assigned a unique ID starting from 1.

      The returned contours are traces of the object. The trace of an object can be found by marking a point with a pen and then marking every point on the contour without removing the pen. It is possible to have the same point multiple times in the contour.

      Parameters:
      input - Input binary image. Not modified.
      rule - Connectivity rule. Can be 4 or 8. 8 is more commonly used.
      output - (Optional) Output labeled image. If null, an image will be declared internally. Modified.
      Returns:
      List of found contours for each blob.
      See Also:
      LinearContourLabelChang2004
    • contourExternal

      public static List<Contour> contourExternal​(GrayU8 input, ConnectRule rule)
      Finds the external contours only in the image
      Parameters:
      input - Input binary image. Not modified.
      rule - Connectivity rule. Can be 4 or 8. 8 is more commonly used.
      Returns:
      List of found contours for each blob.
    • convertContours

      public static List<Contour> convertContours​(BinaryContourInterface alg)
    • relabel

      public static void relabel​(GrayS32 input, int[] labels)
      Used to change the labels in a labeled binary image.
      Parameters:
      input - Labeled binary image.
      labels - Look up table where the indexes are the current label and the value are its new value.
    • labelToBinary

      public static GrayU8 labelToBinary​(GrayS32 labelImage, GrayU8 binaryImage)
      Converts a labeled image into a binary image by setting any non-zero value to one.
      Parameters:
      labelImage - Input image. Not modified.
      binaryImage - Output image. Modified.
      Returns:
      The binary image.
    • labelToBinary

      public static GrayU8 labelToBinary​(GrayS32 labelImage, GrayU8 binaryImage, boolean[] selectedBlobs)
      Only converts the specified blobs over into the binary image
      Parameters:
      labelImage - Input image. Not modified.
      binaryImage - Output image. If null a new one will be declared. Modified.
      selectedBlobs - Each index corresponds to a blob and specifies if it is included or not. Expected size is the number of found clusters + 1.
      Returns:
      The binary image.
    • labelToBinary

      public static GrayU8 labelToBinary​(GrayS32 labelImage, GrayU8 binaryImage, int numLabels, int... selected)
      Only converts the specified blobs over into the binary image. Easier to use version of labelToBinary(GrayS32, GrayU8, boolean[]).
      Parameters:
      labelImage - Input image. Not modified.
      binaryImage - Output image. If null a new one will be declared. Modified.
      numLabels - Number of labels in the image. This is the number of found clusters + 1.
      selected - The index of labels which will be marked as 1 in the output binary image.
      Returns:
      The binary image.
    • labelToClusters

      public static List<List<Point2D_I32>> labelToClusters​(GrayS32 labelImage, int numLabels, DogArray<Point2D_I32> queue)
      Scans through the labeled image and adds the coordinate of each pixel that has been labeled to a list specific to its label.
      Parameters:
      labelImage - The labeled image.
      numLabels - Number of labeled objects inside the image.
      queue - (Optional) Storage for pixel coordinates. Improves runtime performance. Can be null.
      Returns:
      List of pixels in each cluster.
    • clusterToBinary

      public static void clusterToBinary​(List<List<Point2D_I32>> clusters, GrayU8 binary)
      Sets each pixel in the list of clusters to one in the binary image.
      Parameters:
      clusters - List of all the clusters.
      binary - Output
    • selectRandomColors

      public static int[] selectRandomColors​(int numBlobs, Random rand)
      Several blob rending functions take in an array of colors so that the random blobs can be drawn with the same color each time. This function selects a random color for each blob and returns it in an array.
      Parameters:
      numBlobs - Number of blobs found.
      rand - Random number generator
      Returns:
      array of RGB colors for each blob + the background blob