Segmentation of simply connected spaces in 2D data. More...
#include <RegionGrowing2D.hpp>
Public Types | |
typedef BinaryDataType | binary_value_type |
typedef LabelType | label_type |
typedef Coordinate< unsigned > | Point |
typedef std::deque< Point > | Region |
typedef std::deque< Region > | Regions |
Public Member Functions | |
RegionGrowing2D () | |
RegionGrowing2D (const BinaryDataType *data, const unsigned width, const unsigned height) | |
virtual | ~RegionGrowing2D () |
void | setData (const BinaryDataType *data, const unsigned width, const unsigned height) |
void | setNeighborhoodSize (const unsigned size) |
void | compute () |
Performs the region growing. | |
template<int StrideX, int StrideY> | |
void | compute () |
void | compute (const Point &seed_point) |
Performs the region growing. | |
void | compute (const std::deque< Point > &seed_points) |
Performs the region growing. | |
const Regions & | getRegions () const |
const LabelType * | getLabelMask () const |
Segmentation of simply connected spaces in 2D data.
BinaryDataType | Data type of the binary mask. |
LabelType | Data type of the label mask (should be able to hold the number of segmented regions). |
Segmentation of simply connected spaces in 2D data. The segmentation is done fully automatically, i.e. no seed points need to be provided (though, they can be provided). The result of the region growing is a label mask and a list of regions where, again, each region consists of a list of points forming the respective region.
Points are considered to be connected if they are lying in the same neighborhood, where a neighborhood \( \cal{N}\) is defined as
\[ \cal{N} \left( (x_0, y_0) \right) := \left\{ (x, y) \; | \; (x - x_0)^2 + (y - y_0)^2 \le c \right\} \]
The parameter \( c \) can be set by setNeighborhoodSize(); its default value is 2.
Here is an example of how to use this class:
#include <iostream> #include "TRTK/RegionGrowing2D.hpp" using namespace std; using namespace TRTK; const unsigned WIDTH = 11; const unsigned HEIGHT = 10; bool data[WIDTH * HEIGHT] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0}; int main() { // Print the data. cout << "Data" << endl << endl; for (unsigned m = 0; m < HEIGHT; ++m) { for (unsigned n = 0; n < WIDTH; ++n) { cout << data[m * WIDTH + n] << " "; } cout << endl; } // Perform the region growing. RegionGrowing2D<bool> regionGrowing2D(data, WIDTH, HEIGHT); regionGrowing2D.setNeighborhoodSize(2); regionGrowing2D.compute(); // Print the label mask. cout << endl << "Label mask" << endl << endl; const RegionGrowing2D<bool>::label_type * label_mask = regionGrowing2D.getLabelMask(); for (unsigned m = 0; m < HEIGHT; ++m) { for (unsigned n = 0; n < WIDTH; ++n) { cout << label_mask[m * WIDTH + n] << " "; } cout << std::endl; } // Print the regions. cout << endl << "Regions" << endl << endl; for (unsigned label = 0; label < regionGrowing2D.getRegions().size(); ++label) { for (unsigned i = 0; i < regionGrowing2D.getRegions()[label].size(); ++i) { cout << regionGrowing2D.getRegions()[label][i] << " "; } cout << endl; } return 0; }
Output:
Data 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0 Label mask 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 2 2 2 0 0 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 0 2 0 0 0 3 3 3 0 0 0 0 0 0 0 0 3 3 3 0 0 0 0 0 0 0 0 3 3 3 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 4 4 0 0 0 0 0 0 0 Regions (8, 0) (8, 1) (9, 0) (9, 1) (1, 2) (1, 3) (2, 2) (2, 3) (2, 4) (3, 2) (3, 3) (3, 4) (2, 5) (6, 5) (6, 6) (7, 5) (7, 6) (6, 7) (7, 7) (8, 5) (8, 6) (8, 7) (8, 8) (2, 9) (3, 9)
Definition at line 185 of file RegionGrowing2D.hpp.
TRTK::RegionGrowing2D< BinaryDataType, LabelType >::RegionGrowing2D | ( | ) |
Constructs an instance of RegionGrowing2D.
Definition at line 229 of file RegionGrowing2D.hpp.
TRTK::RegionGrowing2D< BinaryDataType, LabelType >::RegionGrowing2D | ( | const BinaryDataType * | data, |
const unsigned | width, | ||
const unsigned | height | ||
) |
[in] | data | 2D data |
[in] | width | number of columns of data |
[in] | height | number of rows of data |
Constructs an instance of RegionGrowing2D.
Definition at line 247 of file RegionGrowing2D.hpp.
TRTK::RegionGrowing2D< BinaryDataType, LabelType >::~RegionGrowing2D | ( | ) | [virtual] |
Destructs the instance of RegionGrowing2D.
Definition at line 261 of file RegionGrowing2D.hpp.
void TRTK::RegionGrowing2D< BinaryDataType, LabelType >::compute | ( | ) |
Performs the region growing.
All potential regions within the data set are extracted. The region growing depends on the size of the neighborhood. The result is a label mask and a list of regions which again are lists consisting of points of the respective regions.
StrideX | Step size in x while traversing the data. |
StrideY | Step size in y while traversing the data. |
All potential regions within the data set are extracted. The region growing depends on the size of the neighborhood. The result is a label mask and a list of regions which again are lists consisting of points of the respective regions.
The template parameters StrideX
and StrideY
specify the step size with which the binary mask is traversed while searching for potential seed points. This may lead to a significant speed-up. However, structures may be missed if their dimensions are smaller than these sizes.
Definition at line 278 of file RegionGrowing2D.hpp.
void TRTK::RegionGrowing2D< BinaryDataType, LabelType >::compute | ( | const Point & | seed_point ) |
Performs the region growing.
[in] | seed_point | Starting point for region growing. |
Only a single region is extracted. The region growing depends on the size of the neighborhood. The result is a label mask and a list of regions which again are lists consisting of points of the respective regions.
Definition at line 467 of file RegionGrowing2D.hpp.
void TRTK::RegionGrowing2D< BinaryDataType, LabelType >::compute | ( | const std::deque< Point > & | seed_points ) |
Performs the region growing.
[in] | seed_points | List of seed points. |
A seed point is a starting point from which a region is grown up. Only those regions are extracted from which one or more points are in the list of seed points. The region growing depends on the size of the neighborhood. The result is a label mask and a list of regions which again are lists consisting of points of the respective regions.
Definition at line 489 of file RegionGrowing2D.hpp.
const LabelType * TRTK::RegionGrowing2D< BinaryDataType, LabelType >::getLabelMask | ( | ) | const |
data
belongs to. Definition at line 588 of file RegionGrowing2D.hpp.
const RegionGrowing2D< BinaryDataType, LabelType >::Regions & TRTK::RegionGrowing2D< BinaryDataType, LabelType >::getRegions | ( | ) | const [inline] |
Definition at line 659 of file RegionGrowing2D.hpp.
void TRTK::RegionGrowing2D< BinaryDataType, LabelType >::setData | ( | const BinaryDataType * | data, |
const unsigned | width, | ||
const unsigned | height | ||
) |
[in] | data | 2D data |
[in] | width | number of columns of data |
[in] | height | number of rows of data |
Sets the binary image as well as its width and height.
Definition at line 688 of file RegionGrowing2D.hpp.
void TRTK::RegionGrowing2D< BinaryDataType, LabelType >::setNeighborhoodSize | ( | const unsigned | size ) |
[in] | size | Size of the neighborhood. |
Sets the size \( c \) of the neighborhood \( \cal{N}\) of a point \( (x_0, y_0) \), where the neighborhood is defined as
\[ \cal{N} \left( (x_0, y_0) \right) := \left\{ (x, y) \; | \; (x - x_0)^2 + (y - y_0)^2 \le c \right\} \]
Definition at line 712 of file RegionGrowing2D.hpp.
Documentation generated by Doxygen