DLConnectedComponents Class Reference

Calculates and stores connected components of an DLImage. More...

#include <DLConnectedComponents.h>

List of all members.

Public Types

typedef std::vector< DLComponent
>::iterator 
iterator
typedef std::vector< DLComponent
>::const_iterator 
const_iterator
typedef fiterator_base< const
DLComponent, const std::vector<
DLComponent >, std::vector<
DLComponent >::const_iterator,
const std::vector< int >,
std::vector< int >::const_iterator
const_fiterator
typedef fiterator_base< DLComponent,
std::vector< DLComponent >,
std::vector< DLComponent
>::iterator, std::vector<
int >, std::vector< int
>::iterator
fiterator

Public Member Functions

 DLConnectedComponents ()
 DLConnectedComponents (const DLConnectedComponents &orig)
const DLConnectedComponentsoperator= (const DLConnectedComponents &right)
virtual ~DLConnectedComponents ()
void dlCreateConnectedComponents (const DLImage &img)
vector< DLComponentdlGetConnectedComponents () const
void dlCalculateMoments ()
vector< DLComponentdlGetFilteredCCs () const
void dlResetCCFilter ()
DLImage dlRenderCCs ()
DLImage dlRenderFilteredCCs ()
DLImage dlRenderColorCCs ()
DLConnectedComponents dlCopyCCs ()
int dlGetNumCCs () const
const vector< int > dlGetConnectedCCMap ()
void dlSetFilteredCCColor (DLColor color)
iterator begin ()
const_iterator begin () const
const_iterator end () const
iterator end ()
fiterator fbegin ()
fiterator fend ()
const_fiterator fbegin () const
const_fiterator fend () const
Filtering Functions
int dlFilterCCHeightBetween (int minHeight, int maxHeight)
int dlFilterCCWidthBetween (int minWidth, int maxWidth)
int dlFilterCCRemoveTopBottom (int toprow, int bottomrow)
int dlFilterCCRemoveLeftRight (int leftcol, int rightcol)
int dlFilterCCDensityGreater (float density)
int dlFilterCCDensityLess (float density)
int dlFilterCCDensityBetween (float mindensity, float maxdensity)
int dlFilterCCBoxLess (float width, float height)
int dlFilterCCBoxGreater (float width, float height)
int dlFilterCCMassGreater (float mass)
int dlFilterCCMassLess (float mass)
int dlFilterCCMassBetween (float minmass, float maxmass)

Classes

class  fiterator_base
 Class for iterating over all the filtered connected components. More...


Detailed Description

Calculates and stores connected components of an DLImage.

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.


Member Typedef Documentation

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.


Constructor & Destructor Documentation

DLConnectedComponents::DLConnectedComponents (  ) 

Default DLConnectedComponents constructor

DLConnectedComponents::DLConnectedComponents ( const DLConnectedComponents orig  ) 

DLConnectedComponents Copy Constructor

virtual DLConnectedComponents::~DLConnectedComponents (  )  [virtual]

Default DLConnectedComponents destructor


Member Function Documentation

const DLConnectedComponents& DLConnectedComponents::operator= ( const DLConnectedComponents right  ) 

Assignment operator

Parameters:
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.

Parameters:
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.

Returns:
vector of DLComponents

void DLConnectedComponents::dlCalculateMoments (  ) 

Calculate the first 3 moments of all connected components

vector<DLComponent> DLConnectedComponents::dlGetFilteredCCs (  )  const

Get filtered connected components. See the iterator functions fbegin() and fend() for an alternative method for accessing individual components which does not require a full copy.

Returns:
the current set of filtered connected components

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)

Parameters:
minHeight minimum height for including component
maxHeight maximum height for including component
Returns:
number of components included

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)

Parameters:
minWidth minimum width for including component
maxWidth maximum width for including component
Returns:
number of components included

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.

Parameters:
toprow top limit for including component - Row number
bottomrow bottom limit for including component - Row number
Returns:
number of components included

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.

Parameters:
leftcol left limit for including component - Column number
rightcol right limit for including component - Column number
Returns:
number of components included

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]. )

Parameters:
density minimum density
Returns:
number of components included

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]. )

Parameters:
density maximum density
Returns:
number of components included

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]. )

Parameters:
mindensity minimum density
maxdensity maximum density
Returns:
number of components included

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)

Parameters:
width width float
height height float
Returns:
number of components included

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)

Parameters:
width width float
height height float
Returns:
number of components included

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.

Parameters:
mass minimum mass
Returns:
number of components included

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.

Parameters:
mass maximum mass
Returns:
number of components included

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)

Parameters:
minmass minimum mass
maxmass maximum mass
Returns:
number of components included

DLImage DLConnectedComponents::dlRenderCCs (  ) 

Render connected components

Returns:
image of 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().

Returns:
image of filtered connected components

DLImage DLConnectedComponents::dlRenderColorCCs (  ) 

Render a color image of the connected components. Use dlSetFilteredCCColor() to color groups of components.

Returns:
image of connected components

DLConnectedComponents DLConnectedComponents::dlCopyCCs (  ) 

Copy connected components

Returns:
connected components

int DLConnectedComponents::dlGetNumCCs (  )  const

Get the number of connected components

Returns:
result

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()

Returns:
component map integer vector

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().

Parameters:
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.


The documentation for this class was generated from the following file:

DOCLIB is being developed under contract by a collaboration between:
The Laboratory for Language and Media Processing
Unviersity of Maryland, College Park
and
Booz | Allen | Hamilton

All Rights Reserved, 2003-2007