2012-08-19 17:13:58 +08:00
|
|
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
|
|
|
//
|
|
|
|
// By downloading, copying, installing or using the software you agree to this license.
|
|
|
|
// If you do not agree to this license, do not download, install,
|
|
|
|
// copy or use the software.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Intel License Agreement
|
|
|
|
// For Open Source Computer Vision Library
|
|
|
|
//
|
|
|
|
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
|
|
|
// Third party copyrights are property of their respective icvers.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
// are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistribution's of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// * The name of Intel Corporation may not be used to endorse or promote products
|
|
|
|
// derived from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// This software is provided by the copyright holders and contributors "as is" and
|
|
|
|
// any express or implied warranties, including, but not limited to, the implied
|
|
|
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
|
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
|
|
// indirect, incidental, special, exemplary, or consequential damages
|
|
|
|
// (including, but not limited to, procurement of substitute goods or services;
|
|
|
|
// loss of use, data, or profits; or business interruption) however caused
|
|
|
|
// and on any theory of liability, whether in contract, strict liability,
|
|
|
|
// or tort (including negligence or otherwise) arising in any way out of
|
|
|
|
// the use of this software, even if advised of the possibility of such damage.
|
|
|
|
//
|
|
|
|
//M*/
|
|
|
|
|
|
|
|
#ifndef __OPENCV_FAST_NLMEANS_MULTI_DENOISING_INVOKER_HPP__
|
|
|
|
#define __OPENCV_FAST_NLMEANS_MULTI_DENOISING_INVOKER_HPP__
|
|
|
|
|
|
|
|
#include "precomp.hpp"
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
#include "fast_nlmeans_denoising_invoker_commons.hpp"
|
|
|
|
#include "arrays.hpp"
|
|
|
|
|
|
|
|
using namespace cv;
|
|
|
|
|
2015-03-06 00:50:52 +08:00
|
|
|
template <typename T, typename IT, typename UIT, typename D, typename WT>
|
2014-02-11 23:08:13 +08:00
|
|
|
struct FastNlMeansMultiDenoisingInvoker :
|
|
|
|
ParallelLoopBody
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FastNlMeansMultiDenoisingInvoker(const std::vector<Mat>& srcImgs, int imgToDenoiseIndex,
|
|
|
|
int temporalWindowSize, Mat& dst, int template_window_size,
|
2015-03-06 00:50:52 +08:00
|
|
|
int search_window_size, const float *h);
|
2014-02-11 23:08:13 +08:00
|
|
|
|
2018-03-15 21:17:00 +08:00
|
|
|
void operator() (const Range& range) const CV_OVERRIDE;
|
2014-02-11 23:08:13 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
void operator= (const FastNlMeansMultiDenoisingInvoker&);
|
|
|
|
|
|
|
|
int rows_;
|
|
|
|
int cols_;
|
|
|
|
|
|
|
|
Mat& dst_;
|
|
|
|
|
|
|
|
std::vector<Mat> extended_srcs_;
|
|
|
|
Mat main_extended_src_;
|
|
|
|
int border_size_;
|
|
|
|
|
|
|
|
int template_window_size_;
|
|
|
|
int search_window_size_;
|
|
|
|
int temporal_window_size_;
|
|
|
|
|
|
|
|
int template_window_half_size_;
|
|
|
|
int search_window_half_size_;
|
|
|
|
int temporal_window_half_size_;
|
|
|
|
|
2015-03-06 21:28:43 +08:00
|
|
|
typename pixelInfo<WT>::sampleType fixed_point_mult_;
|
2014-02-11 23:08:13 +08:00
|
|
|
int almost_template_window_size_sq_bin_shift;
|
2015-03-06 00:50:52 +08:00
|
|
|
std::vector<WT> almost_dist2weight;
|
2014-02-11 23:08:13 +08:00
|
|
|
|
2015-03-05 20:36:42 +08:00
|
|
|
void calcDistSumsForFirstElementInRow(int i, Array3d<int>& dist_sums,
|
|
|
|
Array4d<int>& col_dist_sums,
|
|
|
|
Array4d<int>& up_col_dist_sums) const;
|
2014-02-11 23:08:13 +08:00
|
|
|
|
|
|
|
void calcDistSumsForElementInFirstRow(int i, int j, int first_col_num,
|
2015-03-05 20:36:42 +08:00
|
|
|
Array3d<int>& dist_sums, Array4d<int>& col_dist_sums,
|
|
|
|
Array4d<int>& up_col_dist_sums) const;
|
2012-08-19 17:13:58 +08:00
|
|
|
};
|
|
|
|
|
2015-03-06 00:50:52 +08:00
|
|
|
template <typename T, typename IT, typename UIT, typename D, typename WT>
|
|
|
|
FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D, WT>::FastNlMeansMultiDenoisingInvoker(
|
2013-02-25 00:14:01 +08:00
|
|
|
const std::vector<Mat>& srcImgs,
|
2012-09-17 21:18:04 +08:00
|
|
|
int imgToDenoiseIndex,
|
|
|
|
int temporalWindowSize,
|
|
|
|
cv::Mat& dst,
|
|
|
|
int template_window_size,
|
|
|
|
int search_window_size,
|
2015-03-06 00:50:52 +08:00
|
|
|
const float *h) :
|
2014-02-11 23:08:13 +08:00
|
|
|
dst_(dst), extended_srcs_(srcImgs.size())
|
2012-08-19 17:13:58 +08:00
|
|
|
{
|
2012-08-21 20:05:18 +08:00
|
|
|
CV_Assert(srcImgs.size() > 0);
|
2015-02-13 01:45:09 +08:00
|
|
|
CV_Assert(srcImgs[0].channels() == pixelInfo<T>::channels);
|
2012-08-21 20:05:18 +08:00
|
|
|
|
2012-08-19 17:13:58 +08:00
|
|
|
rows_ = srcImgs[0].rows;
|
|
|
|
cols_ = srcImgs[0].cols;
|
|
|
|
|
|
|
|
template_window_half_size_ = template_window_size / 2;
|
|
|
|
search_window_half_size_ = search_window_size / 2;
|
|
|
|
temporal_window_half_size_ = temporalWindowSize / 2;
|
|
|
|
|
|
|
|
template_window_size_ = template_window_half_size_ * 2 + 1;
|
|
|
|
search_window_size_ = search_window_half_size_ * 2 + 1;
|
|
|
|
temporal_window_size_ = temporal_window_half_size_ * 2 + 1;
|
|
|
|
|
|
|
|
border_size_ = search_window_half_size_ + template_window_half_size_;
|
2014-02-11 23:08:13 +08:00
|
|
|
for (int i = 0; i < temporal_window_size_; i++)
|
|
|
|
copyMakeBorder(srcImgs[imgToDenoiseIndex - temporal_window_half_size_ + i], extended_srcs_[i],
|
2012-08-19 17:13:58 +08:00
|
|
|
border_size_, border_size_, border_size_, border_size_, cv::BORDER_DEFAULT);
|
|
|
|
|
2014-02-11 23:08:13 +08:00
|
|
|
main_extended_src_ = extended_srcs_[temporal_window_half_size_];
|
2015-02-12 22:23:28 +08:00
|
|
|
const IT max_estimate_sum_value =
|
2015-02-13 01:45:09 +08:00
|
|
|
(IT)temporal_window_size_ * (IT)search_window_size_ * (IT)search_window_size_ * (IT)pixelInfo<T>::sampleMax();
|
2015-03-05 20:55:06 +08:00
|
|
|
fixed_point_mult_ = (int)std::min<IT>(std::numeric_limits<IT>::max() / max_estimate_sum_value,
|
2015-03-06 21:28:43 +08:00
|
|
|
pixelInfo<WT>::sampleMax());
|
2012-08-19 17:13:58 +08:00
|
|
|
|
|
|
|
// precalc weight for every possible l2 dist between blocks
|
|
|
|
// additional optimization of precalced weights to replace division(averaging) by binary shift
|
|
|
|
int template_window_size_sq = template_window_size_ * template_window_size_;
|
|
|
|
almost_template_window_size_sq_bin_shift = 0;
|
2014-02-11 23:08:13 +08:00
|
|
|
while (1 << almost_template_window_size_sq_bin_shift < template_window_size_sq)
|
2012-08-19 17:13:58 +08:00
|
|
|
almost_template_window_size_sq_bin_shift++;
|
2012-09-17 21:18:04 +08:00
|
|
|
|
2012-08-19 17:13:58 +08:00
|
|
|
int almost_template_window_size_sq = 1 << almost_template_window_size_sq_bin_shift;
|
2014-02-11 23:08:13 +08:00
|
|
|
double almost_dist2actual_dist_multiplier = (double) almost_template_window_size_sq / template_window_size_sq;
|
2012-08-19 17:13:58 +08:00
|
|
|
|
2015-03-05 20:36:42 +08:00
|
|
|
int max_dist = D::template maxDist<T>();
|
|
|
|
int almost_max_dist = (int)(max_dist / almost_dist2actual_dist_multiplier + 1);
|
2015-02-18 06:08:36 +08:00
|
|
|
almost_dist2weight.resize(almost_max_dist);
|
|
|
|
|
|
|
|
for (int almost_dist = 0; almost_dist < almost_max_dist; almost_dist++)
|
2014-02-11 23:08:13 +08:00
|
|
|
{
|
2015-02-18 06:08:36 +08:00
|
|
|
double dist = almost_dist * almost_dist2actual_dist_multiplier;
|
2015-03-06 00:50:52 +08:00
|
|
|
almost_dist2weight[almost_dist] =
|
|
|
|
D::template calcWeight<T, WT>(dist, h, fixed_point_mult_);
|
2012-08-19 17:13:58 +08:00
|
|
|
}
|
|
|
|
|
2014-02-11 23:08:13 +08:00
|
|
|
// additional optimization init end
|
|
|
|
if (dst_.empty())
|
2012-08-19 17:13:58 +08:00
|
|
|
dst_ = Mat::zeros(srcImgs[0].size(), srcImgs[0].type());
|
|
|
|
}
|
|
|
|
|
2015-03-06 00:50:52 +08:00
|
|
|
template <typename T, typename IT, typename UIT, typename D, typename WT>
|
|
|
|
void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D, WT>::operator() (const Range& range) const
|
2014-02-11 23:08:13 +08:00
|
|
|
{
|
2013-05-30 22:44:33 +08:00
|
|
|
int row_from = range.start;
|
|
|
|
int row_to = range.end - 1;
|
2012-08-19 17:13:58 +08:00
|
|
|
|
2015-03-05 20:36:42 +08:00
|
|
|
Array3d<int> dist_sums(temporal_window_size_, search_window_size_, search_window_size_);
|
2012-09-17 21:18:04 +08:00
|
|
|
|
2012-08-19 17:13:58 +08:00
|
|
|
// for lazy calc optimization
|
2015-03-05 20:36:42 +08:00
|
|
|
Array4d<int> col_dist_sums(template_window_size_, temporal_window_size_, search_window_size_, search_window_size_);
|
2012-09-17 21:18:04 +08:00
|
|
|
|
2012-08-19 17:13:58 +08:00
|
|
|
int first_col_num = -1;
|
2015-03-05 20:36:42 +08:00
|
|
|
Array4d<int> up_col_dist_sums(cols_, temporal_window_size_, search_window_size_, search_window_size_);
|
2012-08-19 17:13:58 +08:00
|
|
|
|
2014-02-11 23:08:13 +08:00
|
|
|
for (int i = row_from; i <= row_to; i++)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < cols_; j++)
|
|
|
|
{
|
2012-08-19 17:13:58 +08:00
|
|
|
int search_window_y = i - search_window_half_size_;
|
|
|
|
int search_window_x = j - search_window_half_size_;
|
|
|
|
|
|
|
|
// calc dist_sums
|
2014-02-11 23:08:13 +08:00
|
|
|
if (j == 0)
|
|
|
|
{
|
2012-08-19 17:13:58 +08:00
|
|
|
calcDistSumsForFirstElementInRow(i, dist_sums, col_dist_sums, up_col_dist_sums);
|
|
|
|
first_col_num = 0;
|
2014-02-11 23:08:13 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// calc cur dist_sums using previous dist_sums
|
|
|
|
if (i == row_from)
|
|
|
|
{
|
2012-09-17 21:18:04 +08:00
|
|
|
calcDistSumsForElementInFirstRow(i, j, first_col_num,
|
|
|
|
dist_sums, col_dist_sums, up_col_dist_sums);
|
2012-08-19 17:13:58 +08:00
|
|
|
|
2014-02-11 23:08:13 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-17 21:18:04 +08:00
|
|
|
int ay = border_size_ + i;
|
2012-08-19 17:13:58 +08:00
|
|
|
int ax = border_size_ + j + template_window_half_size_;
|
|
|
|
|
2012-09-17 21:18:04 +08:00
|
|
|
int start_by =
|
2012-08-19 17:13:58 +08:00
|
|
|
border_size_ + i - search_window_half_size_;
|
|
|
|
|
2012-09-17 21:18:04 +08:00
|
|
|
int start_bx =
|
2012-08-19 17:13:58 +08:00
|
|
|
border_size_ + j - search_window_half_size_ + template_window_half_size_;
|
|
|
|
|
|
|
|
T a_up = main_extended_src_.at<T>(ay - template_window_half_size_ - 1, ax);
|
|
|
|
T a_down = main_extended_src_.at<T>(ay + template_window_half_size_, ax);
|
|
|
|
|
|
|
|
// copy class member to local variable for optimization
|
|
|
|
int search_window_size = search_window_size_;
|
|
|
|
|
2014-02-11 23:08:13 +08:00
|
|
|
for (int d = 0; d < temporal_window_size_; d++)
|
|
|
|
{
|
2012-08-19 17:13:58 +08:00
|
|
|
Mat cur_extended_src = extended_srcs_[d];
|
2015-03-05 20:36:42 +08:00
|
|
|
Array2d<int> cur_dist_sums = dist_sums[d];
|
|
|
|
Array2d<int> cur_col_dist_sums = col_dist_sums[first_col_num][d];
|
|
|
|
Array2d<int> cur_up_col_dist_sums = up_col_dist_sums[j][d];
|
2014-02-11 23:08:13 +08:00
|
|
|
for (int y = 0; y < search_window_size; y++)
|
|
|
|
{
|
2015-03-05 20:36:42 +08:00
|
|
|
int* dist_sums_row = cur_dist_sums.row_ptr(y);
|
2012-09-17 21:18:04 +08:00
|
|
|
|
2015-03-05 20:36:42 +08:00
|
|
|
int* col_dist_sums_row = cur_col_dist_sums.row_ptr(y);
|
|
|
|
int* up_col_dist_sums_row = cur_up_col_dist_sums.row_ptr(y);
|
2012-08-19 17:13:58 +08:00
|
|
|
|
2014-02-11 23:08:13 +08:00
|
|
|
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);
|
2012-09-17 21:18:04 +08:00
|
|
|
|
2014-02-11 23:08:13 +08:00
|
|
|
for (int x = 0; x < search_window_size; x++)
|
|
|
|
{
|
2012-08-19 17:13:58 +08:00
|
|
|
dist_sums_row[x] -= col_dist_sums_row[x];
|
2012-09-17 21:18:04 +08:00
|
|
|
|
|
|
|
col_dist_sums_row[x] = up_col_dist_sums_row[x] +
|
2015-03-05 20:36:42 +08:00
|
|
|
D::template calcUpDownDist<T>(a_up, a_down, b_up_ptr[start_bx + x], b_down_ptr[start_bx + x]);
|
2012-08-19 17:13:58 +08:00
|
|
|
|
|
|
|
dist_sums_row[x] += col_dist_sums_row[x];
|
|
|
|
up_col_dist_sums_row[x] = col_dist_sums_row[x];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-17 21:18:04 +08:00
|
|
|
|
2012-08-19 17:13:58 +08:00
|
|
|
first_col_num = (first_col_num + 1) % template_window_size_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// calc weights
|
2015-03-06 21:28:43 +08:00
|
|
|
IT estimation[pixelInfo<T>::channels], weights_sum[pixelInfo<WT>::channels];
|
2015-02-13 05:14:01 +08:00
|
|
|
for (size_t channel_num = 0; channel_num < pixelInfo<T>::channels; channel_num++)
|
2015-03-06 21:28:43 +08:00
|
|
|
estimation[channel_num] = 0;
|
|
|
|
for (size_t channel_num = 0; channel_num < pixelInfo<WT>::channels; channel_num++)
|
|
|
|
weights_sum[channel_num] = 0;
|
2014-02-11 23:08:13 +08:00
|
|
|
|
|
|
|
for (int d = 0; d < temporal_window_size_; d++)
|
|
|
|
{
|
2012-08-21 21:16:06 +08:00
|
|
|
const Mat& esrc_d = extended_srcs_[d];
|
2014-02-11 23:08:13 +08:00
|
|
|
for (int y = 0; y < search_window_size_; y++)
|
|
|
|
{
|
2012-08-21 21:16:06 +08:00
|
|
|
const T* cur_row_ptr = esrc_d.ptr<T>(border_size_ + search_window_y + y);
|
2012-08-19 17:13:58 +08:00
|
|
|
|
2015-03-05 20:36:42 +08:00
|
|
|
int* dist_sums_row = dist_sums.row_ptr(d, y);
|
2012-08-19 17:13:58 +08:00
|
|
|
|
2014-02-11 23:08:13 +08:00
|
|
|
for (int x = 0; x < search_window_size_; x++)
|
|
|
|
{
|
2015-03-05 20:36:42 +08:00
|
|
|
int almostAvgDist = dist_sums_row[x] >> almost_template_window_size_sq_bin_shift;
|
2012-08-19 17:13:58 +08:00
|
|
|
|
2015-03-07 03:43:55 +08:00
|
|
|
WT weight = almost_dist2weight[almostAvgDist];
|
2012-08-19 17:13:58 +08:00
|
|
|
T p = cur_row_ptr[border_size_ + search_window_x + x];
|
2015-03-06 00:50:52 +08:00
|
|
|
incWithWeight<T, IT, WT>(estimation, weights_sum, weight, p);
|
2012-08-19 17:13:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-06 21:28:43 +08:00
|
|
|
divByWeightsSum<IT, UIT, pixelInfo<T>::channels, pixelInfo<WT>::channels>(estimation,
|
|
|
|
weights_sum);
|
2015-02-12 22:23:28 +08:00
|
|
|
dst_.at<T>(i,j) = saturateCastFromArray<T, IT>(estimation);
|
2012-08-19 17:13:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-06 00:50:52 +08:00
|
|
|
template <typename T, typename IT, typename UIT, typename D, typename WT>
|
|
|
|
inline void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D, WT>::calcDistSumsForFirstElementInRow(
|
2015-03-05 20:36:42 +08:00
|
|
|
int i, Array3d<int>& dist_sums, Array4d<int>& col_dist_sums, Array4d<int>& up_col_dist_sums) const
|
2012-08-19 17:13:58 +08:00
|
|
|
{
|
|
|
|
int j = 0;
|
|
|
|
|
2014-02-11 23:08:13 +08:00
|
|
|
for (int d = 0; d < temporal_window_size_; d++)
|
|
|
|
{
|
2012-08-19 17:13:58 +08:00
|
|
|
Mat cur_extended_src = extended_srcs_[d];
|
2014-02-11 23:08:13 +08:00
|
|
|
for (int y = 0; y < search_window_size_; y++)
|
|
|
|
for (int x = 0; x < search_window_size_; x++)
|
|
|
|
{
|
2012-08-19 17:13:58 +08:00
|
|
|
dist_sums[d][y][x] = 0;
|
2014-02-11 23:08:13 +08:00
|
|
|
for (int tx = 0; tx < template_window_size_; tx++)
|
2012-08-19 17:13:58 +08:00
|
|
|
col_dist_sums[tx][d][y][x] = 0;
|
|
|
|
|
|
|
|
int start_y = i + y - search_window_half_size_;
|
|
|
|
int start_x = j + x - search_window_half_size_;
|
|
|
|
|
2015-03-05 20:36:42 +08:00
|
|
|
int* dist_sums_ptr = &dist_sums[d][y][x];
|
|
|
|
int* col_dist_sums_ptr = &col_dist_sums[0][d][y][x];
|
2012-09-17 21:18:04 +08:00
|
|
|
int col_dist_sums_step = col_dist_sums.step_size(0);
|
2014-02-11 23:08:13 +08:00
|
|
|
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++)
|
|
|
|
{
|
2015-03-05 20:36:42 +08:00
|
|
|
int dist = D::template calcDist<T>(
|
2014-02-11 23:08:13 +08:00
|
|
|
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));
|
2012-08-19 17:13:58 +08:00
|
|
|
|
|
|
|
*dist_sums_ptr += dist;
|
|
|
|
*col_dist_sums_ptr += dist;
|
|
|
|
}
|
|
|
|
col_dist_sums_ptr += col_dist_sums_step;
|
|
|
|
}
|
|
|
|
|
|
|
|
up_col_dist_sums[j][d][y][x] = col_dist_sums[template_window_size_ - 1][d][y][x];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-06 00:50:52 +08:00
|
|
|
template <typename T, typename IT, typename UIT, typename D, typename WT>
|
|
|
|
inline void FastNlMeansMultiDenoisingInvoker<T, IT, UIT, D, WT>::calcDistSumsForElementInFirstRow(
|
2015-03-05 20:36:42 +08:00
|
|
|
int i, int j, int first_col_num, Array3d<int>& dist_sums,
|
|
|
|
Array4d<int>& col_dist_sums, Array4d<int>& up_col_dist_sums) const
|
2012-08-19 17:13:58 +08:00
|
|
|
{
|
2012-09-17 21:18:04 +08:00
|
|
|
int ay = border_size_ + i;
|
2012-08-19 17:13:58 +08:00
|
|
|
int ax = border_size_ + j + template_window_half_size_;
|
|
|
|
|
|
|
|
int start_by = border_size_ + i - search_window_half_size_;
|
|
|
|
int start_bx = border_size_ + j - search_window_half_size_ + template_window_half_size_;
|
2012-09-17 21:18:04 +08:00
|
|
|
|
2012-08-19 17:13:58 +08:00
|
|
|
int new_last_col_num = first_col_num;
|
|
|
|
|
2014-02-11 23:08:13 +08:00
|
|
|
for (int d = 0; d < temporal_window_size_; d++)
|
|
|
|
{
|
2012-08-19 17:13:58 +08:00
|
|
|
Mat cur_extended_src = extended_srcs_[d];
|
2014-02-11 23:08:13 +08:00
|
|
|
for (int y = 0; y < search_window_size_; y++)
|
|
|
|
for (int x = 0; x < search_window_size_; x++)
|
|
|
|
{
|
2012-08-19 17:13:58 +08:00
|
|
|
dist_sums[d][y][x] -= col_dist_sums[first_col_num][d][y][x];
|
2012-09-17 21:18:04 +08:00
|
|
|
|
|
|
|
col_dist_sums[new_last_col_num][d][y][x] = 0;
|
|
|
|
int by = start_by + y;
|
2012-08-19 17:13:58 +08:00
|
|
|
int bx = start_bx + x;
|
|
|
|
|
2015-03-05 20:36:42 +08:00
|
|
|
int* col_dist_sums_ptr = &col_dist_sums[new_last_col_num][d][y][x];
|
2014-02-11 23:08:13 +08:00
|
|
|
for (int ty = -template_window_half_size_; ty <= template_window_half_size_; ty++)
|
|
|
|
{
|
2015-03-05 20:36:42 +08:00
|
|
|
*col_dist_sums_ptr += D::template calcDist<T>(
|
2014-02-11 23:08:13 +08:00
|
|
|
main_extended_src_.at<T>(ay + ty, ax),
|
|
|
|
cur_extended_src.at<T>(by + ty, bx));
|
2012-09-17 21:18:04 +08:00
|
|
|
}
|
2012-08-19 17:13:58 +08:00
|
|
|
|
|
|
|
dist_sums[d][y][x] += col_dist_sums[new_last_col_num][d][y][x];
|
|
|
|
|
|
|
|
up_col_dist_sums[j][d][y][x] = col_dist_sums[new_last_col_num][d][y][x];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|