latest version v1.9 - last update 10 Apr 2010 |
Functor to manipulate graphs of adjacent image regions. More...
#include <ltiRegionGraphFunctor.h>
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 |
regionGraphFunctor & | copy (const regionGraphFunctor &other) |
regionGraphFunctor & | operator= (const regionGraphFunctor &other) |
virtual functor * | clone () const |
const parameters & | getParameters () const |
bool | apply (const matrix< int > ®ions, 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 > ®ions, const int minLabel, graph_type &graph) |
bool | generate (const matrix< int > ®ions, 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 ®ions, const bool compact=false) const |
bool | reassignLabels (const ivector &equivalences, const imatrix ®ions, imatrix &newRegions, const bool compact=false) const |
bool | reassignLabels (const ivector &equivalences, const imatrix ®ions, imatrix &newRegions, ivector ®ionSizes, const bool compact=false) const |
bool | reassignLabels (const ivector &equivalences, imatrix ®ions, ivector ®ionSizes, 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 > ®ions, const int minLabel, graph_type &graph) |
Methods to be reimplemented | |
virtual bool | checkInternalData (const point ®ionsSize, 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) |
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).
typedef graph_type::edge_data_type lti::regionGraphFunctor< G >::edge_data_type |
Edge data type.
Reimplemented in lti::regionGraphColor< F >, lti::regionGraphGray< F >, and lti::regionGraphColor< regionGraphColorHarisDistance >.
typedef graph_type::edge_traits lti::regionGraphFunctor< G >::edge_traits |
Edge traits.
typedef G lti::regionGraphFunctor< G >::graph_type |
Graph type.
Reimplemented in lti::regionGraphColor< F >, lti::regionGraphGray< F >, and lti::regionGraphColor< regionGraphColorHarisDistance >.
typedef graph_type::node_pair lti::regionGraphFunctor< G >::node_pair |
Edge denotation with the pair of node ids.
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 >.
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 >.
lti::regionGraphFunctor< G >::regionGraphFunctor | ( | const bool | initParams = true |
) |
default constructor
lti::regionGraphFunctor< G >::regionGraphFunctor | ( | const typename parameters::eMergeMode & | mode, | |
const weight_type & | threshold = weight_type() | |||
) |
default constructor
lti::regionGraphFunctor< G >::regionGraphFunctor | ( | const parameters & | par | ) |
Construct a functor using the given parameters.
lti::regionGraphFunctor< G >::regionGraphFunctor | ( | const regionGraphFunctor< G > & | other | ) |
copy constructor
other | the object to be copied |
virtual lti::regionGraphFunctor< G >::~regionGraphFunctor | ( | ) | [virtual] |
destructor
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.
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 >.
bool lti::regionGraphFunctor< G >::apply | ( | const weight_type & | threshold, | |
const int | minLabel, | |||
graph_type & | graph, | |||
ivector & | equivalences | |||
) |
Alias for merge().
Reimplemented in lti::regionGraphColor< regionGraphColorHarisDistance >.
bool lti::regionGraphFunctor< G >::apply | ( | graph_type & | graph, | |
ivector & | equivalences | |||
) |
Alias for merge() taking the threshold from the parameters.
Reimplemented in lti::regionGraphColor< regionGraphColorHarisDistance >.
bool lti::regionGraphFunctor< G >::apply | ( | const weight_type & | threshold, | |
graph_type & | graph, | |||
ivector & | equivalences | |||
) |
Alias for merge().
Reimplemented in lti::regionGraphColor< regionGraphColorHarisDistance >.
bool lti::regionGraphFunctor< G >::apply | ( | const matrix< int > & | regions, | |
const int | minLabel, | |||
graph_type & | graph | |||
) |
Alias for generate().
Reimplemented in lti::regionGraphColor< regionGraphColorHarisDistance >.
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.
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. |
Reimplemented in lti::regionGraphColor< F >, lti::regionGraphGray< F >, and lti::regionGraphColor< regionGraphColorHarisDistance >.
virtual functor* lti::regionGraphFunctor< G >::clone | ( | ) | const [virtual] |
returns a pointer to a clone of this functor.
Implements lti::functor.
Reimplemented in lti::regionGraphColor< F >, lti::regionGraphGray< F >, and lti::regionGraphColor< regionGraphColorHarisDistance >.
int lti::regionGraphFunctor< G >::compactLabels | ( | const ivector & | equivalences, | |
ivector & | newEquivalences | |||
) | const |
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.
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. |
Reimplemented in lti::regionGraphColor< regionGraphColorHarisDistance >.
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.
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. |
Reimplemented in lti::regionGraphColor< regionGraphColorHarisDistance >.
regionGraphFunctor& lti::regionGraphFunctor< G >::copy | ( | const regionGraphFunctor< G > & | other | ) |
copy data of "other" functor.
other | the functor to be copied |
Reimplemented from lti::functor.
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.
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 |
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:
This method ensures that the node ids corresponds to the region labels.
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 |
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.
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 |
const parameters& lti::regionGraphFunctor< G >::getParameters | ( | ) | const |
returns used parameters
Reimplemented from lti::functor.
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 >.
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.
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.
bool lti::regionGraphFunctor< G >::mirrorEdgeData | ( | graph_type & | graph | ) | const [protected] |
regionGraphFunctor& lti::regionGraphFunctor< G >::operator= | ( | const regionGraphFunctor< G > & | other | ) |
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.
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().
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. |
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().
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. |
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().
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. |
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().
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. |