#include <DLConnectedComponents.h>
DLConnectedComponents stores a list of DLComponents to represent the connected components of the entire image. An image must be binary (black and white) in order to calculate its connected components. See DLBitsPerPixelConverter for methods to convert color or grayscale images to binary.
Typical usage:
DLImage i("test.tif"); // load binary (B&W) image DLConnectedComponents cc; // declare connected components object cc.dlCreateConnectedComponents(i); // calculate components from image cout << cc.dlGetNumCCs() << endl; // output number of components in image
Use the filtering functions to keep or remove components based on a variety of criteria. Filtering does not actually destroy any connected components, and any filtering operations can be undone using dlResetCCFilter(). Filtering functions can be applied in series to achieve a cumulative effect.
Once filtered, use functions such as dlRenderFilteredCCs(), fbegin() and fend() to use the filtered components. See DLComponent and the various flavors of component iterators, including DLConnectedComponents::iterator, DLConnectedComponents::fiterator, DLConnectedComponents::const_iterator and DLConnectedComponents::const_fiterator for information about accessing individual connected components.
Example:
cc.dlFilterCCBoxGreater(2,2); // remove small components (e.g. speckle) DLImage despeckled = cc.dlRenderFilteredCCs(); // create new image from only large components
Definition at line 51 of file DLConnectedComponents.h.
typedef std::vector<DLComponent>::iterator DLConnectedComponents::iterator |
Iterator which iterates over all connected components, whether or not a filter was run
Definition at line 476 of file DLConnectedComponents.h.
typedef std::vector<DLComponent>::const_iterator DLConnectedComponents::const_iterator |
const
iterator which iterates over all connected components, weather or not a filter was run. Use this instead of the plain iterator if the DLConnectedComponents object has itself been declared const
.
Definition at line 482 of file DLConnectedComponents.h.
typedef fiterator_base<const DLComponent, const std::vector<DLComponent>, std::vector<DLComponent>::const_iterator, const std::vector<int>, std::vector<int>::const_iterator> DLConnectedComponents::const_fiterator |
Filtered iterator which iterates over all connected components, A filtering function must first be run.
Definition at line 488 of file DLConnectedComponents.h.
typedef fiterator_base<DLComponent, std::vector<DLComponent>, std::vector<DLComponent>::iterator, std::vector<int>, std::vector<int>::iterator> DLConnectedComponents::fiterator |
const
filtered iterator which iterates over all connected components. A filtering function must first be run.
Definition at line 494 of file DLConnectedComponents.h.
DLConnectedComponents::DLConnectedComponents | ( | ) |
Default DLConnectedComponents constructor
DLConnectedComponents::DLConnectedComponents | ( | const DLConnectedComponents & | orig | ) |
DLConnectedComponents Copy Constructor
virtual DLConnectedComponents::~DLConnectedComponents | ( | ) | [virtual] |
Default DLConnectedComponents destructor
const DLConnectedComponents& DLConnectedComponents::operator= | ( | const DLConnectedComponents & | right | ) |
Assignment operator
right | DLConnectedComponents |
void DLConnectedComponents::dlCreateConnectedComponents | ( | const DLImage & | img | ) |
Calculate connected components for a given image. The result will be saved in the DLConnectedComponents object and can be accessed.
img | binary (B&W) image to process |
vector<DLComponent> DLConnectedComponents::dlGetConnectedComponents | ( | ) | const |
Gets the list of the calculated connected components. Note that this makes a copy of the entire internal structure of DLConnectedComponents. See begin() and end() for an alternative method for accessing individual components which does not require a full copy.
void DLConnectedComponents::dlCalculateMoments | ( | ) |
Calculate the first 3 moments of all connected components
vector<DLComponent> DLConnectedComponents::dlGetFilteredCCs | ( | ) | const |
void DLConnectedComponents::dlResetCCFilter | ( | ) |
Reset Filter for connected components All of the components are re-selected, and filtCompIndices (the indices of filtered components) is reinitialized for all components.
int DLConnectedComponents::dlFilterCCHeightBetween | ( | int | minHeight, | |
int | maxHeight | |||
) |
Filter connected components by height: retain components with height between or equal to the limits. (Exclude too-small and too-large components)
minHeight | minimum height for including component | |
maxHeight | maximum height for including component |
int DLConnectedComponents::dlFilterCCWidthBetween | ( | int | minWidth, | |
int | maxWidth | |||
) |
Filter connected components by width: retain components with width between or equal to the limits. (Exclude too-small and too-large components)
minWidth | minimum width for including component | |
maxWidth | maximum width for including component |
int DLConnectedComponents::dlFilterCCRemoveTopBottom | ( | int | toprow, | |
int | bottomrow | |||
) |
Filter connected components by their vertical position in an image. (Exclude above-top and below-bottom components.) This filter retains only components entirely below (or touching) toprow and above (or touching) bottomrow.
toprow | top limit for including component - Row number | |
bottomrow | bottom limit for including component - Row number |
int DLConnectedComponents::dlFilterCCRemoveLeftRight | ( | int | leftcol, | |
int | rightcol | |||
) |
Filter connected components by their horizontal position in an image. (Exclude far-left and far-right components.) This filter retains only components lying entirely to the right of (or touching) leftcol and entirely to the left of (or touching) rightcol.
leftcol | left limit for including component - Column number | |
rightcol | right limit for including component - Column number |
int DLConnectedComponents::dlFilterCCDensityGreater | ( | float | density | ) |
Filter connected components by density. This filter retains only components whose density exceeds or is equal to the given parameter. (Exclude low-density components.) Density is calculated by taking the number of dark pixels in the component and dividing by area of the component's bounding box. ( Density can be a float in the range (0.0, 1.0]. )
density | minimum density |
int DLConnectedComponents::dlFilterCCDensityLess | ( | float | density | ) |
Filter connected components by density. This filter retains only components whose density is below or equal to the given parameter. (Exclude high-density components.) Density is calculated by taking the number of dark pixels in the component and dividing by area of the component's bounding box. ( Density can be a float in the range (0.0, 1.0]. )
density | maximum density |
int DLConnectedComponents::dlFilterCCDensityBetween | ( | float | mindensity, | |
float | maxdensity | |||
) |
Filter connected components by density. This filter retains only components whose density exceeds or is equal to mindensity and is less than or equal to maxdensity. (Exclude too-high- and too-low-density components.) Density is calculated by taking the number of dark pixels in the component and dividing by area of the component's bounding box. ( Density can be a float in the range (0.0, 1.0]. )
mindensity | minimum density | |
maxdensity | maximum density |
int DLConnectedComponents::dlFilterCCBoxLess | ( | float | width, | |
float | height | |||
) |
Filter connected components by size of their rectangular bounding box. This filter retains components whose height and width are both smaller (or equal to) than the given parameters. (Exclude larger-boxed components)
width | width float | |
height | height float |
int DLConnectedComponents::dlFilterCCBoxGreater | ( | float | width, | |
float | height | |||
) |
Filter connected components by size of their rectangular bounding box. This filter retains components whose height and width are both larger (or equal to) than the given parameters. (Exclude smaller-boxed components)
width | width float | |
height | height float |
int DLConnectedComponents::dlFilterCCMassGreater | ( | float | mass | ) |
Filter connected components by mass. This filter retains components whose mass is greater than or equal to the given parameter. (Exclude low-mass components) "Mass" is the number of dark pixels in the connected component.
mass | minimum mass |
int DLConnectedComponents::dlFilterCCMassLess | ( | float | mass | ) |
Filter connected components by mass. This filter retains components whose mass is less than or equal to the given parameter. (Exclude high-mass components) "Mass" is the number of dark pixels in the connected component.
mass | maximum mass |
int DLConnectedComponents::dlFilterCCMassBetween | ( | float | minmass, | |
float | maxmass | |||
) |
Filter connected components by mass. This filter retains components whose mass is between (or equal to) minmass and maxmass. "Mass" is the number of dark pixels in the connected component. (Exclude too-high- or too-low-mass components)
minmass | minimum mass | |
maxmass | maximum mass |
DLImage DLConnectedComponents::dlRenderCCs | ( | ) |
Render connected components
DLImage DLConnectedComponents::dlRenderFilteredCCs | ( | ) |
Render filtered connected components: form an image of only the components retained after any filter functions have been called. Note that if this function is called immediately after calculating the connected components, or after dlResetCCFilter(), it will have the same effect as dlRenderCCs().
DLImage DLConnectedComponents::dlRenderColorCCs | ( | ) |
Render a color image of the connected components. Use dlSetFilteredCCColor() to color groups of components.
DLConnectedComponents DLConnectedComponents::dlCopyCCs | ( | ) |
Copy connected components
int DLConnectedComponents::dlGetNumCCs | ( | ) | const |
Get the number of connected components
const vector<int> DLConnectedComponents::dlGetConnectedCCMap | ( | ) |
Creates integer vector, the same height and width as the input image. Each entry (x,y) in the array will be either the index of the connected component to which image pixel (x,y) belongs, or '-1' if that pixel location is not part of any connected component.
Note: dlRenderFilteredCCs() must be called before calling dlGetConnectedCCMap()
void DLConnectedComponents::dlSetFilteredCCColor | ( | DLColor | color | ) |
Assign a color value to the current filtered connected component list. This will loop through the filtered CC list and assign the passed in color value to the component. Then see dlRenderColorCCs().
color | color value |
iterator DLConnectedComponents::begin | ( | ) | [inline] |
Obtain an iterator to the beginning of all the connected components.
Definition at line 498 of file DLConnectedComponents.h.
const_iterator DLConnectedComponents::begin | ( | ) | const [inline] |
Obtain a const
iterator to the beginning of all the connected components. Only read access is allowed with this iterator.
Definition at line 504 of file DLConnectedComponents.h.
const_iterator DLConnectedComponents::end | ( | ) | const [inline] |
Obtain a const
iterator pointing just past the end of all the connected components.
Definition at line 510 of file DLConnectedComponents.h.
iterator DLConnectedComponents::end | ( | ) | [inline] |
Obtain an iterator pointing just past the end of all the connected components.
Definition at line 516 of file DLConnectedComponents.h.
fiterator DLConnectedComponents::fbegin | ( | ) | [inline] |
Obtain an iterator over the filtered connected components; this iterator is invalidated if the DLConnectedComponents filter is reset, or if an additional filter operation is applied.
Definition at line 523 of file DLConnectedComponents.h.
fiterator DLConnectedComponents::fend | ( | ) | [inline] |
Obtain an iterator to the end of the filtered connected components; this iterator is invalidated if the DLConnectedComponents filter is reset, or if an additional filter operation is applied.
Definition at line 530 of file DLConnectedComponents.h.
const_fiterator DLConnectedComponents::fbegin | ( | ) | const [inline] |
Obtain a const
iterator over the filtered connected components; this iterator is invalidated if the DLConnectedComponents filter is reset, or if an additional filter operation is applied.
Definition at line 538 of file DLConnectedComponents.h.
const_fiterator DLConnectedComponents::fend | ( | ) | const [inline] |
Obtain a const
iterator to the end of the filtered connected components; this iterator is invalidated if the DLConnectedComponents filter is reset, or if an additional filter operation is applied.
Definition at line 545 of file DLConnectedComponents.h.