LTI-Lib latest version v1.9 - last update 10 Apr 2010

lti::regionGraphFunctor< G > Class Template Reference

Functor to manipulate graphs of adjacent image regions. More...

#include <ltiRegionGraphFunctor.h>

Inheritance diagram for lti::regionGraphFunctor< G >:
Inheritance graph
[legend]
Collaboration diagram for lti::regionGraphFunctor< G >:
Collaboration graph
[legend]

List of all members.

Classes

class  parameters
 the parameters for the class regionGraphFunctor More...

Public Types

typedef G graph_type
typedef graph_type::edge_traits edge_traits
typedef graph_type::weight_type weight_type
typedef graph_type::node_pair node_pair
typedef graph_type::node_type node_type
typedef graph_type::edge_data_type edge_data_type

Public Member Functions

 regionGraphFunctor (const bool initParams=true)
 regionGraphFunctor (const typename parameters::eMergeMode &mode, const weight_type &threshold=weight_type())
 regionGraphFunctor (const parameters &par)
 regionGraphFunctor (const regionGraphFunctor &other)
virtual ~regionGraphFunctor ()
virtual const char * getTypeName () const
regionGraphFunctorcopy (const regionGraphFunctor &other)
regionGraphFunctoroperator= (const regionGraphFunctor &other)
virtual functorclone () const
const parametersgetParameters () const
bool apply (const matrix< int > &regions, const int minLabel, graph_type &graph)
bool apply (const weight_type &threshold, graph_type &graph, ivector &equivalences)
bool apply (graph_type &graph, ivector &equivalences)
bool apply (const weight_type &threshold, const int minLabel, graph_type &graph, ivector &equivalences)
bool apply (const int minLabel, graph_type &graph, ivector &equivalences)
bool generate (const matrix< int > &regions, const int minLabel, graph_type &graph)
bool generate (const matrix< int > &regions, const int minLabel, const std::vector< node_type > &data, graph_type &graph)
virtual bool affinityMatrix (const graph_type &graph, matrix< weight_type > &affinity, const weight_type noEdgeValue=weight_type()) const
virtual bool merge (const weight_type &threshold, graph_type &graph, ivector &equivalences) const
virtual bool merge (const weight_type &threshold, const int minLabel, graph_type &graph, ivector &equivalences) const
bool reassignLabels (const ivector &equivalences, imatrix &regions, const bool compact=false) const
bool reassignLabels (const ivector &equivalences, const imatrix &regions, imatrix &newRegions, const bool compact=false) const
bool reassignLabels (const ivector &equivalences, const imatrix &regions, imatrix &newRegions, ivector &regionSizes, const bool compact=false) const
bool reassignLabels (const ivector &equivalences, imatrix &regions, ivector &regionSizes, const bool compact=false) const
int compactLabels (const ivector &equivalences, ivector &newEquivalences) const

Protected Member Functions

bool mirrorEdgeData (graph_type &graph) const
bool generateWorker (const matrix< int > &regions, const int minLabel, graph_type &graph)
Methods to be reimplemented



virtual bool checkInternalData (const point &regionsSize, const int maxRegionIndex) const
virtual bool considerForEdgeData (const point &p1, const point &p2, edge_data_type &edgeData)
virtual bool considerForNodeData (const point &p1, const int label, node_type &nodeData)
virtual bool prepareEdgeAndNodeData (graph_type &graph)

Detailed Description

template<class G>
class lti::regionGraphFunctor< G >

Functor to manipulate graphs of adjacent image regions.

This class provides some functionality to create and manipulate lti::adjacencyGraph data structures in the context of image region analysis.

It is a template class with template parameter G, which is expected to be a valid lti::adjacencyGraph type.

The class is "almost" abstract, since the real useful instances belong to derived classes that implement specific graph generation and merging strategies. However, it can be used as a standalone class for simple graph operations where only the topology of the graph is of interest.

Derived classes should reimplement following protected methods:

An important constraint to the graph is that the data (not the weights) associated to an edge (a,b) is always the same data associated to edge (b,a).


Member Typedef Documentation

template<class G>
typedef graph_type::edge_data_type lti::regionGraphFunctor< G >::edge_data_type
template<class G>
typedef graph_type::edge_traits lti::regionGraphFunctor< G >::edge_traits

Edge traits.

template<class G>
typedef G lti::regionGraphFunctor< G >::graph_type
template<class G>
typedef graph_type::node_pair lti::regionGraphFunctor< G >::node_pair

Edge denotation with the pair of node ids.

