DGtalTools  0.9.4
ATu0v1.h
1 
17 #pragma once
18 
33 #if defined(ATu0v1_RECURSES)
34 #error Recursive header files inclusion detected in ATu0v1.h
35 #else // defined(ATu0v1_RECURSES)
36 
37 #define ATu0v1_RECURSES
38 
39 #if !defined ATu0v1_h
40 
41 #define ATu0v1_h
42 
44 // Inclusions
45 #include <iostream>
46 // always include EigenSupport.h before any other Eigen headers
47 #include "DGtal/math/linalg/EigenSupport.h"
48 #include "DGtal/base/Common.h"
49 #include "DGtal/dec/DiscreteExteriorCalculus.h"
50 #include "DGtal/dec/DiscreteExteriorCalculusSolver.h"
51 #include "DGtal/dec/DiscreteExteriorCalculusFactory.h"
52 #include "DECImageHelpers.h"
53 
55 
56 namespace DGtal
57 {
58 
60  // template class ATu0v1
72  template < typename TKSpace,
73  typename TLinearAlgebra = EigenLinearAlgebraBackend >
74  struct ATu0v1 : public DECImage2D<TKSpace, TLinearAlgebra>
75  {
76  typedef TKSpace KSpace;
77  typedef TLinearAlgebra LinearAlgebra;
79  using typename Base::Space;
80  using typename Base::Point;
81  using typename Base::RealVector;
82  using typename Base::Scalar;
83  using typename Base::SCell;
84  using typename Base::Domain;
85  using typename Base::Calculus;
86  using typename Base::Index;
87  using typename Base::PrimalForm0;
88  using typename Base::PrimalForm1;
89  using typename Base::PrimalForm2;
90  using typename Base::PrimalIdentity0;
91  using typename Base::PrimalIdentity1;
92  using typename Base::PrimalIdentity2;
93  using typename Base::PrimalDerivative0;
94  using typename Base::PrimalDerivative1;
95  using typename Base::DualDerivative0;
96  using typename Base::DualDerivative1;
97  using typename Base::PrimalHodge0;
98  using typename Base::PrimalHodge1;
99  using typename Base::PrimalHodge2;
100  using typename Base::DualHodge0;
101  using typename Base::DualHodge1;
102  using typename Base::DualHodge2;
103  using Base::calculus;
104  using Base::verbose;
105  using Base::D0;
106  using Base::D1;
107  using Base::dual_D0;
108  using Base::dual_D1;
109  using Base::primal_h0;
110  using Base::primal_h1;
111  using Base::primal_h2;
112  using Base::dual_h0;
113  using Base::dual_h1;
114  using Base::dual_h2;
115 
116  typedef typename LinearAlgebra::SolverSimplicialLLT LinearAlgebraSolver;
121 
123 
124  // ----------------------- Standard services ------------------------------
125  public:
126 
130  ~ATu0v1() = default;
131 
136  ATu0v1( int _verbose = 1 );
137 
141  void init( Clone<KSpace> K );
142 
147  ATu0v1 ( const ATu0v1 & other ) = delete;
148 
153  ATu0v1 ( ATu0v1 && other ) = delete;
154 
160  ATu0v1 & operator= ( const ATu0v1 & other ) = delete;
161 
167  ATu0v1 & operator= ( ATu0v1 && other ) = delete;
168 
197  template <typename Image, typename Function >
198  void addInput( const Image& image,
199  const Function& f,
200  bool perfect_data = false );
201 
205  void setUFromInput();
206 
215  void setAlpha( Scalar _alpha );
216 
232  void setAlpha( Scalar _alpha, const PrimalForm0& m );
233 
244  void setLambda( Scalar _lambda );
245 
256  void setEpsilon( Scalar _epsilon );
257 
259  Scalar computeSNR() const;
260 
262  Scalar getAlpha() const { return alpha; }
263 
265  Scalar getLambda() const { return lambda; }
266 
268  Scalar getEpsilon() const { return epsilon; }
269 
272  const PrimalForm0& getG( int i ) const { return g0.at( i ); }
273 
276  const PrimalForm0& getU( int i ) const { return u0.at( i ); }
277 
279  const PrimalForm1& getV() const { return v1; }
280 
282  unsigned int size0() const { return alpha_Id0.myContainer.columns(); }
283 
285  unsigned int size1() const { return v1.myContainer.rows(); }
286 
287  // ----------------------- Solver --------------------------------------
288  public:
289 
292  bool solveU();
293 
296  bool solveV();
297 
303 
306  Scalar checkV();
307 
308  // ----------------------- Interface --------------------------------------
309  public:
310 
315  void selfDisplay ( std::ostream & out ) const;
316 
321  bool isValid() const;
322 
323 
324  // ------------------------- Public Datas ------------------------------
325  public:
326 
333 
336 
337  // ------------------------- Protected Datas ------------------------------
338  protected:
339 
341  std::vector< PrimalForm0 > g0;
343  std::vector< PrimalForm0 > i0;
345  std::vector< PrimalForm0 > u0;
351  double alpha;
353  double lambda;
355  double epsilon;
356 
361 
365  std::vector< PrimalForm0 > alpha_g0;
374 
375  // ------------------------- Private Datas --------------------------------
376  private:
377 
378  // ------------------------- Hidden services ------------------------------
379  protected:
380 
381  // ------------------------- Internals ------------------------------------
382  private:
383 
384  }; // end of class ATu0v1
385 
386 
393  template <typename TKSpace, typename TLinearAlgebra>
394  std::ostream&
395  operator<< ( std::ostream & out, const ATu0v1<TKSpace, TLinearAlgebra> & object );
396 
397 } // namespace DGtal
398 
399 
401 // Includes inline functions.
402 //#include "DGtal/dec/ATu0v1.ih"
403 #include "ATu0v1.ih"
404 
405 // //
407 
408 #endif // !defined ATu0v1_h
409 
410 #undef ATu0v1_RECURSES
411 #endif // else defined(ATu0v1_RECURSES)
std::vector< PrimalForm0 > u0
The u 0-forms.
Definition: ATu0v1.h:345
void setEpsilon(Scalar _epsilon)
Calculus::PrimalHodge0 PrimalHodge0
Space::Point Point
PrimalIdentity1 l_L1
lambda * edge laplacien
Definition: ATu0v1.h:367
DiscreteExteriorCalculusSolver< Calculus, LinearAlgebraSolver, 0, PRIMAL, 0, PRIMAL > SolverU
Definition: ATu0v1.h:118
double alpha
Smoothness parameter alpha of AT (in 1/area unit)
Definition: ATu0v1.h:351
std::vector< PrimalForm0 > g0
The g 0-forms.
Definition: ATu0v1.h:341
PrimalIdentity1 left_V1
epsilon * lambda * edge laplacien + (lambda / (4*epsilon)) * Id1
Definition: ATu0v1.h:371
std::vector< PrimalForm0 > alpha_g0
alpha g0
Definition: ATu0v1.h:365
Calculus::DualHodge0 DualHodge0
ATu0v1 & operator=(const ATu0v1 &other)=delete
Calculus::PrimalDerivative0 PrimalDerivative0
DualDerivative0 dual_D0
dual derivative dual 0-form -> dual 1-form
Scalar computeVariation()
~ATu0v1()=default
BOOST_STATIC_ASSERT((KSpace::dimension==2))
Calculus::DualDerivative1 DualDerivative1
Scalar getEpsilon() const
Definition: ATu0v1.h:268
double lambda
Amount of discontinuity parameter lambda (in 1/length unit).
Definition: ATu0v1.h:353
void setAlpha(Scalar _alpha)
Aim: This class simplifies the development of 2D image processing tools using discrete exterior calcu...
const PrimalForm0 & getG(int i) const
Definition: ATu0v1.h:272
Calculus::PrimalHodge1 PrimalHodge1
PrimalHodge2 primal_h2
hodge star: 2-form -> dual 2-form
DualDerivative1 dual_D1
dual derivative dual 1-form -> dual 2-form
PrimalIdentity0 alpha_Id0
alpha Id0
Definition: ATu0v1.h:363
DiscreteExteriorCalculusSolver< Calculus, LinearAlgebraSolver, 1, PRIMAL, 1, PRIMAL > SolverV
Definition: ATu0v1.h:120
Container myContainer
DualHodge0 dual_h0
hodge star: dual 0-form -> 0-form
TLinearAlgebra LinearAlgebra
Definition: ATu0v1.h:77
RealVector::Component Scalar
Calculus::PrimalHodge2 PrimalHodge2
void addInput(const Image &image, const Function &f, bool perfect_data=false)
Calculus::PrimalForm2 PrimalForm2
Calculus::PrimalIdentity2 PrimalIdentity2
double epsilon
Thickness of discontinuity set (in length unit).
Definition: ATu0v1.h:355
PrimalForm1 v1
The v 1-form.
Definition: ATu0v1.h:347
PrimalIdentity1 L1
edge laplacien
Definition: ATu0v1.h:335
bool isValid() const
Scalar checkV()
PrimalForm1 l_1_over_4e
lambda 1/(4*epsilon) 1
Definition: ATu0v1.h:373
Space::RealVector RealVector
Calculus::PrimalForm1 PrimalForm1
Scalar delta_v_loo
The Linfinity-norm of variation of v.
Definition: ATu0v1.h:332
DiscreteExteriorCalculus< 2, 2, LinearAlgebra > Calculus
unsigned int size0() const
Definition: ATu0v1.h:282
unsigned int size1() const
Definition: ATu0v1.h:285
void selfDisplay(std::ostream &out) const
TKSpace KSpace
Definition: ATu0v1.h:76
DualHodge1 dual_h1
hodge star: dual 1-form -> 1-form
Calculus::DualHodge2 DualHodge2
LinearAlgebra::SolverSimplicialLLT LinearAlgebraSolver
Definition: ATu0v1.h:116
Calculus::PrimalIdentity1 PrimalIdentity1
void setLambda(Scalar _lambda)
Calculus::PrimalDerivative1 PrimalDerivative1
SolverU solver_u
The solver for every 0-form u[i].
Definition: ATu0v1.h:358
KSpace::SCell SCell
Calculus::DualHodge1 DualHodge1
PrimalForm1 former_v1
The v 1-form at the previous iteration.
Definition: ATu0v1.h:349
int verbose
The verbose level (0: silent).
ATu0v1(int _verbose=1)
Scalar getAlpha() const
Definition: ATu0v1.h:262
DECImage2D< TKSpace, TLinearAlgebra > Base
Definition: ATu0v1.h:78
Calculus::PrimalIdentity0 PrimalIdentity0
void setUFromInput()
PrimalForm1 l_1_over_4
lambda 1/4 1
Definition: ATu0v1.h:369
Calculus calculus
The discrete exterior calculus instance.
const PrimalForm1 & getV() const
Definition: ATu0v1.h:279
std::vector< PrimalForm0 > i0
The ideal input 0-forms (for snr computation).
Definition: ATu0v1.h:343
PrimalHodge0 primal_h0
hodge star: 0-form -> dual 0-form
Calculus::DualDerivative0 DualDerivative0
Aim: This class solves Ambrosio-Tortorelli functional in a plane for u a (vector of) 0-form(s) and v ...
Definition: ATu0v1.h:74
DualHodge2 dual_h2
hodge star: dual 2-form -> 2-form
Scalar delta_v_l1
The L1-norm of variation of v.
Definition: ATu0v1.h:328
KSpace::Space Space
Scalar getLambda() const
Definition: ATu0v1.h:265
PrimalDerivative0 D0
primal derivative: 0-form -> 1-form
const PrimalForm0 & getU(int i) const
Definition: ATu0v1.h:276
Scalar delta_v_l2
The L2-norm of variation of v.
Definition: ATu0v1.h:330
SolverV solver_v
The solver for 1-form v.
Definition: ATu0v1.h:360
static const constexpr Dimension dimension
PrimalDerivative1 D1
primal derivative: 1-form -> 2-form
void init(Clone< KSpace > K)
PrimalHodge1 primal_h1
hodge star: 1-form -> dual 1-form
Scalar computeSNR() const
Computes the SNR of u wrt ideal input (should have been given.
Calculus::Index Index
Calculus::PrimalForm0 PrimalForm0
HyperRectDomain< Space > Domain
RealVector::Component Scalar