Use row-by-row labeling algorithm to label connected components. The algorithm makes two passes over the image: one pass to record equivalences and assign temporary labels and the second to replace each temporary label by the label of its equivalence class. Based on Linda G. Shapiro, Computer Vision: Theory and Applications. (3.4 Connected Components Labeling), Rosenfeld and Pfaltz (1966). More...
#include <connected_components.h>
Public Member Functions | |
valarray< int > | compactLabeling () |
Rearrange the labels to make the label numbers consecutive. More... | |
connected_components (valarray< int > m, int rows, int cols, bool zeroAsBg) | |
Constructor that initializes the private member variables. More... | |
void | constructBinaryImages (int robotsLabel) |
Create binary arrays of connected labels. More... | |
int | getMaxLabel () |
Get the max label of the labeling process which is in the range [0,max_label]. More... | |
vector< int > | labeling () |
Label the connected components. More... | |
valarray< float > | NormalizedEuclideanDistanceBinary (bool RobotR) |
Calculate the normalized euclidean distance transform of a binary image with foreground pixels set to 1 and background set to 0. More... | |
int | uf_find (int x, vector< int > parent, vector< int > &label) |
Return the root label (starts from 1 because label array is initialized to 0 at first). The label array records the new label for every root. More... | |
void | uf_union (int x, int y, vector< int > &parent) |
Combine two labels. More... | |
Private Member Functions | |
void | DT1D (vector< float > f, vector< float > &d, vector< int > &v, vector< float > &z) |
DT1D. More... | |
vector< float > | getVector (valarray< float > A, int row) |
Get a slice of an array. More... | |
Private Attributes | |
valarray< int > | BinaryNonRobot |
Binary array of the labels not assigned to a robot. More... | |
valarray< int > | BinaryRobot |
Binary array of the label assigned to a robot. More... | |
int | cols |
Number of columns of the image. More... | |
vector< int > | image |
The image to perform the labeling on. More... | |
valarray< int > | label2d |
Array of labels. More... | |
int | next_label = 1 |
The current label ID. More... | |
int | rows |
Number of rows of the image. More... | |
bool | zeroAsBg |
Whether 0 should be considered or not. More... | |
Use row-by-row labeling algorithm to label connected components. The algorithm makes two passes over the image: one pass to record equivalences and assign temporary labels and the second to replace each temporary label by the label of its equivalence class. Based on Linda G. Shapiro, Computer Vision: Theory and Applications. (3.4 Connected Components Labeling), Rosenfeld and Pfaltz (1966).
Definition at line 14 of file connected_components.h.
connected_components::connected_components | ( | valarray< int > | m, |
int | rows, | ||
int | cols, | ||
bool | zeroAsBg | ||
) |
Constructor that initializes the private member variables.
m | The matrix containing the data to label. |
rows | Number of rows in the matrix. |
cols | Number of columns in the matrix. |
zeroAsBg | Whether 0 represents background and is ignored. |
Definition at line 3 of file connected_components.cpp.
valarray< int > connected_components::compactLabeling | ( | ) |
Rearrange the labels to make the label numbers consecutive.
Definition at line 11 of file connected_components.cpp.
void connected_components::constructBinaryImages | ( | int | robotsLabel | ) |
Create binary arrays of connected labels.
robotsLabel | The label to create the binary array for. |
Definition at line 138 of file connected_components.cpp.
|
private |
int connected_components::getMaxLabel | ( | ) |
Get the max label of the labeling process which is in the range [0,max_label].
Definition at line 41 of file connected_components.cpp.
|
private |
Get a slice of an array.
A | The array to take the slice from. |
row | The index of the slice to take. |
Definition at line 231 of file connected_components.cpp.
vector< int > connected_components::labeling | ( | ) |
Label the connected components.
Definition at line 46 of file connected_components.cpp.
valarray< float > connected_components::NormalizedEuclideanDistanceBinary | ( | bool | RobotR | ) |
Calculate the normalized euclidean distance transform of a binary image with foreground pixels set to 1 and background set to 0.
RobotR | Whether to compute the distances to the robot. |
Definition at line 155 of file connected_components.cpp.
int connected_components::uf_find | ( | int | x, |
vector< int > | parent, | ||
vector< int > & | label | ||
) |
Return the root label (starts from 1 because label array is initialized to 0 at first). The label array records the new label for every root.
x | The label to start the search from. |
parent | The label hierarchy. |
label | The vector of labels. |
Definition at line 126 of file connected_components.cpp.
void connected_components::uf_union | ( | int | x, |
int | y, | ||
vector< int > & | parent | ||
) |
Combine two labels.
x | The first label. |
y | The second label. |
parent | The label hierarchy. |
Definition at line 113 of file connected_components.cpp.
|
private |
Binary array of the labels not assigned to a robot.
Definition at line 106 of file connected_components.h.
|
private |
Binary array of the label assigned to a robot.
Definition at line 101 of file connected_components.h.
|
private |
Number of columns of the image.
Definition at line 116 of file connected_components.h.
|
private |
The image to perform the labeling on.
Definition at line 126 of file connected_components.h.
|
private |
Array of labels.
Definition at line 96 of file connected_components.h.
|
private |
The current label ID.
Definition at line 121 of file connected_components.h.
|
private |
Number of rows of the image.
Definition at line 111 of file connected_components.h.
|
private |
Whether 0 should be considered or not.
Definition at line 131 of file connected_components.h.