1 | initial version |
Because in your particular case copyMakeBorder makes extrapolation, as a result you have got slightly different sum value. To prevent this you can make custom copy without extrapolation:
cv::Mat computeDFT(cv::Mat image, int optimal_rows, int optimal_cols) {
cv::Mat padded = cv::Mat(optimal_rows, optimal_cols, image.type());
std::cout << image.rows << " " << image.cols << " " << image.type() << " " << cv::sum(image) << std::endl;
cv::Mat _tempmat = cv::Mat(padded, cv::Rect(0,0,image.rows,image.cols));
image.copyTo(_tempmat);
std::cout << padded.rows << " " << padded.cols << " " << padded.type() << " " << cv::sum(padded) << std::endl;
cv::Mat complexImage(padded.rows, padded.cols, CV_64FC2);
cv::dft(padded, complexImage, CV_HAL_DFT_COMPLEX_OUTPUT);
return complexImage;
}
2 | No.2 Revision |
Because in your particular case copyMakeBorder makes extrapolation, as a result you have got slightly different sum value. To prevent this you can make custom copy without extrapolation:
cv::Mat computeDFT(cv::Mat image, int optimal_rows, int optimal_cols) {
cv::Mat padded = cv::Mat(optimal_rows, optimal_cols, image.type());
std::cout << image.rows << " " << image.cols << " " << image.type() << " " << cv::sum(image) << std::endl;
cv::Mat _tempmat = cv::Mat(padded, cv::Rect(0,0,image.rows,image.cols));
cv::Rect(0,0,image.cols,image.rows));
image.copyTo(_tempmat);
std::cout << padded.rows << " " << padded.cols << " " << padded.type() << " " << cv::sum(padded) << std::endl;
cv::Mat complexImage(padded.rows, padded.cols, CV_64FC2);
cv::dft(padded, complexImage, CV_HAL_DFT_COMPLEX_OUTPUT);
return complexImage;
}