bioprocessing  5.1.2
watershed.h
Go to the documentation of this file.
1 /* Copyright (C) 2000-2013 CEA
2  *
3  * This software and supporting documentation were developed by
4  * bioPICSEL
5  * CEA/DSV/I²BM/MIRCen/LMN, Batiment 61,
6  * 18, route du Panorama
7  * 92265 Fontenay-aux-Roses
8  * France
9  */
10 
11 #ifndef BIOPROCESSING_WATERSHED_WATERSHED
12 #define BIOPROCESSING_WATERSHED_WATERSHED
13 
14 //--- bioprocessing ----------------------------------------------------------
15 #include <bioprocessing/watershed/coustywatershed.h> // Cousty implementation
16 //--- cartodata --------------------------------------------------------------
17 #include <cartodata/volume/volume.h> // carto::VolumeRef
18 //--- cartobase --------------------------------------------------------------
19 #include <cartobase/config/verbose.h> // carto::verbose
20 //--- std --------------------------------------------------------------------
21 #include <string> // std::string
22 //----------------------------------------------------------------------------
23 
24 namespace bio {
25 
31  template <typename T, typename L>
32  class Watershed
33  {
34  public:
38  _implem("cousty"),
39  _verbose(carto::verbose)
40  {}
41 
45  Watershed( const std::string & implem ):
46  _implem(implem),
47  _verbose(carto::verbose)
48  {}
49 
53  void setImplementation( const std::string & implem ) { _implem = implem; }
56  void setVerbose( int verbose = 1 ) { _verbose = verbose; }
58  void setQuiet() { setVerbose(0); }
59 
63  carto::VolumeRef<L> execute( carto::VolumeRef<T> in )
64  {
65  if( _implem == "cousty" )
66  {
67  CoustyWatershed<T,L> watershed;
68  watershed.setVerbose( _verbose );
69  if( in.getSizeX() == 1 )
70  watershed.set2D();
71  _watershed = watershed.execute( in );
72  _minima = watershed.getMinima();
73  return _watershed;
74  }
75  else
76  {
77  std::cout << "unknown watershed implementation" << std::endl;
78  throw;
79  }
80  }
81 
82  carto::VolumeRef<L> getMinima()
83  {
84  return _minima;
85  }
86 
87  protected:
88  std::string _implem;
89  int _verbose;
90  carto::VolumeRef<L> _watershed;
91  carto::VolumeRef<L> _minima;
92  };
93 
94 } // namespace bio
95 
96 #endif // BIOPROCESSING_WATERSHED_WATERSHED
Watershed implementation as described in Cousty et al - Watershed cuts: minimum spanning forests and ...
carto::VolumeRef< L > execute(carto::VolumeRef< T > in)
Allocate and return the watershed segmentation of the input image.
void set2D()
When 2D mode is active, a 2D connectivity is used (4XY)
void setVerbose(int verbose=1)
carto::VolumeRef< L > getMinima()
Interface to watershed implementations.
Definition: watershed.h:33
carto::VolumeRef< L > _minima
Definition: watershed.h:91
std::string _implem
Definition: watershed.h:88
carto::VolumeRef< L > _watershed
Definition: watershed.h:90
void setImplementation(const std::string &implem)
Sets the watershed method Possible implementations are:
Definition: watershed.h:53
Watershed(const std::string &implem)
Constructor from implementation Possible implementations are:
Definition: watershed.h:45
void setQuiet()
Equivalent to setVerbose(0)
Definition: watershed.h:58
carto::VolumeRef< L > execute(carto::VolumeRef< T > in)
Executes the chosen watershed segmentation to the input volume.
Definition: watershed.h:63
carto::VolumeRef< L > getMinima()
Definition: watershed.h:82
Watershed()
Default constructor The default implementation used is Cousty.
Definition: watershed.h:37
void setVerbose(int verbose=1)
Sets the verbosity level.
Definition: watershed.h:56