template<class G>
typedef graph_type::node_type lti::regionGraphFunctor< G >::node_type

Edge denotation with the pair of node ids.

Reimplemented in lti::regionGraphColor< F >, lti::regionGraphGray< F >, and lti::regionGraphColor< regionGraphColorHarisDistance >.

template<class G>
typedef graph_type::weight_type lti::regionGraphFunctor< G >::weight_type

Type used for the weights.

They should usually be float or double, but any type supported by the lti::vector can be used.

Reimplemented in lti::regionGraphColor< F >, lti::regionGraphGray< F >, and lti::regionGraphColor< regionGraphColorHarisDistance >.


Constructor & Destructor Documentation

template<class G>
lti::regionGraphFunctor< G >::regionGraphFunctor ( const bool  initParams = true  ) 

default constructor

template<class G>
lti::regionGraphFunctor< G >::regionGraphFunctor ( const typename parameters::eMergeMode mode,
const weight_type threshold = weight_type() 
)

default constructor

template<class G>
lti::regionGraphFunctor< G >::regionGraphFunctor ( const parameters par  ) 

Construct a functor using the given parameters.

template<class G>
lti::regionGraphFunctor< G >::regionGraphFunctor ( const regionGraphFunctor< G > &  other  ) 

copy constructor

Parameters:
other the object to be copied
template<class G>
virtual lti::regionGraphFunctor< G >::~regionGraphFunctor (  )  [virtual]

destructor


Member Function Documentation

template<class G>
virtual bool lti::regionGraphFunctor< G >::affinityMatrix ( const graph_type graph,
matrix< weight_type > &  affinity,
const weight_type  noEdgeValue = weight_type() 
) const [virtual]

Compute the affinity matrix and degree vector for the given graph.

The affinity matrix containts the weights of the edges. The degree vector the sum of the outgoing edges for each node.

Several functors can require this sort of data structures. One prominent example is the functor lti::multiclassNormalizedCuts.

template<class G>
bool lti::regionGraphFunctor< G >::apply ( const int  minLabel,
graph_type graph,
ivector equivalences 
)

Alias for merge() taking the threshold from the parameters.

Reimplemented in lti::regionGraphColor< regionGraphColorHarisDistance >.

template<class G>
bool lti::regionGraphFunctor< G >::apply ( const weight_type threshold,
const int  minLabel,
graph_type graph,
ivector equivalences 
)
template<class G>
bool lti::regionGraphFunctor< G >::apply ( graph_type graph,
ivector equivalences 
)

Alias for merge() taking the threshold from the parameters.

Reimplemented in lti::regionGraphColor< regionGraphColorHarisDistance >.

template<class G>
bool lti::regionGraphFunctor< G >::apply ( const weight_type threshold,
graph_type graph,
ivector equivalences 
)
template<class G>
bool lti::regionGraphFunctor< G >::apply ( const matrix< int > &  regions,
const int  minLabel,
graph_type graph 
)
template<class G>
virtual bool lti::regionGraphFunctor< G >::checkInternalData ( const point regionsSize,
const int  maxRegionIndex 
) const [protected, virtual]

Check if the internal data is compatible with the region mask.

The weights between region nodes can be computed from very different information sources. Usually, this information is coded in images and channels also extracted from the same image from which the regions map was computed. Therefore, it is important to provide a way to check if the internal data is compatible with the regions map, since both must be provided by the user at different times.

Parameters:
regionsSize size of the original image and region mask. This allows to check for channels and other data in the original image size format.
maxRegionIndex maximum region index employed. This is used to check if the vectors with information per region have the appropriate size.
Returns:
true if the internal data is compatible, false if there are problems.

Reimplemented in lti::regionGraphColor< F >, lti::regionGraphGray< F >, and lti::regionGraphColor< regionGraphColorHarisDistance >.

template<class G>
virtual functor* lti::regionGraphFunctor< G >::clone (  )  const [virtual]
template<class G>
int lti::regionGraphFunctor< G >::compactLabels ( const ivector equivalences,
ivector newEquivalences 
) const

Compact labels.

Recompute the equivalences vector to use a compact set of labels.

Parameters:
equivalences equivalences vector as returned by merge()
newEquivalences new compact equivalences vector, where only a compact set of labels is used.
Returns:
the total number of labels now being used.
template<class G>
virtual bool lti::regionGraphFunctor< G >::considerForEdgeData ( const point p1,
const point p2,
edge_data_type edgeData 
) [protected, virtual]

For each two neighbor pixels that belong to different regions, this method is called to compute the edge data value in a sequential manner.

