Changed from sum of squared differences to sum of abs differences
This commit is contained in:
parent
c339720af9
commit
baf266c29e
@ -130,13 +130,12 @@ FastNlMeansDenoisingInvoker<T, IT, UIT>::FastNlMeansDenoisingInvoker(
|
||||
|
||||
const double WEIGHT_THRESHOLD = 0.001;
|
||||
const size_t ALLOC_CHUNK = 65536;
|
||||
IT max_dist =
|
||||
(IT)pixelInfo<T>::sampleMax() * (IT)pixelInfo<T>::sampleMax() * (IT)pixelInfo<T>::channels;
|
||||
IT max_dist = (IT)pixelInfo<T>::sampleMax() * (IT)pixelInfo<T>::channels;
|
||||
size_t almost_max_dist = 0;
|
||||
while (true)
|
||||
{
|
||||
double dist = almost_max_dist * almost_dist2actual_dist_multiplier;
|
||||
IT weight = (IT)round(fixed_point_mult_ * std::exp(-dist / (h * h * pixelInfo<T>::channels)));
|
||||
IT weight = (IT)round(fixed_point_mult_ * std::exp(-dist*dist / (h * h * pixelInfo<T>::channels)));
|
||||
if (weight < WEIGHT_THRESHOLD * fixed_point_mult_ || dist > max_dist) break;
|
||||
|
||||
if (almost_max_dist >= almost_dist2weight_.size())
|
||||
|
@ -85,7 +85,7 @@ template <typename T, typename IT> struct calcDist_
|
||||
{
|
||||
static inline IT f(const T a, const T b)
|
||||
{
|
||||
return (IT)(a-b) * (IT)(a-b);
|
||||
return std::abs((IT)(a-b));
|
||||
}
|
||||
};
|
||||
|
||||
@ -93,7 +93,7 @@ template <typename ET, typename IT> struct calcDist_<Vec<ET, 2>, IT>
|
||||
{
|
||||
static inline IT 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 std::abs((IT)(a[0]-b[0])) + std::abs((IT)(a[1]-b[1]));
|
||||
}
|
||||
};
|
||||
|
||||
@ -101,10 +101,7 @@ template <typename ET, typename IT> struct calcDist_<Vec<ET, 3>, IT>
|
||||
{
|
||||
static inline IT 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]);
|
||||
return std::abs((IT)(a[0]-b[0])) + std::abs((IT)(a[1]-b[1])) + std::abs((IT)(a[2]-b[2]));
|
||||
}
|
||||
};
|
||||
|
||||
@ -121,31 +118,10 @@ static inline IT calcDist(const Mat& m, int i1, int j1, int i2, int j2)
|
||||
return calcDist<T, IT>(a,b);
|
||||
}
|
||||
|
||||
template <typename T, typename IT> struct calcUpDownDist_
|
||||
{
|
||||
static inline IT 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;
|
||||
return (A-B)*(A+B);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ET, int n, typename IT> struct calcUpDownDist_<Vec<ET, n>, IT>
|
||||
{
|
||||
private:
|
||||
typedef Vec<ET, n> T;
|
||||
public:
|
||||
static inline IT 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);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename IT>
|
||||
static inline IT 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 calcDist<T, IT>(a_down, b_down) - calcDist<T, IT>(a_up, b_up);
|
||||
};
|
||||
|
||||
template <typename T, typename IT> struct incWithWeight_
|
||||
|
@ -141,13 +141,12 @@ FastNlMeansMultiDenoisingInvoker<T, IT, UIT>::FastNlMeansMultiDenoisingInvoker(
|
||||
|
||||
const double WEIGHT_THRESHOLD = 0.001;
|
||||
const size_t ALLOC_CHUNK = 65536;
|
||||
IT max_dist =
|
||||
(IT)pixelInfo<T>::sampleMax() * (IT)pixelInfo<T>::sampleMax() * (IT)pixelInfo<T>::channels;
|
||||
IT max_dist = (IT)pixelInfo<T>::sampleMax() * (IT)pixelInfo<T>::channels;
|
||||
size_t almost_max_dist = 0;
|
||||
while (true)
|
||||
{
|
||||
double dist = almost_max_dist * almost_dist2actual_dist_multiplier;
|
||||
IT weight = (IT)round(fixed_point_mult_ * std::exp(-dist / (h * h * pixelInfo<T>::channels)));
|
||||
IT weight = (IT)round(fixed_point_mult_ * std::exp(-dist*dist / (h * h * pixelInfo<T>::channels)));
|
||||
if (weight < WEIGHT_THRESHOLD * fixed_point_mult_ || dist > max_dist) break;
|
||||
|
||||
if (almost_max_dist >= almost_dist2weight.size())
|
||||
|
Loading…
x
Reference in New Issue
Block a user