Opencv卷积操作
OpenCv卷积操作:通过矩阵运算,给图像的每个像素重新赋值,选择不同的矩阵(kernel,卷积核),可以实现不同的效果.
锐化
[0,-1,0]
[-1,5,-1]
[0,-1,0]
锐化运算
int cols = src.cols * src.channels();
int offset = src.channels();
int rows = src.rows;
Mat dst = Mat::zeros(src.size(), src.type());
for (int row = 1; row < (rows - 1); row++) {
const uchar *pre = src.ptr<uchar>(row - 1);
const uchar *current = src.ptr<uchar>(row);
const uchar *next = src.ptr<uchar>(row + 1);
uchar *output = dst.ptr<uchar>(row);
for (int col = offset; col < cols; ++col) {
//矩阵运算
output[col] = saturate_cast<uchar>(5 * current[col] - current[col - offset] -
current[col + offset] - pre[col] - next[col]);
}
saturate_cast<uchar>
取值0-255,