public class BinaryImageOps
extends java.lang.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 and Description |
|---|
BinaryImageOps() |
| Modifier and Type | Method and Description |
|---|---|
static void |
clusterToBinary(java.util.List<java.util.List<georegression.struct.point.Point2D_I32>> clusters,
GrayU8 binary)
Sets each pixel in the list of clusters to one in the binary image.
|
static java.util.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.
|
static GrayU8 |
dilate4(GrayU8 input,
int numTimes,
GrayU8 output)
Dilates an image according to a 4-neighborhood.
|
static GrayU8 |
dilate8(GrayU8 input,
int numTimes,
GrayU8 output)
Dilates an image according to a 8-neighborhood.
|
static GrayU8 |
edge4(GrayU8 input,
GrayU8 output)
Binary operation which is designed to remove all pixels but ones which are on the edge of an object.
|
static GrayU8 |
edge8(GrayU8 input,
GrayU8 output)
Binary operation which is designed to remove all pixels but ones which are on the edge of an object.
|
static GrayU8 |
erode4(GrayU8 input,
int numTimes,
GrayU8 output)
Erodes an image according to a 4-neighborhood.
|
static GrayU8 |
erode8(GrayU8 input,
int numTimes,
GrayU8 output)
Erodes an image according to a 8-neighborhood.
|
static GrayU8 |
invert(GrayU8 input,
GrayU8 output)
Inverts each pixel from true to false and vis-versa.
|
static GrayU8 |
labelToBinary(GrayS32 labelImage,
GrayU8 binaryImage)
Converts a labeled image into a binary image by setting any non-zero value to one.
|
static GrayU8 |
labelToBinary(GrayS32 labelImage,
GrayU8 binaryImage,
boolean[] selectedBlobs)
Only converts the specified blobs over into the binary image
|
static GrayU8 |
labelToBinary(GrayS32 labelImage,
GrayU8 binaryImage,
int numLabels,
int... selected)
Only converts the specified blobs over into the binary image.
|
static java.util.List<java.util.List<georegression.struct.point.Point2D_I32>> |
labelToClusters(GrayS32 labelImage,
int numLabels,
org.ddogleg.struct.FastQueue<georegression.struct.point.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.
|
static GrayU8 |
logicAnd(GrayU8 inputA,
GrayU8 inputB,
GrayU8 output)
For each pixel it applies the logical 'and' operator between two images.
|
static GrayU8 |
logicOr(GrayU8 inputA,
GrayU8 inputB,
GrayU8 output)
For each pixel it applies the logical 'or' operator between two images.
|
static GrayU8 |
logicXor(GrayU8 inputA,
GrayU8 inputB,
GrayU8 output)
For each pixel it applies the logical 'xor' operator between two images.
|
static void |
relabel(GrayS32 input,
int[] labels)
Used to change the labels in a labeled binary image.
|
static GrayU8 |
removePointNoise(GrayU8 input,
GrayU8 output)
Binary operation which is designed to remove small bits of spurious noise.
|
static int[] |
selectRandomColors(int numBlobs,
java.util.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.
|
static GrayU8 |
thin(GrayU8 input,
int maxIterations,
GrayU8 output)
Applies a morphological thinning operation to the image.
|
public static GrayU8 logicAnd(GrayU8 inputA, GrayU8 inputB, GrayU8 output)
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.public static GrayU8 logicOr(GrayU8 inputA, GrayU8 inputB, GrayU8 output)
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.public static GrayU8 logicXor(GrayU8 inputA, GrayU8 inputB, GrayU8 output)
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.public static GrayU8 invert(GrayU8 input, GrayU8 output)
input - Input image. Not modified.output - Output image. Can be same as input. If null a new instance will be declared, Modified.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.
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.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.
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.public static GrayU8 edge4(GrayU8 input, GrayU8 output)
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.
input - Input image. Not modified.output - If not null, the output image. If null a new image is declared and returned. Modified.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.
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.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.
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.public static GrayU8 edge8(GrayU8 input, GrayU8 output)
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.
input - Input image. Not modified.output - If not null, the output image. If null a new image is declared and returned. Modified.public static GrayU8 removePointNoise(GrayU8 input, GrayU8 output)
input - Input image. Not modified.output - If not null, the output image. If null a new image is declared and returned. Modified.public static GrayU8 thin(GrayU8 input, int maxIterations, GrayU8 output)
input - Input image. Not modified.maxIterations - Maximum number of cycles it will thin for. -1 for the maximum requiredoutput - If not null, the output image. If null a new image is declared and returned. Modified.BinaryThinningpublic static java.util.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.
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.LinearContourLabelChang2004public static void relabel(GrayS32 input, int[] labels)
input - Labeled binary image.labels - Look up table where the indexes are the current label and the value are its new value.public static GrayU8 labelToBinary(GrayS32 labelImage, GrayU8 binaryImage)
labelImage - Input image. Not modified.binaryImage - Output image. Modified.public static GrayU8 labelToBinary(GrayS32 labelImage, GrayU8 binaryImage, boolean[] selectedBlobs)
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.public static GrayU8 labelToBinary(GrayS32 labelImage, GrayU8 binaryImage, int numLabels, int... selected)
labelToBinary(GrayS32, GrayU8, boolean[]).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.public static java.util.List<java.util.List<georegression.struct.point.Point2D_I32>> labelToClusters(GrayS32 labelImage, int numLabels, org.ddogleg.struct.FastQueue<georegression.struct.point.Point2D_I32> queue)
labelImage - The labeled image.numLabels - Number of labeled objects inside the image.queue - (Optional) Storage for pixel coordinates. Improves runtime performance. Can be null.public static void clusterToBinary(java.util.List<java.util.List<georegression.struct.point.Point2D_I32>> clusters,
GrayU8 binary)
clusters - List of all the clusters.binary - Outputpublic static int[] selectRandomColors(int numBlobs,
java.util.Random rand)
numBlobs - Number of blobs found.rand - Random number generator