It will be assumed, that the default constructor of the graph_type::edge_type::data_type "resets" correctly the data of the edge.

Parameters:
p1 coordinates of pixel belonging to one region
p2 coordinates of pixel belonging to another region
edgeData reference to data structure of the edge, where some values can be accumulated or set.
Returns:
true if successful, false otherwise.

Reimplemented in lti::regionGraphColor< regionGraphColorHarisDistance >.

template<class G>
virtual bool lti::regionGraphFunctor< G >::considerForNodeData ( const point p1,
const int  label,
node_type nodeData 
) [protected, virtual]

For each pixel in each region, this method is called once to compute statistics or other data for each node.

Parameters:
p1 coordinates of the current pixel
label identification label for the region to which the pixel belongs.
nodeData reference to the data structure of the node, where some values can be accumulated or set.
Returns:
true if successful, false otherwise.

Reimplemented in lti::regionGraphColor< regionGraphColorHarisDistance >.

template<class G>
regionGraphFunctor& lti::regionGraphFunctor< G >::copy ( const regionGraphFunctor< G > &  other  ) 

copy data of "other" functor.

Parameters:
other the functor to be copied
Returns:
a reference to this functor object

Reimplemented from lti::functor.

template<class G>
bool lti::regionGraphFunctor< G >::generate ( const matrix< int > &  regions,
const int  minLabel,
const std::vector< node_type > &  data,
graph_type graph 
)

Generate the adjacency graph for the given labeled mask regions, using for each region-node the data contained in the given data vector.

However, the method considerForNodeData() has priority, i.e. if this method can change the node's data.

This will ensure that the node id corresponds to the region label.

Parameters:
regions the labeled mask to be analyzed
minLabel only the adjacency between region-labels greater or equal this value will be fully analyzed. No graph edges between regions with labels lower than minLabel will be detected.
data vector containing at the element index i data for the node representing region i.
graph the adjacency graph to be generated
Returns:
true if successful, false otherwise.
template<class G>
bool lti::regionGraphFunctor< G >::generate ( const matrix< int > &  regions,
const int  minLabel,
graph_type graph 
)

Generate the adjacency graph for the given labeled mask regions.

The generation of a graph consists of three phases:

  1. Topology creation. Here the graph topology is determined traversing the given regions mask and detecting adjacent pixels. While traversing, edge and node data can be accumulated or computed using the virtual methods considerForEdgeData() and considerForNodeData().
  2. Data preparation. Once some data in the nodes and edges has been collected, you can prepare it for the computation of weights. This means, you can compute histograms, maxima and minima, etc. which can be used to control the range where the weights will be.
  3. Edge weight computation. The method in the edge_type of the graph "weight()" will be used to compute the weights of all edges at once.

This method ensures that the node ids corresponds to the region labels.

Parameters:
regions the labeled mask to be analyzed
minLabel only the adjacency between region-labels greater or equal this value will be fully analyzed. No graph edges between regions with labels lower than minLabel will be detected.
graph the adjacency graph to be generated
Returns:
true if successful, false otherwise.
template<class G>
bool lti::regionGraphFunctor< G >::generateWorker ( const matrix< int > &  regions,
const int  minLabel,
graph_type graph 
) [protected]

Generate the adjacency graph for the given labeled mask regions.

It is assumed that the nodes of the graph have been already initialized.

Parameters:
regions the labeled mask to be analyzed
minLabel only the adjacency between region-labels greater or equal this value will be fully analyzed. No graph edges between regions with labels lower than minLabel will be detected.
graph the adjacency graph to be generated
Returns:
true if successful, false otherwise.
template<class G>
const parameters& lti::regionGraphFunctor< G >::getParameters (  )  const

returns used parameters

Reimplemented from lti::functor.

template<class G>
virtual const char* lti::regionGraphFunctor< G >::getTypeName (  )  const [virtual]

returns the name of this type ("regionGraphFunctor")

Reimplemented from lti::functor.

Reimplemented in lti::regionGraphColor< F >, lti::regionGraphGray< F >, and lti::regionGraphColor< regionGraphColorHarisDistance >.

template<class G>
virtual bool lti::regionGraphFunctor< G >::merge ( const weight_type threshold,
const int  minLabel,
graph_type graph,
ivector equivalences 
) const [virtual]

Merge all nodes whose edges have a weight smaller or equal than the given threshold and one or both nodes have a label above or equal the given minLabel.

The output will be not only the new graph with the merged data, but an equivalences vector, where for each node id in the original graph a new id is determined.

