Segmentation of simply connected spaces in 3D data. More...
#include <RegionGrowing3D.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 | |
RegionGrowing3D () | |
RegionGrowing3D (BinaryFieldType data, const unsigned width, const unsigned height, const unsigned depth) | |
virtual | ~RegionGrowing3D () |
void | setData (BinaryFieldType data, const unsigned width, const unsigned height, const unsigned depth) |
void | setNeighborhoodSize (const unsigned size) |
template<int StrideX, int StrideY, int StrideZ> | |
void | compute () |
Performs the region growing. | |
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 3D 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). |
BinaryFieldType | Field type of the binary data. This allows overloading operator[]() . |
Segmentation of simply connected spaces in 3D 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, z_0) \right) := \left\{ (x, y, z) \; | \; (x - x_0)^2 + (y - y_0)^2 + (z - z_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/RegionGrowing3D.hpp" using namespace std; using namespace TRTK; const unsigned WIDTH = 7; const unsigned HEIGHT = 5; const unsigned DEPTH = 2; bool data[WIDTH * HEIGHT * DEPTH] = {0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1}; int main() { // Print the data. cout << "Data" << endl << endl; for (unsigned d = 0; d < DEPTH; ++d) { for (unsigned m = 0; m < HEIGHT; ++m) { for (unsigned n = 0; n < WIDTH; ++n) { cout << data[d * WIDTH * HEIGHT + m * WIDTH + n] << " "; } cout << endl; } cout << endl << endl; } // Perform the region growing. RegionGrowing3D<bool> regionGrowing3D(data, WIDTH, HEIGHT, DEPTH); regionGrowing3D.setNeighborhoodSize(2); regionGrowing3D.compute(); // Print the label mask. cout << endl << "Label mask" << endl << endl; const RegionGrowing3D<bool>::label_type * label_mask = regionGrowing3D.getLabelMask(); for (unsigned d = 0; d < DEPTH; ++d) { for (unsigned m = 0; m < HEIGHT; ++m) { for (unsigned n = 0; n < WIDTH; ++n) { cout << label_mask[d * WIDTH * HEIGHT + m * WIDTH + n] << " "; } cout << endl; } cout << endl << endl; } // Print the regions. cout << endl << "Regions" << endl << endl; for (unsigned label = 0; label < regionGrowing3D.getRegions().size(); ++label) { for (unsigned i = 0; i < regionGrowing3D.getRegions()[label].size(); ++i) { cout << regionGrowing3D.getRegions()[label][i] << " "; } cout << endl; } return 0; }
Output:
Data 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 Label mask 0 0 0 0 0 0 1 0 2 2 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 0 3 3 0 0 0 0 0 3 3 0 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 3 3 0 0 0 0 0 3 3 Regions (6, 0, 0) (1, 1, 0) (1, 1, 1) (1, 2, 0) (2, 1, 0) (2, 1, 1) (2, 2, 0) (2, 2, 1) (5, 3, 0) (5, 3, 1) (5, 4, 0) (5, 4, 1) (6, 3, 0) (6, 3, 1) (6, 4, 0) (6, 4, 1)
Definition at line 204 of file RegionGrowing3D.hpp.
TRTK::RegionGrowing3D< BinaryDataType, LabelType, BinaryFieldType >::RegionGrowing3D | ( | ) |
Constructs an instance of RegionGrowing3D.
Definition at line 251 of file RegionGrowing3D.hpp.
TRTK::RegionGrowing3D< BinaryDataType, LabelType, BinaryFieldType >::RegionGrowing3D | ( | BinaryFieldType | data, |
const unsigned | width, | ||
const unsigned | height, | ||
const unsigned | depth | ||
) |
[in] | data | 3D data |
[in] | width | number of columns of data |
[in] | height | number of rows of data |
[in] | depth | number of planes of data |
Constructs an instance of RegionGrowing3D.
Definition at line 271 of file RegionGrowing3D.hpp.
TRTK::RegionGrowing3D< BinaryDataType, LabelType, BinaryFieldType >::~RegionGrowing3D | ( | ) | [virtual] |
Destructs the instance of RegionGrowing3D.
Definition at line 287 of file RegionGrowing3D.hpp.
void TRTK::RegionGrowing3D< BinaryDataType, LabelType, BinaryFieldType >::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. |
StrideZ | Step size in z 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
, StrideY
and StrideZ
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 304 of file RegionGrowing3D.hpp.
void TRTK::RegionGrowing3D< BinaryDataType, LabelType, BinaryFieldType >::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 499 of file RegionGrowing3D.hpp.
void TRTK::RegionGrowing3D< BinaryDataType, LabelType, BinaryFieldType >::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 521 of file RegionGrowing3D.hpp.
const LabelType * TRTK::RegionGrowing3D< BinaryDataType, LabelType, BinaryFieldType >::getLabelMask | ( | ) | const |
A label mask is returned, whose entries denote, to which region a datum in data
belongs to.
Definition at line 624 of file RegionGrowing3D.hpp.
const RegionGrowing3D< BinaryDataType, LabelType, BinaryFieldType >::Regions & TRTK::RegionGrowing3D< BinaryDataType, LabelType, BinaryFieldType >::getRegions | ( | ) | const [inline] |
Definition at line 702 of file RegionGrowing3D.hpp.
void TRTK::RegionGrowing3D< BinaryDataType, LabelType, BinaryFieldType >::setData | ( | BinaryFieldType | data, |
const unsigned | width, | ||
const unsigned | height, | ||
const unsigned | depth | ||
) |
[in] | data | 3D data |
[in] | width | number of columns of data |
[in] | height | number of rows of data |
[in] | depth | number of planes of data |
Sets the binary image as well as its width, height and depth.
Definition at line 732 of file RegionGrowing3D.hpp.
void TRTK::RegionGrowing3D< BinaryDataType, LabelType, BinaryFieldType >::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, z_0) \), where the neighborhood is defined as
\[ \cal{N} \left( (x_0, y_0, z_0) \right) := \left\{ (x, y, z) \; | \; (x - x_0)^2 + (y - y_0)^2 + (z - z_0)^2 \le c \right\} \]
Definition at line 759 of file RegionGrowing3D.hpp.
Documentation generated by Doxygen