11 #define SQR(_X) ((_X)*(_X))
14 #define CUBE(_X) ((_X)*(_X)*(_X))
16 typedef double (* PSIREG)(
const double,
const int np,
double *p);
36 PRIOR_GENERICSCALESPACE,
56 virtual const char *GetName()
const = 0;
59 inline double GetTau()
const
62 inline int GetNParam()
const
65 virtual double GetValue (
const RVector &x)
const = 0;
88 virtual int GetHessianRow (
const RVector &x,
int i, idxtype *colidx,
89 double *val)
const = 0;
99 virtual PRIOR Type()
const = 0;
113 idxtype *rowptr, *colidx;
121 Regularisation_1stOrder (
const Raster *_raster = 0,
const RVector *_x0 = 0);
122 virtual ~Regularisation_1stOrder () {};
133 class STOASTLIB
GenericSigma :
public Regularisation_1stOrder {
140 double * _preg,
double _tau = 1e-2,
double _sdx = 0,
double _sdf = 0,
141 const void *_kref=0,
bool _KRefTensFlag =
false);
144 double *_preg,
double _tau,
const RVector &_refimg,
double _sdr,
145 double _sdx = 0,
double _sdf = 0,
double _fT = 0,
146 bool _KRefTensFlag =
false);
150 const char *GetName()
const
151 {
return "GenericSigma"; }
156 RVector *MakeKref (
const RVector &gimgref,
double sdr,
double fT);
166 PRIOR Type()
const {
return PRIOR_GENERICSIGMA; }
172 double GetValue (
const RVector &x)
const;
180 return GetHess1f (x, x - *x0);
190 int GetHessianRow (
const RVector &x,
int i, idxtype *colidx,
double *val)
const;
198 const double sdx, sdf;
199 virtual double func(
const double,
const int np,
double *p)
const = 0;
200 virtual double kfunc(
const double,
const int np,
double *p)
const = 0;
201 virtual double d2func(
const double,
const int np,
double *p)
const = 0;
202 void CreateDerivativeOperators ();
207 const bool KRefTensFlag;
215 inline double sinterp(
const RVector & v,
const int i,
const int j)
217 return 0.5*(v[i] + v[j]);
224 for(
int r = 0; r < tmp.nRows(); r++)
225 for(
int c = 0; c < tmp.nCols(); c++)
226 tmp(r,c) = 0.5*(mat[i](r,c) + mat[j](r,c));
235 double d1 = det(mat[i]);
236 double d2 = det(mat[j]);
237 return (d1 < d2 ? mat[i] : mat[j]);
244 #ifdef TINTERP2D // old version
245 static const int dim = 2;
247 double fx = 0.5*( mat[i](0,0) + mat[j](0,0));
248 double fy = 0.5*( mat[i](1,1) + mat[j](1,1));
249 double fxsq = SQR(fx);
250 double fysq = SQR(fy);
251 double gsq = fxsq + fysq;
252 double T = 0.5*( mat[i](0,1) + mat[j](0,1));
257 double gam = 1- exp( -sqrt(gsq)/T);
258 tmp(0,0) -= (fx == 0.0 ? 0 : gam*fxsq/gsq);
259 tmp(1,1) -= (fy == 0.0 ? 0 : gam*fysq/gsq);
260 tmp(0,1) -= (gsq == 0.0 ? 0 : gam*fx*fy/gsq);
263 #else // new, but untested
267 for (m = 0; m < dim; m++) {
268 f[m] = 0.5*(mat[i](m,m) + mat[j](m,m));
271 double T = 0.5*(mat[i](0,1) + mat[j](0,1));
275 double gam = 1.0-exp(-sqrt(gsq)/T);
276 for (m = 0; m < dim; m++)
277 for (n = 0; n < dim; n++)
278 tmp(m,n) -= (gsq == 0.0 ? 0 : gam*f[m]*f[n]/gsq);
290 TVSigma (
double _tau,
double _beta,
double _sd,
const RVector *_x0,
291 const Raster *_raster,
bool _SmoothKappaOnly =
true,
292 const void *_kref = 0,
bool _KRefTensFlag =
false)
293 :
GenericSigma (_raster, _x0, 1, (
new double [1]), _tau, _sd,
294 (_SmoothKappaOnly ? 0 : _sd), _kref, _KRefTensFlag)
297 TVSigma (
double _tau,
double _beta,
double _sd,
const RVector *_x0,
299 double _fT,
bool _SmoothKappaOnly =
true,
bool _KRefTensFlag =
false)
300 :
GenericSigma (_raster, _x0, 1, (
new double [1]), _tau, _refimg,
301 _sdr, _sd, (_SmoothKappaOnly ? 0 : _sd), _fT, _KRefTensFlag)
307 const char *GetName()
const
308 {
return "TV_SIGMA"; }
314 inline double func(
const double t,
const int np,
double *p)
const{
315 double betasq = SQR(p[0]);
316 return p[0]*sqrt(SQR(t) + betasq) - betasq ;
319 inline double kfunc(
const double t,
const int np,
double *p)
const{
320 double betasq = SQR(p[0]);
321 return p[0]/sqrt(SQR(t) + betasq) ;
324 inline double d2func(
const double t,
const int np,
double *p)
const{
325 double betasq = SQR(p[0]);
326 double hx =sqrt(SQR(t) + betasq);
328 return p[0]/sqrt(SQR(t) + betasq);
335 TV (
double _tau,
double _beta,
const RVector *_x0,
const Raster *_raster,
336 const void *_kref=0,
bool _KRefTensFlag =
false)
337 :
TVSigma ( _tau, _beta, 0, _x0, _raster,
false, _kref, _KRefTensFlag)
340 TV (
double _tau,
double _beta,
const RVector *_x0,
const Raster *_raster,
341 const RVector &_refimg,
double _sdr,
double _fT,
342 bool _KRefTensFlag =
false)
343 :
TVSigma (_tau, _beta, 0, _x0, _raster, _refimg, _sdr, _fT,
false,
350 const char *GetName()
const
358 const Raster *_raster,
bool _SmoothKappaOnly =
true,
359 const void *_kref=0,
bool _KRefTensFlag =
false)
361 (_SmoothKappaOnly ? 0 : _sd), _kref, _KRefTensFlag)
365 const Raster *_raster,
const RVector &_refimg,
double _sdr,
double _fT,
366 bool _SmoothKappaOnly =
true,
bool _KRefTensFlag =
false)
367 :
GenericSigma (_raster, _x0, 0, (
double*)0, _tau, _refimg,
368 _sdr, _sd, (_SmoothKappaOnly ? 0 : _sd), _fT, _KRefTensFlag)
374 const char *GetName()
const
375 {
return "TK1_SIGMA"; }
378 inline double func(
const double t,
const int np,
double *p)
const{
382 inline double kfunc(
const double t,
const int np,
double *p)
const{
386 inline double d2func(
const double t,
const int np,
double *p)
const{
394 const void *_kref = 0,
bool _KRefTensFlag =
false)
395 :
TK1Sigma ( _tau, 0, _x0, _raster,
false, _kref, _KRefTensFlag)
399 const RVector &_refimg,
double _sdr,
double _fT,
400 bool _KRefTenseFlag =
false)
401 :
TK1Sigma (_tau, 0, _x0, _raster, _refimg, _sdr, _fT,
false,
408 const char *GetName()
const
416 const Raster *_raster,
bool _SmoothKappaOnly =
true,
417 const void *_kref = 0,
bool _KRefTensFlag =
false)
418 :
GenericSigma (_raster, _x0, 1, (
new double [1]), _tau, _sd,
419 (_SmoothKappaOnly ? 0 : _sd), _kref, _KRefTensFlag)
423 const Raster *_raster,
const RVector _refimg,
double _sdr,
double _fT,
424 bool _SmoothKappaOnly =
true,
bool _KRefTensFlag =
false)
425 :
GenericSigma (_raster, _x0, 1, (
new double[1]), _tau, _refimg,
426 _sdr, _sd, (_SmoothKappaOnly ? 0 : _sd), _fT, _KRefTensFlag)
432 const char *GetName()
const
433 {
return "HUBER_SIGMA"; }
439 inline double func(
const double t,
const int np,
double *p)
const{
442 return (at <= eps ? 0.5*SQR(t) : eps*(at - 0.5*eps));
445 inline double kfunc(
const double t,
const int np,
double *p)
const{
448 return (at <= eps ? 1 : eps/at);
451 inline double d2func(
const double t,
const int np,
double *p)
const{
454 return (at <= eps ? 1 : CUBE(eps/at));
461 const void *_kref = 0,
bool _KRefTensFlag =
false)
462 :
HuberSigma (_tau, _eps, 0, _x0, _raster,
false, _kref, _KRefTensFlag)
466 const RVector &_refimg,
double _sdr,
double _fT,
467 bool _KRefTensFlag =
false)
468 :
HuberSigma (_tau, _eps, 0, _x0, _raster, _refimg, _sdr, _fT,
false,
475 const char *GetName()
const
482 const Raster *_raster,
bool _SmoothKappaOnly =
true,
483 const void *_kref = 0,
bool _KRefTensFlag =
false)
484 :
GenericSigma (_raster, _x0, 1, (
new double [1]), _tau, _sd,
485 (_SmoothKappaOnly ? 0 : _sd), _kref, _KRefTensFlag)
489 const Raster *_raster,
const RVector &_refimg,
double _sdr,
double _fT,
490 bool _SmoothKappaOnly =
true,
bool _KRefTensFlag =
false)
491 :
GenericSigma (_raster, _x0, 1, (
new double[1]), _tau, _refimg,
492 _sdr, _sd, (_SmoothKappaOnly ? 0 : _sd), _fT, _KRefTensFlag)
499 inline double func(
const double t,
const int np,
double *p)
const{
501 return 0.5*SQR(T)*(1-exp(-SQR(t/T)));
504 inline double kfunc(
const double t,
const int np,
double *p)
const{
506 return exp(-SQR(t/T));
509 inline double d2func(
const double t,
const int np,
double *p)
const{
512 return exp(-SQR(t/T));
519 const void *_kref = 0,
bool _KRefTensFlag =
false)
520 :
PMSigma (_tau, _T, 0, _x0, _raster,
false, _kref, _KRefTensFlag)
524 const RVector &_refimg,
double _sdr,
double _fT,
525 bool _KRefTensFlag =
false)
526 :
PMSigma (_tau, _T, 0, _x0, _raster, _refimg, _sdr, _fT,
false,
537 const Raster *_raster,
bool _SmoothKappaOnly =
true,
538 const void *_kref = 0,
bool _KRefTensFlag =
false)
539 :
GenericSigma (_raster, _x0, 1, (
new double[1]), _tau, _sd,
540 (_SmoothKappaOnly ? 0 : _sd), _kref, _KRefTensFlag)
544 const Raster *_raster,
const RVector &_refimg,
double _sdr,
double _fT,
545 bool _SmoothKappaOnly =
true,
bool _KRefTensFlag =
false)
546 :
GenericSigma (_raster, _x0, 1, (
new double[1]), _tau, _refimg,
547 _sdr, _sd, (_SmoothKappaOnly ? 0 : _sd), _fT, _KRefTensFlag)
554 inline double func(
const double t,
const int np,
double *p)
const{
556 return 0.5*SQR(T)*log(SQR(t/T) + 1);
559 inline double kfunc(
const double t,
const int np,
double *p)
const{
561 return 1/(SQR(t/T) + 1) ;
564 inline double d2func(
const double t,
const int np,
double *p)
const{
566 double hx = (SQR(t/T) + 1);
575 const void *_kref = 0,
bool _KRefTensFlag =
false)
576 :
QPMSigma (_tau, _T, 0, _x0, _raster,
false, _kref, _KRefTensFlag)
580 const RVector &_refimg,
double _sdr,
double _fT,
581 bool _KRefTensFlag =
false)
582 :
QPMSigma (_tau, _T, 0, _x0, _raster, _refimg, _sdr, _fT,
false,
594 const Raster *_raster,
bool _SmoothKappaOnly =
true,
595 const void *_kref = 0,
bool _KRefTensFlag =
false)
596 :
GenericSigma (_raster, _x0, 1, (
new double[1]), _tau, _sd,
597 (_SmoothKappaOnly ? 0 : _sd), _kref, _KRefTensFlag)
601 const Raster *_raster,
const RVector &_refimg,
double _sdr,
double _fT,
602 bool _SmoothKappaOnly =
true,
bool _KRefTensFlag =
false)
603 :
GenericSigma (_raster, _x0, 1, (
new double[1]), _tau, _refimg,
604 _sdr, _sd, (_SmoothKappaOnly ? 0 : _sd), _fT, _KRefTensFlag)
611 inline double func(
const double t,
const int np,
double *p)
const{
613 return 0.5*SQR(t)*(1 - SQR(t/T) + SQR(SQR(t/T))/3.0 );
616 inline double kfunc(
const double t,
const int np,
double *p)
const{
619 return (at <= T ? SQR(1 - (SQR(t/T))) : 0);
622 inline double d2func(
const double t,
const int np,
double *p)
const{
625 return (at <= T ? SQR(1 - (SQR(t/T))) : 0);
632 const void *_kref = 0,
bool _KRefTensFlag =
false)
633 :
TukeySigma (_tau, _T, 0, _x0, _raster,
false, _kref, _KRefTensFlag)
637 const RVector &_refimg,
double _sdr,
double _fT,
638 bool _KRefTensFlag =
false)
639 :
TukeySigma (_tau, _T, 0, _x0, _raster, _refimg, _sdr, _fT,
false,
651 GenericScaleSpace (
const Raster *_raster,
const RVector *_x0, PSIREG _func, PSIREG _kfunc, PSIREG _k1func,
const int _npreg,
double * _preg,
double _tau,
double _sdx = 0,
double _sdf = 0,
const RDenseMatrix *_kreftens=0);
655 PRIOR Type()
const {
return PRIOR_GENERICSCALESPACE; }
661 double GetValue (
const RVector &x)
const;
669 return GetHess1f (x, x - *x0);
677 return GetHess1f_KappaSet(f);
679 return GetHess1f_KappaNotSet(x,f);
685 int GetHessianRow (
const RVector &x,
int i, idxtype *colidx,
double *val)
const;
693 const double sdx, sdf ;
694 const PSIREG func, kfunc, k1func;
706 Generic (
const Raster *_raster,
const RVector *_x0,
const int _npreg,
double * _preg,
double _tau,
const RVector *_kap=0) :
GenericSigma (_raster, _x0, _npreg, _preg, _tau, 0, 0,_kap) {};
716 PRIOR Type()
const {
return PRIOR_NONE; }
717 const char *GetName()
const {
return "NONE"; }
718 double GetValue (
const RVector &x)
const;
725 int GetHessianRow (
const RVector &x,
int i, idxtype *colidx,
double *val)
742 PRIOR Type()
const {
return PRIOR_DIAG; }
744 const char *GetName()
const {
return "TK0"; }
745 double GetValue (
const RVector &x)
const;
751 int GetHessianRow (
const RVector &x,
int i, idxtype *colidx,
double *val)
754 void SetTau (
double _tau);
755 void SetTau (
const RVector &_tau);
770 char *kaprefimg_name;
779 PRIOR Type()
const {
return PRIOR_LAPLACIAN; }
780 const char *GetName()
const {
return "Tikhonov1"; }
781 double GetValue (
const RVector &x)
const;
791 int GetHessianRow (
const RVector &x,
int i, idxtype *colidx,
double *val)
802 void CreateHessian (
const Raster *raster,
const RVector &kappa,
814 TVSigmaOLD (
double _tau,
double _beta,
double _sd,
const RVector *_x0,
const Raster *_raster,
bool _SmoothKappaOnly =
true,
const RVector *_kap=0);
817 PRIOR Type()
const {
return PRIOR_TVSIGMA; }
818 double GetValue (
const RVector &x)
const;
828 void OLDSetHessian (
const RVector &x)
const;
829 int GetHessianRow (
const RVector &x,
int i, idxtype *colidx,
double *val)
839 double tau, beta, betasq, sd;
840 bool SmoothKappaOnly ;
851 TVOLD (
double _tau,
double _beta,
const RVector *_x0,
const Raster *_raster,
const RVector *_kap=0):
TVSigmaOLD(_tau,_beta,0,_x0, _raster,
false, _kap) {};
852 PRIOR Type()
const {
return PRIOR_TV; }
862 PRIOR Type()
const {
return PRIOR_MRF; }
863 const char *GetName()
const {
return "MRF"; }
865 void SetKaprefImg (
const RVector *kap = 0);
867 double GetValue (
const RVector &x)
const;
877 int GetHessianRow (
const RVector &x,
int i, idxtype *colidx,
double *val)
885 #endif // !OLD_REGUL2
886 #endif // !__ST_REGUL_H
Templated vector class.
Definition: vector.h:39
Base class for mapping between mesh and an independent basis representation.
Definition: raster.h:20
Dense matrix class.
Definition: crmatrix.h:38