1 Star 0 Fork 1

宋佳蓁/Gaussianfilter

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
cacheAccelerate.cpp 1.81 KB
一键复制 编辑 原始数据 按行查看 历史
宋佳蓁 提交于 2022-07-11 01:03 . 1
#include "cacheAccelerate.h"
/**
* 2 dimension gaussian filter, cache accelerate
* @param src
* @param dst
* @param window
*/
void cacheGaussianFilter(Mat &src, Mat &dst, Mat window) {
int hh = (window.rows - 1) / 2;
int hw = (window.cols - 1) / 2;
dst = Mat::zeros(src.size(), src.type());
//边界填充
Mat newSrc;
copyMakeBorder(src, newSrc, hh, hh, hw, hw, BORDER_REPLICATE);//边界复制
vector<uchar> windowVector = window.reshape(1, 1);
vector<uchar> srcVector = newSrc.reshape(1, 1);
//高斯滤波
for (int i = hh; i < src.rows + hh; ++i) {
for (int j = hw; j < src.cols + hw; ++j) {
double sum[3] = {0};
for (int r = -hh; r <= hh; ++r) {
for (int c = -hw; c <= hw; ++c) {
if (src.channels() == 1)
{
// 1
sum[0] = sum[0] + visitOneDimVectorMat(srcVector, newSrc.rows, newSrc.cols, i+r, j+c) * visitOneDimVectorMat(windowVector, window.rows, window.cols, r + hh, c + hw);
// 2
// sum[0] = sum[0] + newSrc.at<uchar>(i + r, j + c) *
// visitOneDimVectorMat(windowVector, window.rows, window.cols, r + hh, c + hw);
// 3
// sum[0] = sum[0] + newSrc.at<uchar>(i + r, j + c) * window.at<double>(r + hh, c + hw);
}
}
}
for (int k = 0; k < src.channels(); ++k) {
if (sum[k] < 0)
sum[k] = 0;
else if (sum[k] > 255)
sum[k] = 255;
}
if (src.channels() == 1) {
dst.at<uchar>(i - hh, j - hw) = static_cast<uchar>(sum[0]);
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/song-jiazhen/Gaussianfilter.git
git@gitee.com:song-jiazhen/Gaussianfilter.git
song-jiazhen
Gaussianfilter
Gaussianfilter
master

搜索帮助