您的位置:首页 > 其它

遍历图像和邻域操作,图像锐化

2014-04-15 13:43 92 查看
#include<opencv2\core\core.hpp>
#include<opencv2\imgproc\imgproc.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<iostream>

using namespace std;
using namespace cv;

//锐化函数
void sharpen(const cv::Mat &image,cv::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++=cv::saturate_cast<uchar>(5*current[i]-current[i-1]-current[i+1]-previous[i]-next[i]);
}
}
result.row(0).setTo(cv::Scalar(0));
result.row(result.rows-1).setTo(cv::Scalar(0));
result.col(0).setTo(cv::Scalar(0));
result.col(result.cols-1).setTo(cv::Scalar(0));
}
int main()
{
cv::Mat image=cv::imread("d:\\test\\opencv\\img.jpg",0);//注意灰色图像
cv::Mat out;
sharpen(image,out);
cv::namedWindow("result");
cv::imshow("result",out);
cv::namedWindow("img");
cv::imshow("img",image);
waitKey(0);
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: