目录
note
code
test
note
code
// 不扩充边缘的矩阵卷积,输出矩阵和输入矩阵一样大
void MyMatConvolute2(Mat& src, Mat& kernel, Mat& res) {
if (src.type() != CV_8UC1) {
return;
}
if ((kernel.type() != CV_8UC1) || (kernel.rows != kernel.cols) || (kernel.rows / 2 == 0)) {
return;
}
// 先扩大,再缩小为原来大小
int edge = kernel.rows / 2;
Mat tmp(src.rows+2*edge, src.cols+2*edge, CV_8UC1, Scalar(0));
for (int i = 0; i < src.rows; ++i) {
for (int j = 0; j < src.cols; ++j) {
tmp.at<uchar>(i+edge,j+edge) = src.at<uchar>(i,j);
}
}
MyMatConvolute1(tmp, kernel, res);
test