在图像处理中经常有这样的处理函数,它在计算每个像素的数值时,需要使用周边像素的值。如果相邻像素在上一行或下一行,就需要同时扫描图像的多行。实现方法:
sharpened_pixel=5*current-left-right-up-down;
这里的left是与当前像素相邻的左侧像素,up是上一行的相邻像素,因此类推。
锐化滤波器的核心矩阵:
实现函数为cv::filter2D
#include<opencv2/core.hpp>
#include<opencv2/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
cv::Mat image;
cv::Mat result1;
cv::Mat result2;
void sharpen(const cv::Mat &image, cv::Mat &result) {
//判断是否需要分配图像数据。如果需要,就分配。
result.create(image.size(), image.type());
//获得通道数
int nchannels = image.channels();
//处理所有行(除了第一行和最后一行)
for (int j = 1; j < image.rows - 1; j++) {
const uchar* previous = image.ptr<const