11 #ifndef BIOPROCESSING_WATERSHED_COUSTY
12 #define BIOPROCESSING_WATERSHED_COUSTY
19 #include <aims/vector/vector.h>
21 #include <cartodata/volume/volume.h>
23 #include <cartobase/config/verbose.h>
38 template <
typename T,
typename L>
67 carto::VolumeRef<L>
execute( carto::VolumeRef<T> in );
70 void execute( carto::VolumeRef<T> in, carto::VolumeRef<L> out );
100 template <
typename T,
typename L>
103 carto::VolumeRef<L> out( in.getSizeX(), in.getSizeY(),
104 in.getSizeZ(), in.getSizeT() );
105 out->copyHeaderFrom( in.header() );
110 template <
typename T,
typename L>
112 carto::VolumeRef<L> out )
115 _g =
Graph( in, aims::strel::Connectivity6XYZ() );
117 _g =
Graph( in, aims::strel::Connectivity4XY() );
119 _psi.setVolume( out );
120 _psi.init( _g.beginVertex(), _g.endVertex() );
124 template <
typename T,
typename L>
130 typename FlowMap::iterator i;
133 long size = _psi.size();
135 std::cout << std::endl;
136 for( i = _psi.begin() ; i != _psi.end(); ++i )
138 if( _verbose && ( ++j % 10000 == 0 ) )
139 std::cout <<
"\rVertex: " << j <<
"/" << size << std::flush;
142 if( lab == _psi.labelNone() )
144 lab = computeStream( x );
145 if( lab == _psi.labelMinus() )
146 setLabel( ++nb_labs );
153 std::cout << std::endl <<
"Labels created: " << nb_labs << std::endl;
156 template <
typename T,
typename L>
160 for( i = _s.begin(); i != _s.end(); ++i )
162 _psi.setLabel( *i, lab );
166 template <
typename T,
typename L>
179 breadth_first =
true;
180 while( breadth_first && findEdge( y, z ) )
183 if( lab != _psi.labelNone() )
185 else if( _g.Fm( z ) < _g.Fm( y ) )
189 breadth_first =
false;
199 return _psi.labelMinus();
202 template <
typename T,
typename L>
206 for( e = _g.beginEdge(y); e != _g.endEdge(y); ++e )
211 if( _g.weight( *e ) == _g.Fm( y ) )
void erase(const Vertex &v)
Pointed::iterator iterator
std::pair< iterator, bool > insert(const Vertex &v)
const_iterator begin() const
Watershed implementation as described in Cousty et al - Watershed cuts: minimum spanning forests and ...
L computeStream(Vertex x)
Follows the descent stream from vertex v.
Point4dl Point
Point type.
carto::VolumeRef< L > execute(carto::VolumeRef< T > in)
Allocate and return the watershed segmentation of the input image.
void computeWatershed()
Iterates on the vertices of the image, and for each one follows a descent stream until it encounters ...
Graph::Vertex Vertex
Vertex type.
VolumeGraphRef< T, Point > Graph
Graph type.
void set2D()
When 2D mode is active, a 2D connectivity is used (4XY)
bool findEdge(Vertex y, Vertex &z)
Finds an edge of minimum altitude for y.
CoustyFlowMapRef< Vertex, L > FlowMap
FlowMap type (the labelled image)
void setVerbose(int verbose=1)
Graph::Edge Edge
Edge type.
carto::VolumeRef< L > getMinima()
CoustyStreamRef< Vertex > Stream
Stream type (a set of vertices)
void set3D()
When 3D mode is active, a 3D connectivity is used (6XYZ)
void setLabel(L lab)
Sets the label lab for all vertices in the stream _s.
Pointed::edge_iterator edge_iterator