|
|
|
@ -83,63 +83,63 @@ template <typename T> struct pixelInfo: public pixelInfo_<T> |
|
|
|
|
|
|
|
|
|
class DistAbs |
|
|
|
|
{ |
|
|
|
|
template <typename T, typename IT> struct calcDist_ |
|
|
|
|
template <typename T> struct calcDist_ |
|
|
|
|
{ |
|
|
|
|
static inline IT f(const T a, const T b) |
|
|
|
|
static inline int f(const T a, const T b) |
|
|
|
|
{ |
|
|
|
|
return std::abs((IT)(a-b)); |
|
|
|
|
return std::abs((int)(a-b)); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
template <typename ET, typename IT> struct calcDist_<Vec<ET, 2>, IT> |
|
|
|
|
template <typename ET> struct calcDist_<Vec<ET, 2> > |
|
|
|
|
{ |
|
|
|
|
static inline IT f(const Vec<ET, 2> a, const Vec<ET, 2> b) |
|
|
|
|
static inline int f(const Vec<ET, 2> a, const Vec<ET, 2> b) |
|
|
|
|
{ |
|
|
|
|
return std::abs((IT)(a[0]-b[0])) + std::abs((IT)(a[1]-b[1])); |
|
|
|
|
return std::abs((int)(a[0]-b[0])) + std::abs((int)(a[1]-b[1])); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
template <typename ET, typename IT> struct calcDist_<Vec<ET, 3>, IT> |
|
|
|
|
template <typename ET> struct calcDist_<Vec<ET, 3> > |
|
|
|
|
{ |
|
|
|
|
static inline IT f(const Vec<ET, 3> a, const Vec<ET, 3> b) |
|
|
|
|
static inline int f(const Vec<ET, 3> a, const Vec<ET, 3> b) |
|
|
|
|
{ |
|
|
|
|
return |
|
|
|
|
std::abs((IT)(a[0]-b[0])) + |
|
|
|
|
std::abs((IT)(a[1]-b[1])) + |
|
|
|
|
std::abs((IT)(a[2]-b[2])); |
|
|
|
|
std::abs((int)(a[0]-b[0])) + |
|
|
|
|
std::abs((int)(a[1]-b[1])) + |
|
|
|
|
std::abs((int)(a[2]-b[2])); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
template <typename ET, typename IT> struct calcDist_<Vec<ET, 4>, IT> |
|
|
|
|
template <typename ET> struct calcDist_<Vec<ET, 4> > |
|
|
|
|
{ |
|
|
|
|
static inline IT f(const Vec<ET, 4> a, const Vec<ET, 4> b) |
|
|
|
|
static inline int f(const Vec<ET, 4> a, const Vec<ET, 4> b) |
|
|
|
|
{ |
|
|
|
|
return |
|
|
|
|
std::abs((IT)(a[0]-b[0])) + |
|
|
|
|
std::abs((IT)(a[1]-b[1])) + |
|
|
|
|
std::abs((IT)(a[2]-b[2])) + |
|
|
|
|
std::abs((IT)(a[3]-b[3])); |
|
|
|
|
std::abs((int)(a[0]-b[0])) + |
|
|
|
|
std::abs((int)(a[1]-b[1])) + |
|
|
|
|
std::abs((int)(a[2]-b[2])) + |
|
|
|
|
std::abs((int)(a[3]-b[3])); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
template <typename T, typename IT> static inline IT calcDist(const T a, const T b) |
|
|
|
|
template <typename T> static inline int calcDist(const T a, const T b) |
|
|
|
|
{ |
|
|
|
|
return calcDist_<T, IT>::f(a, b); |
|
|
|
|
return calcDist_<T>::f(a, b); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T, typename IT> |
|
|
|
|
static inline IT calcDist(const Mat& m, int i1, int j1, int i2, int j2) |
|
|
|
|
template <typename T> |
|
|
|
|
static inline int calcDist(const Mat& m, int i1, int j1, int i2, int j2) |
|
|
|
|
{ |
|
|
|
|
const T a = m.at<T>(i1, j1); |
|
|
|
|
const T b = m.at<T>(i2, j2); |
|
|
|
|
return calcDist<T, IT>(a,b); |
|
|
|
|
return calcDist<T>(a,b); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T, typename IT> |
|
|
|
|
static inline IT calcUpDownDist(T a_up, T a_down, T b_up, T b_down) |
|
|
|
|
template <typename T> |
|
|
|
|
static inline int calcUpDownDist(T a_up, T a_down, T b_up, T b_down) |
|
|
|
|
{ |
|
|
|
|
return calcDist<T, IT>(a_down, b_down) - calcDist<T, IT>(a_up, b_up); |
|
|
|
|
return calcDist<T>(a_down, b_down) - calcDist<T>(a_up, b_up); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
@ -148,93 +148,93 @@ public: |
|
|
|
|
return std::exp(-dist*dist / (h * h * pixelInfo<T>::channels)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T, typename IT> |
|
|
|
|
template <typename T> |
|
|
|
|
static double maxDist() |
|
|
|
|
{ |
|
|
|
|
return (IT)pixelInfo<T>::sampleMax() * (IT)pixelInfo<T>::channels; |
|
|
|
|
return (int)pixelInfo<T>::sampleMax() * pixelInfo<T>::channels; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
class DistSquared |
|
|
|
|
{ |
|
|
|
|
template <typename T, typename IT> struct calcDist_ |
|
|
|
|
template <typename T> struct calcDist_ |
|
|
|
|
{ |
|
|
|
|
static inline IT f(const T a, const T b) |
|
|
|
|
static inline int f(const T a, const T b) |
|
|
|
|
{ |
|
|
|
|
return (IT)(a-b) * (IT)(a-b); |
|
|
|
|
return (int)(a-b) * (int)(a-b); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
template <typename ET, typename IT> struct calcDist_<Vec<ET, 2>, IT> |
|
|
|
|
template <typename ET> struct calcDist_<Vec<ET, 2> > |
|
|
|
|
{ |
|
|
|
|
static inline IT f(const Vec<ET, 2> a, const Vec<ET, 2> b) |
|
|
|
|
static inline int f(const Vec<ET, 2> a, const Vec<ET, 2> b) |
|
|
|
|
{ |
|
|
|
|
return (IT)(a[0]-b[0])*(IT)(a[0]-b[0]) + (IT)(a[1]-b[1])*(IT)(a[1]-b[1]); |
|
|
|
|
return (int)(a[0]-b[0])*(int)(a[0]-b[0]) + (int)(a[1]-b[1])*(int)(a[1]-b[1]); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
template <typename ET, typename IT> struct calcDist_<Vec<ET, 3>, IT> |
|
|
|
|
template <typename ET> struct calcDist_<Vec<ET, 3> > |
|
|
|
|
{ |
|
|
|
|
static inline IT f(const Vec<ET, 3> a, const Vec<ET, 3> b) |
|
|
|
|
static inline int f(const Vec<ET, 3> a, const Vec<ET, 3> b) |
|
|
|
|
{ |
|
|
|
|
return |
|
|
|
|
(IT)(a[0]-b[0])*(IT)(a[0]-b[0]) + |
|
|
|
|
(IT)(a[1]-b[1])*(IT)(a[1]-b[1]) + |
|
|
|
|
(IT)(a[2]-b[2])*(IT)(a[2]-b[2]); |
|
|
|
|
(int)(a[0]-b[0])*(int)(a[0]-b[0]) + |
|
|
|
|
(int)(a[1]-b[1])*(int)(a[1]-b[1]) + |
|
|
|
|
(int)(a[2]-b[2])*(int)(a[2]-b[2]); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
template <typename ET, typename IT> struct calcDist_<Vec<ET, 4>, IT> |
|
|
|
|
template <typename ET> struct calcDist_<Vec<ET, 4> > |
|
|
|
|
{ |
|
|
|
|
static inline IT f(const Vec<ET, 4> a, const Vec<ET, 4> b) |
|
|
|
|
static inline int f(const Vec<ET, 4> a, const Vec<ET, 4> b) |
|
|
|
|
{ |
|
|
|
|
return |
|
|
|
|
(IT)(a[0]-b[0])*(IT)(a[0]-b[0]) + |
|
|
|
|
(IT)(a[1]-b[1])*(IT)(a[1]-b[1]) + |
|
|
|
|
(IT)(a[2]-b[2])*(IT)(a[2]-b[2]) + |
|
|
|
|
(IT)(a[3]-b[3])*(IT)(a[3]-b[3]); |
|
|
|
|
(int)(a[0]-b[0])*(int)(a[0]-b[0]) + |
|
|
|
|
(int)(a[1]-b[1])*(int)(a[1]-b[1]) + |
|
|
|
|
(int)(a[2]-b[2])*(int)(a[2]-b[2]) + |
|
|
|
|
(int)(a[3]-b[3])*(int)(a[3]-b[3]); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
template <typename T, typename IT> struct calcUpDownDist_ |
|
|
|
|
template <typename T> struct calcUpDownDist_ |
|
|
|
|
{ |
|
|
|
|
static inline IT f(T a_up, T a_down, T b_up, T b_down) |
|
|
|
|
static inline int f(T a_up, T a_down, T b_up, T b_down) |
|
|
|
|
{ |
|
|
|
|
IT A = a_down - b_down; |
|
|
|
|
IT B = a_up - b_up; |
|
|
|
|
int A = a_down - b_down; |
|
|
|
|
int B = a_up - b_up; |
|
|
|
|
return (A-B)*(A+B); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
template <typename ET, int n, typename IT> struct calcUpDownDist_<Vec<ET, n>, IT> |
|
|
|
|
template <typename ET, int n> struct calcUpDownDist_<Vec<ET, n> > |
|
|
|
|
{ |
|
|
|
|
private: |
|
|
|
|
typedef Vec<ET, n> T; |
|
|
|
|
public: |
|
|
|
|
static inline IT f(T a_up, T a_down, T b_up, T b_down) |
|
|
|
|
static inline int f(T a_up, T a_down, T b_up, T b_down) |
|
|
|
|
{ |
|
|
|
|
return calcDist<T, IT>(a_down, b_down) - calcDist<T, IT>(a_up, b_up); |
|
|
|
|
return calcDist<T>(a_down, b_down) - calcDist<T>(a_up, b_up); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
template <typename T, typename IT> static inline IT calcDist(const T a, const T b) |
|
|
|
|
template <typename T> static inline int calcDist(const T a, const T b) |
|
|
|
|
{ |
|
|
|
|
return calcDist_<T, IT>::f(a, b); |
|
|
|
|
return calcDist_<T>::f(a, b); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T, typename IT> |
|
|
|
|
static inline IT calcDist(const Mat& m, int i1, int j1, int i2, int j2) |
|
|
|
|
template <typename T> |
|
|
|
|
static inline int calcDist(const Mat& m, int i1, int j1, int i2, int j2) |
|
|
|
|
{ |
|
|
|
|
const T a = m.at<T>(i1, j1); |
|
|
|
|
const T b = m.at<T>(i2, j2); |
|
|
|
|
return calcDist<T, IT>(a,b); |
|
|
|
|
return calcDist<T>(a,b); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T, typename IT> |
|
|
|
|
static inline IT calcUpDownDist(T a_up, T a_down, T b_up, T b_down) |
|
|
|
|
template <typename T> |
|
|
|
|
static inline int calcUpDownDist(T a_up, T a_down, T b_up, T b_down) |
|
|
|
|
{ |
|
|
|
|
return calcUpDownDist_<T, IT>::f(a_up, a_down, b_up, b_down); |
|
|
|
|
return calcUpDownDist_<T>::f(a_up, a_down, b_up, b_down); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
@ -243,11 +243,11 @@ public: |
|
|
|
|
return std::exp(-dist / (h * h * pixelInfo<T>::channels)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T, typename IT> |
|
|
|
|
template <typename T> |
|
|
|
|
static double maxDist() |
|
|
|
|
{ |
|
|
|
|
return (IT)pixelInfo<T>::sampleMax() * (IT)pixelInfo<T>::sampleMax() * |
|
|
|
|
(IT)pixelInfo<T>::channels; |
|
|
|
|
return (int)pixelInfo<T>::sampleMax() * (int)pixelInfo<T>::sampleMax() * |
|
|
|
|
pixelInfo<T>::channels; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|