template<class G>
virtual bool lti::regionGraphFunctor< G >::merge ( const weight_type threshold,
graph_type graph,
ivector equivalences 
) const [virtual]

Merge all nodes whose edges have a weight smaller or equal than the given threshold.

The output will be not only the new graph with the merged data, but an equivalences vector, where for each node id in the original graph a new id is determined.

template<class G>
bool lti::regionGraphFunctor< G >::mirrorEdgeData ( graph_type graph  )  const [protected]

Copy the bottom left diagonal matrix into the upper left.

This is used if a symmetric graph has been used, for which at first only the data in the bottom matrix is computed.

template<class G>
regionGraphFunctor& lti::regionGraphFunctor< G >::operator= ( const regionGraphFunctor< G > &  other  ) 

alias for copy member

Parameters:
other the functor to be copied
Returns:
a reference to this functor object

Reimplemented from lti::functor.

template<class G>
virtual bool lti::regionGraphFunctor< G >::prepareEdgeAndNodeData ( graph_type graph  )  [protected, virtual]

This method is called just after the topological graph has been build and all data of edges and nodes has been considered, and before the weights are computed.

You can overload this method to, for example, compute mean values per region, compute the min an max values of the means, to adaptivelly assign the weights to predefined ranges, etc.

Warning:
: only the data for the edges(a,b) with a<b contain valid data.
template<class G>
bool lti::regionGraphFunctor< G >::reassignLabels ( const ivector equivalences,
imatrix regions,
ivector regionSizes,
const bool  compact = false 
) const

Simple helper method to reassign the labels used in the given labeled mask using an equivalences vector, as computed by merge.

You must ensure that the equivalences vector has enough elements to avoid an improper memory access, i.e. equivalences.size() > regions.maximum().

Parameters:
equivalences vector containing for each label i the new label.
regions matrix with the source input labels, the resulting labels will be left here too.
regionSizes recompute the number of pixels per eventually new region label.
compact flag to indicate if the equivalences should be use as they are (false), or if a new labels set should be computed which lies between 0 and n-1, with n the total number of different labels used in the equivalences vector.
Returns:
true if successful, false otherwise.
template<class G>
bool lti::regionGraphFunctor< G >::reassignLabels ( const ivector equivalences,
const imatrix regions,
imatrix newRegions,
ivector regionSizes,
const bool  compact = false 
) const

Simple helper method to reassign the labels used in the given labeled mask using an equivalences vector, as computed by merge.

You must ensure that the equivalences vector has enough elements to avoid an improper memory access, i.e. equivalences.size() > regions.maximum().

Parameters:
equivalences vector containing for each label i the new label.
regions matrix with the source input labels.
newRegions the new labels mask will be left here.
regionSizes recompute the number of pixels per eventually new region label.
compact flag to indicate if the equivalences should be use as they are (false), or if a new labels set should be computed which lies between 0 and n-1, with n the total number of different labels used in the equivalences vector.
Returns:
true if successful, false otherwise.
template<class G>
bool lti::regionGraphFunctor< G >::reassignLabels ( const ivector equivalences,
const imatrix regions,
imatrix newRegions,
const bool  compact = false 
) const

Simple helper method to reassign the labels used in the given labeled mask using an equivalences vector, as computed by merge.

You must ensure that the equivalences vector has enough elements to avoid an improper memory access, i.e. equivalences.size() > regions.maximum().

Parameters:
equivalences vector containing for each label i the new label.
regions matrix with the source input labels.
newRegions the new labels mask will be left here.
compact flag to indicate if the equivalences should be use as they are (false), or if a new labels set should be computed which lies between 0 and n-1, with n the total number of different labels used in the equivalences vector.
Returns:
true if successful, false otherwise.
template<class G>
bool lti::regionGraphFunctor< G >::reassignLabels ( const ivector equivalences,
imatrix regions,
const bool  compact = false 
) const

Simple helper method to reassign the labels used in the given labeled mask using an equivalences vector, as computed by merge.

You must ensure that the equivalences vector has enough elements to avoid an improper memory access, i.e. equivalences.size() > regions.maximum().

Parameters:
equivalences vector containing for each label i the new label.
regions matrix with the source input labels. The result will be left here too.
compact flag to indicate if the equivalences should be use as they are (false), or if a new labels set should be computed which lies between 0 and n-1, with n the total number of different labels used in the equivalences vector.
Returns:
true if successful, false otherwise.

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

Generated on Sat Apr 10 15:27:45 2010 for LTI-Lib by Doxygen 1.6.1