Main MRPT website
>
C++ reference
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
mrpt
vision
robust_kernels.h
Go to the documentation of this file.
1
/* +---------------------------------------------------------------------------+
2
| The Mobile Robot Programming Toolkit (MRPT) C++ library |
3
| |
4
| http://www.mrpt.org/ |
5
| |
6
| Copyright (C) 2005-2012 University of Malaga |
7
| |
8
| This software was written by the Machine Perception and Intelligent |
9
| Robotics Lab, University of Malaga (Spain). |
10
| Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11
| |
12
| This file is part of the MRPT project. |
13
| |
14
| MRPT is free software: you can redistribute it and/or modify |
15
| it under the terms of the GNU General Public License as published by |
16
| the Free Software Foundation, either version 3 of the License, or |
17
| (at your option) any later version. |
18
| |
19
| MRPT is distributed in the hope that it will be useful, |
20
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
21
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22
| GNU General Public License for more details. |
23
| |
24
| You should have received a copy of the GNU General Public License |
25
| along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26
| |
27
+---------------------------------------------------------------------------+ */
28
29
#ifndef mrpt_vision_robust_kernels_H
30
#define mrpt_vision_robust_kernels_H
31
32
#include <
mrpt/utils/CImage.h
>
33
#include <
mrpt/utils/CLoadableOptions.h
>
34
#include <
mrpt/utils/TMatchingPair.h
>
35
36
#include <
mrpt/vision/link_pragmas.h
>
37
38
namespace
mrpt
39
{
40
namespace
vision
41
{
42
/** \addtogroup mrpt_vision_grp
43
* @{ */
44
45
/** The different types of kernels for usage within a robustified least-squares estimator.
46
* \sa Use these types as arguments of the template RobustKernel<>
47
*/
48
enum
TRobustKernelType
49
{
50
rkLeastSquares
= 0,
//!< No robust kernel, use standard least squares: rho(r)= 1/2 * r^2
51
rkPseudoHuber
//!< Pseudo-huber robust kernel
52
};
53
54
// Generic declaration.
55
template
<
int
TRobustKernelType,
typename
T=
double
>
struct
RobustKernel
;
56
57
/** No robust kernel, use standard least squares: rho(r)= 1/2 * r^2
58
* \note the "static_cast<>" in the declaration is to avoid a bug in MSVC 2008
59
*/
60
template
<
typename
T>
61
struct
RobustKernel
< static_cast<int>(
rkLeastSquares
), T >
62
{
63
/** Evaluates the kernel function at error norm = "delta" and returns
64
* robustified squared error and, optionally, the 1st derivative of sqrt(2*rho(r)) at this point.
65
*/
66
inline
T eval(
67
const
T delta,
68
T * out_1st_deriv=NULL)
69
{
70
if
(out_1st_deriv) *out_1st_deriv = 1;
71
//if (out_2nd_deriv) *out_2nd_deriv = 0;
72
// cost: 0.5* |delta|^2
73
return
delta*delta;
// return: 2*cost
74
}
75
};
76
77
/** Pseudo-huber robust kernel: rho(r) = b^2 * (-1+sqrt(1+(r\b)^2))
78
* \note the "static_cast<>" in the declaration is to avoid a bug in MSVC 2008
79
*/
80
template
<
typename
T>
81
struct
RobustKernel
< static_cast<int>(
rkPseudoHuber
), T >
82
{
83
T
b_sq
;
//!< The kernel parameter "b" squared (b^2).
84
85
/** Evaluates the kernel function at error norm = "delta" and returns
86
* robustified squared error and, optionally, the 1st derivative of sqrt(2*rho(r)) at this point.
87
*/
88
inline
T eval(
89
const
T delta,
90
T * out_1st_deriv=NULL)
91
{
92
const
double
r = delta*delta/b_sq;
93
const
double
n = std::sqrt(1+r);
94
const
double
cost = b_sq*(n-1);
95
if
(out_1st_deriv) *out_1st_deriv = ( 1.414213562373095 * delta)/(2* n * std::sqrt(b_sq*(n-1)) );
96
//if (out_2nd_deriv) *out_2nd_deriv = ((-3*1.414213562373095*n)*delta*delta + 2*1.414213562373095*b_sq*pow(1+r,1.5) - 2*1.414213562373095*b_sq)/(4*pow(1+r,1.5)*pow(b_sq*n - b_sq,1.5));
97
return
2*cost;
// return: 2*cost
98
}
99
};
100
101
102
103
104
/** @} */
// end of grouping
105
}
106
}
107
108
#endif
Page generated by
Doxygen 1.8.3
for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013