18 #ifndef __otbMeanShiftKernels_h
19 #define __otbMeanShiftKernels_h
25 #include "itkNumericTraits.h"
67 return new Self(*
this);
72 return (
dot(x, x) - 2.0 *
dot(x, y) +
dot(y, y));
100 this->
SetName(
"invMultiQuadric");
101 this->SetValue<double>(
"const_coef", 1);
108 return new Self(*
this);
113 double mq = this->GetValue<double>(
"const_coef") +
m_Custom(x, y, param);
116 return itk::NumericTraits<double>::max();
118 return 1.0 / sqrt(mq);
150 this->SetValue<double>(
"const_coef", 1);
156 double mq = this->GetValue<double>(
"const_coef") +
m_Custom(x, y, param);
160 return itk::NumericTraits<double>::max();
162 return exp(param.
gamma / mq) - 1.0;
168 return new Self(*
this);
205 double den =
dot(x, x) *
dot(y, y);
210 double ss =
dot(x, y);
211 return vcl_acos(ss / vcl_sqrt(den));
217 return new Self(*
this);
251 return vcl_exp(-param.
gamma *
m_Sam(x, y, param));
257 return new Self(*
this);
288 this->
SetName(
"InverseCosSAM");
294 return 1.0 - vcl_cos(
m_Sam(x, y, param));
300 return new Self(*
this);
331 this->
SetName(
"invMultiQuadraticSAM");
332 this->SetValue<double>(
"const_coef", 1);
339 return new Self(*
this);
344 double mq = this->GetValue<double>(
"const_coef") +
m_Sam(x, y, param);
348 return itk::NumericTraits<double>::max();
350 return 1. / sqrt(mq);
382 this->SetValue<double>(
"const_coef", 1);
389 return new Self(*
this);
394 double mq = this->GetValue<double>(
"const_coef") +
m_Sam(x, y, param);
398 return itk::NumericTraits<double>::max();
400 return vcl_exp(param.
gamma / mq) - 1.0;
432 this->SetValue<double>(
"gamma_coef", 0.5);
439 return new Self(*
this);
444 double res = this->GetValue<double>(
"gamma_coef") *
m_Custom(x, y, param);
445 return vcl_exp(-res);
454 double constValue)
const
456 double gamma = this->GetValue<double>(
"gamma_coef");
457 double kernelValue = 0.;
466 while (xtemp->
index != -1 && ytemp->
index != -1 && stop ==
false)
496 kernelValue = constValue;
509 return (-2 * gamma * (yval - xval) * kernelValue);
514 this->
derivative(x, y, param, degree - 2, index, isAtEnd, constValue) +
515 (yval - xval) *
derivative(x, y, param, degree - 1, index, isAtEnd, constValue)));
550 this->SetValue<double>(
"lin_coef", 1.);
557 return new Self(*
this);
562 return (this->GetValue<double>(
"lin_coef") * vcl_exp(-param.
gamma *
m_Custom(x, y, param))
563 + (1.0 - this->GetValue<double>(
"lin_coef")) *
m_RadialSam(x, y, param));
596 this->SetValue<double>(
"const_coef", 1);
597 this->SetValue<double>(
"lin_coef", 1);
604 return new Self(*
this);
609 return this->GetValue<double>(
"const_lin") * vcl_pow(
dot(x, y) + this->GetValue<double>(
"const_coef"), param.
degree)
610 + (1.0 - this->GetValue<double>(
"const_coef"))
649 return new Self(*
this);
707 return new Self(*
this);
718 return (vcl_exp(value));
756 return new Self(*
this);
761 const char * parameters = param.
custom;
762 const char * twoPoints =
":";
763 const char * position = strpbrk (parameters, twoPoints);
764 int twoPointsPosition = 0;
767 int numberOfGroups = atoi(parameters);
769 twoPointsPosition = position - parameters;
771 parameters = parameters + twoPointsPosition + 1;
774 std::vector<int> begin;
775 begin.resize(numberOfGroups);
776 std::vector<int> end;
777 end.resize(numberOfGroups);
779 for (i = 0; i < numberOfGroups; ++i)
781 begin[i] = atoi(parameters);
782 position = strpbrk (parameters, twoPoints);
783 twoPointsPosition = position - parameters;
784 parameters = parameters + twoPointsPosition + 1;
786 end[i] = atoi(parameters);
787 parameters = parameters + twoPointsPosition + 1;
796 while (xBuff->
index != 1)
802 while (yBuff->
index != 1)
817 for (j = 0; j < numberOfGroups; ++j)
823 while (xTemp->
index != 1 && yTemp->
index != 1)
827 if ((xTemp->
index < begin[j]) || (xTemp->
index > end[j]))
829 xGroup[index].
value = 0;
830 yGroup[index].
value = 0;
851 else if ((sizeX > 0) && (sizeY == 0))
856 for (j = 0; j < numberOfGroups; ++j)
861 while (xTemp->
index != -1)
866 if ((xTemp->
index < begin[j]) || (xTemp->
index > end[j]))
868 xGroup[index].
value = 0;
869 yGroup[index].
value = 0;
874 yGroup[index].
value = 0;
891 total =
static_cast<double>(numberOfGroups) *
m_CustomLinear(x, y, param);
894 if (xTemp !=
NULL)
delete xTemp;
895 if (yTemp !=
NULL)
delete yTemp;
928 this->
SetName(
"groupingAdaptive");
929 this->SetValue<double>(
"lin_coef", 1.);
930 this->SetValue<double>(
"const_coef", 1.);
937 return new Self(*
this);
942 const char * parameters = param.
custom;
943 const char * twoPoints =
":";
944 const char * position = strpbrk (parameters, twoPoints);
945 int twoPointsPosition = 0;
948 int numberOfGroups = atoi(parameters);
950 twoPointsPosition = position - parameters;
952 parameters = parameters + twoPointsPosition + 1;
956 std::vector<int> begin;
957 begin.resize(numberOfGroups);
958 std::vector<int> end;
959 end.resize(numberOfGroups);
961 for (i = 0; i < numberOfGroups; ++i)
963 begin[i] = atoi(parameters);
964 position = strpbrk (parameters, twoPoints);
965 twoPointsPosition = position - parameters;
966 parameters = parameters + twoPointsPosition + 1;
968 end[i] = atoi(parameters);
969 parameters = parameters + twoPointsPosition + 1;
978 while (xBuff->
index != 1)
984 while (yBuff->
index != 1)
1000 for (j = 0; j < numberOfGroups; ++j)
1006 while (xTemp->
index != 1 && yTemp->
index != 1)
1010 if ((xTemp->
index < begin[j]) || (xTemp->
index > end[j]))
1012 xGroup[index].
value = 0;
1013 yGroup[index].
value = 0;
1026 value = vcl_pow(this->GetValue<double>(
"lin_coef") *
dot(xGroup, yGroup) + this->GetValue<double>(
1027 "const_coef"), static_cast<double>(param.
degree));
1035 else if ((sizeX > 0) && (sizeY == 0))
1040 for (j = 0; j < numberOfGroups; ++j)
1045 while (xTemp->
index != 1)
1050 if ((xTemp->
index < begin[j]) || (xTemp->
index > end[j]))
1052 xGroup[index].
value = 0;
1053 yGroup[index].
value = 0;
1058 yGroup[index].
value = 0;
1065 value = vcl_pow(this->GetValue<double>(
"lin_coef") *
dot(xGroup, yGroup) + this->GetValue<double>(
1066 "const_coef"), static_cast<double>(param.
degree));
1077 total =
static_cast<double>(numberOfGroups) * custom(x, y, param);