这个程序有bug,暂时还没找到原因:
/*
*本程序的主要功能是图像锐化
*2014年1月4日,
*/
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
void imageSharpen(const Mat &image, Mat &result);
int main()
{
Mat image = imread("D:/fodder/7.tif");
Mat result;
if(!image.data)
{
return -1;
}
namedWindow("原始图像");
imshow("原始图像", image);
imageSharpen(image, result);
namedWindow("锐化图像");
imshow("锐化图像", result);
waitKey(0);
destroyAllWindows();
return 0;
}
void imageSharpen(const Mat &image, Mat &result)
{
result.create(image.size(), image.type());
for(int j = 1; j<image.rows - 1; j++)//第一行和最后一行没有处理
{
const uchar* previous = image.ptr<const uchar>(j - 1);
const uchar* current = image.ptr<const uchar>(j);
const uchar* next = image.ptr<const uchar>(j + 1);
uchar* output = result.ptr<uchar>(j);
for(int i = 1; i < image.cols - 1; i++)
{
*output++ = saturate_cast<uchar>(5 * current[i] - current[i-1] - current[i+1] - previous[i] - next[i]);
}
}
//
result.row(0).setTo(Scalar(0));
result.row(result.rows - 1).setTo(Scalar(0));
result.col(0).setTo(Scalar(0));
result.col(result.cols - 1).setTo(Scalar(0));
}