Commit 305cff36 authored by Erik Karlsson's avatar Erik Karlsson

Changed from IT to int for distance calculation

parent 69eae13f
...@@ -80,15 +80,15 @@ private: ...@@ -80,15 +80,15 @@ private:
std::vector<IT> almost_dist2weight_; std::vector<IT> almost_dist2weight_;
void calcDistSumsForFirstElementInRow( void calcDistSumsForFirstElementInRow(
int i, Array2d<IT>& dist_sums, int i, Array2d<int>& dist_sums,
Array3d<IT>& col_dist_sums, Array3d<int>& col_dist_sums,
Array3d<IT>& up_col_dist_sums) const; Array3d<int>& up_col_dist_sums) const;
void calcDistSumsForElementInFirstRow( void calcDistSumsForElementInFirstRow(
int i, int j, int first_col_num, int i, int j, int first_col_num,
Array2d<IT>& dist_sums, Array2d<int>& dist_sums,
Array3d<IT>& col_dist_sums, Array3d<int>& col_dist_sums,
Array3d<IT>& up_col_dist_sums) const; Array3d<int>& up_col_dist_sums) const;
}; };
inline int getNearestPowerOf2(int value) inline int getNearestPowerOf2(int value)
...@@ -128,8 +128,8 @@ FastNlMeansDenoisingInvoker<T, IT, UIT, D>::FastNlMeansDenoisingInvoker( ...@@ -128,8 +128,8 @@ FastNlMeansDenoisingInvoker<T, IT, UIT, D>::FastNlMeansDenoisingInvoker(
almost_template_window_size_sq_bin_shift_ = getNearestPowerOf2(template_window_size_sq); almost_template_window_size_sq_bin_shift_ = getNearestPowerOf2(template_window_size_sq);
double almost_dist2actual_dist_multiplier = ((double)(1 << almost_template_window_size_sq_bin_shift_)) / template_window_size_sq; double almost_dist2actual_dist_multiplier = ((double)(1 << almost_template_window_size_sq_bin_shift_)) / template_window_size_sq;
IT max_dist = D::template maxDist<T, IT>(); int max_dist = D::template maxDist<T>();
size_t almost_max_dist = (size_t)(max_dist / almost_dist2actual_dist_multiplier + 1); int almost_max_dist = (int)(max_dist / almost_dist2actual_dist_multiplier + 1);
almost_dist2weight_.resize(almost_max_dist); almost_dist2weight_.resize(almost_max_dist);
const double WEIGHT_THRESHOLD = 0.001; const double WEIGHT_THRESHOLD = 0.001;
...@@ -156,14 +156,14 @@ void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& range) ...@@ -156,14 +156,14 @@ void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& range)
int row_to = range.end - 1; int row_to = range.end - 1;
// sums of cols anf rows for current pixel p // sums of cols anf rows for current pixel p
Array2d<IT> dist_sums(search_window_size_, search_window_size_); Array2d<int> dist_sums(search_window_size_, search_window_size_);
// for lazy calc optimization (sum of cols for current pixel) // for lazy calc optimization (sum of cols for current pixel)
Array3d<IT> col_dist_sums(template_window_size_, search_window_size_, search_window_size_); Array3d<int> col_dist_sums(template_window_size_, search_window_size_, search_window_size_);
int first_col_num = -1; int first_col_num = -1;
// last elements of column sum (for each element in row) // last elements of column sum (for each element in row)
Array3d<IT> up_col_dist_sums(src_.cols, search_window_size_, search_window_size_); Array3d<int> up_col_dist_sums(src_.cols, search_window_size_, search_window_size_);
for (int i = row_from; i <= row_to; i++) for (int i = row_from; i <= row_to; i++)
{ {
...@@ -202,9 +202,9 @@ void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& range) ...@@ -202,9 +202,9 @@ void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& range)
for (int y = 0; y < search_window_size; y++) for (int y = 0; y < search_window_size; y++)
{ {
IT * dist_sums_row = dist_sums.row_ptr(y); int * dist_sums_row = dist_sums.row_ptr(y);
IT * col_dist_sums_row = col_dist_sums.row_ptr(first_col_num, y); int * col_dist_sums_row = col_dist_sums.row_ptr(first_col_num, y);
IT * up_col_dist_sums_row = up_col_dist_sums.row_ptr(j, y); int * up_col_dist_sums_row = up_col_dist_sums.row_ptr(j, y);
const T * b_up_ptr = extended_src_.ptr<T>(start_by - template_window_half_size_ - 1 + y); const T * b_up_ptr = extended_src_.ptr<T>(start_by - template_window_half_size_ - 1 + y);
const T * b_down_ptr = extended_src_.ptr<T>(start_by + template_window_half_size_ + y); const T * b_down_ptr = extended_src_.ptr<T>(start_by + template_window_half_size_ + y);
...@@ -215,7 +215,7 @@ void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& range) ...@@ -215,7 +215,7 @@ void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& range)
dist_sums_row[x] -= col_dist_sums_row[x]; dist_sums_row[x] -= col_dist_sums_row[x];
int bx = start_bx + x; int bx = start_bx + x;
col_dist_sums_row[x] = up_col_dist_sums_row[x] + D::template calcUpDownDist<T, IT>(a_up, a_down, b_up_ptr[bx], b_down_ptr[bx]); col_dist_sums_row[x] = up_col_dist_sums_row[x] + D::template calcUpDownDist<T>(a_up, a_down, b_up_ptr[bx], b_down_ptr[bx]);
dist_sums_row[x] += col_dist_sums_row[x]; dist_sums_row[x] += col_dist_sums_row[x];
up_col_dist_sums_row[x] = col_dist_sums_row[x]; up_col_dist_sums_row[x] = col_dist_sums_row[x];
...@@ -234,10 +234,10 @@ void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& range) ...@@ -234,10 +234,10 @@ void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& range)
for (int y = 0; y < search_window_size_; y++) for (int y = 0; y < search_window_size_; y++)
{ {
const T* cur_row_ptr = extended_src_.ptr<T>(border_size_ + search_window_y + y); const T* cur_row_ptr = extended_src_.ptr<T>(border_size_ + search_window_y + y);
IT* dist_sums_row = dist_sums.row_ptr(y); int* dist_sums_row = dist_sums.row_ptr(y);
for (int x = 0; x < search_window_size_; x++) for (int x = 0; x < search_window_size_; x++)
{ {
size_t almostAvgDist = (size_t)(dist_sums_row[x] >> almost_template_window_size_sq_bin_shift_); int almostAvgDist = dist_sums_row[x] >> almost_template_window_size_sq_bin_shift_;
IT weight = almost_dist2weight_[almostAvgDist]; IT weight = almost_dist2weight_[almostAvgDist];
weights_sum += weight; weights_sum += weight;
...@@ -257,9 +257,9 @@ void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& range) ...@@ -257,9 +257,9 @@ void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& range)
template <typename T, typename IT, typename UIT, typename D> template <typename T, typename IT, typename UIT, typename D>
inline void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForFirstElementInRow( inline void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForFirstElementInRow(
int i, int i,
Array2d<IT>& dist_sums, Array2d<int>& dist_sums,
Array3d<IT>& col_dist_sums, Array3d<int>& col_dist_sums,
Array3d<IT>& up_col_dist_sums) const Array3d<int>& up_col_dist_sums) const
{ {
int j = 0; int j = 0;
...@@ -276,7 +276,7 @@ inline void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForFirstElem ...@@ -276,7 +276,7 @@ inline void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForFirstElem
for (int ty = -template_window_half_size_; ty <= template_window_half_size_; ty++) for (int ty = -template_window_half_size_; ty <= template_window_half_size_; ty++)
for (int tx = -template_window_half_size_; tx <= template_window_half_size_; tx++) for (int tx = -template_window_half_size_; tx <= template_window_half_size_; tx++)
{ {
int dist = D::template calcDist<T, IT>(extended_src_, int dist = D::template calcDist<T>(extended_src_,
border_size_ + i + ty, border_size_ + j + tx, border_size_ + i + ty, border_size_ + j + tx,
border_size_ + start_y + ty, border_size_ + start_x + tx); border_size_ + start_y + ty, border_size_ + start_x + tx);
...@@ -291,9 +291,9 @@ inline void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForFirstElem ...@@ -291,9 +291,9 @@ inline void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForFirstElem
template <typename T, typename IT, typename UIT, typename D> template <typename T, typename IT, typename UIT, typename D>
inline void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForElementInFirstRow( inline void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForElementInFirstRow(
int i, int j, int first_col_num, int i, int j, int first_col_num,
Array2d<IT>& dist_sums, Array2d<int>& dist_sums,
Array3d<IT>& col_dist_sums, Array3d<int>& col_dist_sums,
Array3d<IT>& up_col_dist_sums) const Array3d<int>& up_col_dist_sums) const
{ {
int ay = border_size_ + i; int ay = border_size_ + i;
int ax = border_size_ + j + template_window_half_size_; int ax = border_size_ + j + template_window_half_size_;
...@@ -312,7 +312,7 @@ inline void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForElementIn ...@@ -312,7 +312,7 @@ inline void FastNlMeansDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForElementIn
int by = start_by + y; int by = start_by + y;
int bx = start_bx + x; int bx = start_bx + x;
for (int ty = -template_window_half_size_; ty <= template_window_half_size_; ty++) for (int ty = -template_window_half_size_; ty <= template_window_half_size_; ty++)
col_dist_sums[new_last_col_num][y][x] += D::template calcDist<T,IT>(extended_src_, ay + ty, ax, by + ty, bx); col_dist_sums[new_last_col_num][y][x] += D::template calcDist<T>(extended_src_, ay + ty, ax, by + ty, bx);
dist_sums[y][x] += col_dist_sums[new_last_col_num][y][x]; dist_sums[y][x] += col_dist_sums[new_last_col_num][y][x];
up_col_dist_sums[j][y][x] = col_dist_sums[new_last_col_num][y][x]; up_col_dist_sums[j][y][x] = col_dist_sums[new_last_col_num][y][x];
......
...@@ -83,63 +83,63 @@ template <typename T> struct pixelInfo: public pixelInfo_<T> ...@@ -83,63 +83,63 @@ template <typename T> struct pixelInfo: public pixelInfo_<T>
class DistAbs 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 return
std::abs((IT)(a[0]-b[0])) + std::abs((int)(a[0]-b[0])) +
std::abs((IT)(a[1]-b[1])) + std::abs((int)(a[1]-b[1])) +
std::abs((IT)(a[2]-b[2])); 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 return
std::abs((IT)(a[0]-b[0])) + std::abs((int)(a[0]-b[0])) +
std::abs((IT)(a[1]-b[1])) + std::abs((int)(a[1]-b[1])) +
std::abs((IT)(a[2]-b[2])) + std::abs((int)(a[2]-b[2])) +
std::abs((IT)(a[3]-b[3])); std::abs((int)(a[3]-b[3]));
} }
}; };
public: 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> template <typename T>
static inline IT calcDist(const Mat& m, int i1, int j1, int i2, int j2) 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 a = m.at<T>(i1, j1);
const T b = m.at<T>(i2, j2); const T b = m.at<T>(i2, j2);
return calcDist<T, IT>(a,b); return calcDist<T>(a,b);
} }
template <typename T, typename IT> template <typename T>
static inline IT calcUpDownDist(T a_up, T a_down, T b_up, T b_down) 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> template <typename T>
...@@ -148,93 +148,93 @@ public: ...@@ -148,93 +148,93 @@ public:
return std::exp(-dist*dist / (h * h * pixelInfo<T>::channels)); return std::exp(-dist*dist / (h * h * pixelInfo<T>::channels));
} }
template <typename T, typename IT> template <typename T>
static double maxDist() static double maxDist()
{ {
return (IT)pixelInfo<T>::sampleMax() * (IT)pixelInfo<T>::channels; return (int)pixelInfo<T>::sampleMax() * pixelInfo<T>::channels;
} }
}; };
class DistSquared 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 return
(IT)(a[0]-b[0])*(IT)(a[0]-b[0]) + (int)(a[0]-b[0])*(int)(a[0]-b[0]) +
(IT)(a[1]-b[1])*(IT)(a[1]-b[1]) + (int)(a[1]-b[1])*(int)(a[1]-b[1]) +
(IT)(a[2]-b[2])*(IT)(a[2]-b[2]); (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 return
(IT)(a[0]-b[0])*(IT)(a[0]-b[0]) + (int)(a[0]-b[0])*(int)(a[0]-b[0]) +
(IT)(a[1]-b[1])*(IT)(a[1]-b[1]) + (int)(a[1]-b[1])*(int)(a[1]-b[1]) +
(IT)(a[2]-b[2])*(IT)(a[2]-b[2]) + (int)(a[2]-b[2])*(int)(a[2]-b[2]) +
(IT)(a[3]-b[3])*(IT)(a[3]-b[3]); (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; int A = a_down - b_down;
IT B = a_up - b_up; int B = a_up - b_up;
return (A-B)*(A+B); 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: private:
typedef Vec<ET, n> T; typedef Vec<ET, n> T;
public: 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: 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> template <typename T>
static inline IT calcDist(const Mat& m, int i1, int j1, int i2, int j2) 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 a = m.at<T>(i1, j1);
const T b = m.at<T>(i2, j2); const T b = m.at<T>(i2, j2);
return calcDist<T, IT>(a,b); return calcDist<T>(a,b);
} }
template <typename T, typename IT> template <typename T>
static inline IT calcUpDownDist(T a_up, T a_down, T b_up, T b_down) 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> template <typename T>
...@@ -243,11 +243,11 @@ public: ...@@ -243,11 +243,11 @@ public:
return std::exp(-dist / (h * h * pixelInfo<T>::channels)); return std::exp(-dist / (h * h * pixelInfo<T>::channels));
} }
template <typename T, typename IT> template <typename T>
static double maxDist() static double maxDist()
{ {
return (IT)pixelInfo<T>::sampleMax() * (IT)pixelInfo<T>::sampleMax() * return (int)pixelInfo<T>::sampleMax() * (int)pixelInfo<T>::sampleMax() *
(IT)pixelInfo<T>::channels; pixelInfo<T>::channels;
} }
}; };
......
...@@ -85,13 +85,13 @@ private: ...@@ -85,13 +85,13 @@ private:
int almost_template_window_size_sq_bin_shift; int almost_template_window_size_sq_bin_shift;
std::vector<IT> almost_dist2weight; std::vector<IT> almost_dist2weight;
void calcDistSumsForFirstElementInRow(int i, Array3d<IT>& dist_sums, void calcDistSumsForFirstElementInRow(int i, Array3d<int>& dist_sums,
Array4d<IT>& col_dist_sums, Array4d<int>& col_dist_sums,
Array4d<IT>& up_col_dist_sums) const; Array4d<int>& up_col_dist_sums) const;
void calcDistSumsForElementInFirstRow(int i, int j, int first_col_num, void calcDistSumsForElementInFirstRow(int i, int j, int first_col_num,
Array3d<IT>& dist_sums, Array4d<IT>& col_dist_sums, Array3d<int>& dist_sums, Array4d<int>& col_dist_sums,
Array4d<IT>& up_col_dist_sums) const; Array4d<int>& up_col_dist_sums) const;
}; };
template <typename T, typename IT, typename UIT, typename D> template <typename T, typename IT, typename UIT, typename D>
...@@ -139,8 +139,8 @@ FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::FastNlMeansMultiDenoisingInvoke ...@@ -139,8 +139,8 @@ FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::FastNlMeansMultiDenoisingInvoke
int almost_template_window_size_sq = 1 << almost_template_window_size_sq_bin_shift; int almost_template_window_size_sq = 1 << almost_template_window_size_sq_bin_shift;
double almost_dist2actual_dist_multiplier = (double) almost_template_window_size_sq / template_window_size_sq; double almost_dist2actual_dist_multiplier = (double) almost_template_window_size_sq / template_window_size_sq;
IT max_dist = D::template maxDist<T,IT>(); int max_dist = D::template maxDist<T>();
int almost_max_dist = (int) (max_dist / almost_dist2actual_dist_multiplier + 1); int almost_max_dist = (int)(max_dist / almost_dist2actual_dist_multiplier + 1);
almost_dist2weight.resize(almost_max_dist); almost_dist2weight.resize(almost_max_dist);
const double WEIGHT_THRESHOLD = 0.001; const double WEIGHT_THRESHOLD = 0.001;
...@@ -166,13 +166,13 @@ void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& r ...@@ -166,13 +166,13 @@ void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& r
int row_from = range.start; int row_from = range.start;
int row_to = range.end - 1; int row_to = range.end - 1;
Array3d<IT> dist_sums(temporal_window_size_, search_window_size_, search_window_size_); Array3d<int> dist_sums(temporal_window_size_, search_window_size_, search_window_size_);
// for lazy calc optimization // for lazy calc optimization
Array4d<IT> col_dist_sums(template_window_size_, temporal_window_size_, search_window_size_, search_window_size_); Array4d<int> col_dist_sums(template_window_size_, temporal_window_size_, search_window_size_, search_window_size_);
int first_col_num = -1; int first_col_num = -1;
Array4d<IT> up_col_dist_sums(cols_, temporal_window_size_, search_window_size_, search_window_size_); Array4d<int> up_col_dist_sums(cols_, temporal_window_size_, search_window_size_, search_window_size_);
for (int i = row_from; i <= row_to; i++) for (int i = row_from; i <= row_to; i++)
{ {
...@@ -216,15 +216,15 @@ void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& r ...@@ -216,15 +216,15 @@ void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& r
for (int d = 0; d < temporal_window_size_; d++) for (int d = 0; d < temporal_window_size_; d++)
{ {
Mat cur_extended_src = extended_srcs_[d]; Mat cur_extended_src = extended_srcs_[d];
Array2d<IT> cur_dist_sums = dist_sums[d]; Array2d<int> cur_dist_sums = dist_sums[d];
Array2d<IT> cur_col_dist_sums = col_dist_sums[first_col_num][d]; Array2d<int> cur_col_dist_sums = col_dist_sums[first_col_num][d];
Array2d<IT> cur_up_col_dist_sums = up_col_dist_sums[j][d]; Array2d<int> cur_up_col_dist_sums = up_col_dist_sums[j][d];
for (int y = 0; y < search_window_size; y++) for (int y = 0; y < search_window_size; y++)
{ {
IT* dist_sums_row = cur_dist_sums.row_ptr(y); int* dist_sums_row = cur_dist_sums.row_ptr(y);
IT* col_dist_sums_row = cur_col_dist_sums.row_ptr(y); int* col_dist_sums_row = cur_col_dist_sums.row_ptr(y);
IT* up_col_dist_sums_row = cur_up_col_dist_sums.row_ptr(y); int* up_col_dist_sums_row = cur_up_col_dist_sums.row_ptr(y);
const T* b_up_ptr = cur_extended_src.ptr<T>(start_by - template_window_half_size_ - 1 + y); const T* b_up_ptr = cur_extended_src.ptr<T>(start_by - template_window_half_size_ - 1 + y);
const T* b_down_ptr = cur_extended_src.ptr<T>(start_by + template_window_half_size_ + y); const T* b_down_ptr = cur_extended_src.ptr<T>(start_by + template_window_half_size_ + y);
...@@ -234,7 +234,7 @@ void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& r ...@@ -234,7 +234,7 @@ void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& r
dist_sums_row[x] -= col_dist_sums_row[x]; dist_sums_row[x] -= col_dist_sums_row[x];
col_dist_sums_row[x] = up_col_dist_sums_row[x] + col_dist_sums_row[x] = up_col_dist_sums_row[x] +
D::template calcUpDownDist<T, IT>(a_up, a_down, b_up_ptr[start_bx + x], b_down_ptr[start_bx + x]); D::template calcUpDownDist<T>(a_up, a_down, b_up_ptr[start_bx + x], b_down_ptr[start_bx + x]);
dist_sums_row[x] += col_dist_sums_row[x]; dist_sums_row[x] += col_dist_sums_row[x];
up_col_dist_sums_row[x] = col_dist_sums_row[x]; up_col_dist_sums_row[x] = col_dist_sums_row[x];
...@@ -260,11 +260,11 @@ void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& r ...@@ -260,11 +260,11 @@ void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& r
{ {
const T* cur_row_ptr = esrc_d.ptr<T>(border_size_ + search_window_y + y); const T* cur_row_ptr = esrc_d.ptr<T>(border_size_ + search_window_y + y);
IT* dist_sums_row = dist_sums.row_ptr(d, y); int* dist_sums_row = dist_sums.row_ptr(d, y);
for (int x = 0; x < search_window_size_; x++) for (int x = 0; x < search_window_size_; x++)
{ {
size_t almostAvgDist = (size_t)(dist_sums_row[x] >> almost_template_window_size_sq_bin_shift); int almostAvgDist = dist_sums_row[x] >> almost_template_window_size_sq_bin_shift;
IT weight = almost_dist2weight[almostAvgDist]; IT weight = almost_dist2weight[almostAvgDist];
weights_sum += weight; weights_sum += weight;
...@@ -286,7 +286,7 @@ void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& r ...@@ -286,7 +286,7 @@ void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::operator() (const Range& r
template <typename T, typename IT, typename UIT, typename D> template <typename T, typename IT, typename UIT, typename D>
inline void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForFirstElementInRow( inline void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForFirstElementInRow(
int i, Array3d<IT>& dist_sums, Array4d<IT>& col_dist_sums, Array4d<IT>& up_col_dist_sums) const int i, Array3d<int>& dist_sums, Array4d<int>& col_dist_sums, Array4d<int>& up_col_dist_sums) const
{ {
int j = 0; int j = 0;
...@@ -303,14 +303,14 @@ inline void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForFirs ...@@ -303,14 +303,14 @@ inline void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForFirs
int start_y = i + y - search_window_half_size_; int start_y = i + y - search_window_half_size_;
int start_x = j + x - search_window_half_size_; int start_x = j + x - search_window_half_size_;
IT* dist_sums_ptr = &dist_sums[d][y][x]; int* dist_sums_ptr = &dist_sums[d][y][x];
IT* col_dist_sums_ptr = &col_dist_sums[0][d][y][x]; int* col_dist_sums_ptr = &col_dist_sums[0][d][y][x];
int col_dist_sums_step = col_dist_sums.step_size(0); int col_dist_sums_step = col_dist_sums.step_size(0);
for (int tx = -template_window_half_size_; tx <= template_window_half_size_; tx++) for (int tx = -template_window_half_size_; tx <= template_window_half_size_; tx++)
{ {
for (int ty = -template_window_half_size_; ty <= template_window_half_size_; ty++) for (int ty = -template_window_half_size_; ty <= template_window_half_size_; ty++)
{ {
IT dist = D::template calcDist<T, IT>( int dist = D::template calcDist<T>(
main_extended_src_.at<T>(border_size_ + i + ty, border_size_ + j + tx), main_extended_src_.at<T>(border_size_ + i + ty, border_size_ + j + tx),
cur_extended_src.at<T>(border_size_ + start_y + ty, border_size_ + start_x + tx)); cur_extended_src.at<T>(border_size_ + start_y + ty, border_size_ + start_x + tx));
...@@ -327,8 +327,8 @@ inline void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForFirs ...@@ -327,8 +327,8 @@ inline void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForFirs
template <typename T, typename IT, typename UIT, typename D> template <typename T, typename IT, typename UIT, typename D>
inline void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForElementInFirstRow( inline void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForElementInFirstRow(
int i, int j, int first_col_num, Array3d<IT>& dist_sums, int i, int j, int first_col_num, Array3d<int>& dist_sums,
Array4d<IT>& col_dist_sums, Array4d<IT>& up_col_dist_sums) const Array4d<int>& col_dist_sums, Array4d<int>& up_col_dist_sums) const
{ {
int ay = border_size_ + i; int ay = border_size_ + i;
int ax = border_size_ + j + template_window_half_size_; int ax = border_size_ + j + template_window_half_size_;
...@@ -350,10 +350,10 @@ inline void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForElem ...@@ -350,10 +350,10 @@ inline void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D>::calcDistSumsForElem
int by = start_by + y; int by = start_by + y;
int bx = start_bx + x; int bx = start_bx + x;
IT* col_dist_sums_ptr = &col_dist_sums[new_last_col_num][d][y][x]; int* col_dist_sums_ptr = &col_dist_sums[new_last_col_num][d][y][x];
for (int ty = -template_window_half_size_; ty <= template_window_half_size_; ty++) for (int ty = -template_window_half_size_; ty <= template_window_half_size_; ty++)
{ {
*col_dist_sums_ptr += D::template calcDist<T, IT>( *col_dist_sums_ptr += D::template calcDist<T>(
main_extended_src_.at<T>(ay + ty, ax), main_extended_src_.at<T>(ay + ty, ax),
cur_extended_src.at<T>(by + ty, bx)); cur_extended_src.at<T>(by + ty, bx));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment