aimsalgo  5.1.2
Neuroimaging image processing
peronaMalikSmoother.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 
35 #ifndef AIMS_PRIMALSKETCH_PERONAMALIKSMOOTHER_H
36 #define AIMS_PRIMALSKETCH_PERONAMALIKSMOOTHER_H
37 
39 
40 namespace aims
41 {
42 
43  template<class T> class PeronaMalikSmoother
44  : public Smoother<carto::VolumeRef<T>, carto::VolumeRef<T> >
45  {
46 
47  private:
48 
49  float _K; // control of the gradient - proportion of gradients which are NOT edges - generally around 0.98
50  float _gradK; // the actual gradient bound, computed from K and the image to be processed
51  float _sigma; // regularisation parameter (i.e. smoothing of the gradient)
52  float _dt;
53 
54  int _conductance; // vaut 1, ou 2, ou autrre si on rajoute des fonctions de conductance
55 
56  inline float conductance(float x)
57  {
58  switch (_conductance)
59  {
60  case 1: return(conductance1(x));
61  case 2: return(conductance2(x));
62  default : exit(EXIT_FAILURE);
63  }
64  }
65 
66  inline float conductance1(float x)
67  { return (1.0/float(1.0+(x*x)/(_gradK*_gradK))); }
68  inline float conductance2(float x)
69  { return (exp(-(x*x)/(_gradK*_gradK))); }
70 
71  void SetDt(float dt)
72  {
73  if (dt<=0.25) _dt=dt;
74  else
75  {
76  std::cerr << "Diffusion Smoother : dt must be <= 0.25" << std::endl;
77  exit(EXIT_FAILURE);
78  }
79  }
80 
81  public:
82 
83  PeronaMalikSmoother(float dt, float K, float sigma, int cond)
84  : _K(K), _sigma(sigma), _conductance(cond) {SetDt(dt);}
85 
87  int maxiter, bool verbose=false);
88 
89  float dt() {return _dt;}
90  bool optimal() {return true;}
91 
92  };
93 
94 }
95 
96 #endif
carto::VolumeRef< T > doSmoothing(const carto::VolumeRef< T > &ima, int maxiter, bool verbose=false)
PeronaMalikSmoother(float dt, float K, float sigma, int cond)