下面是一个灰度图锐化的函数,我有两种方式实现,方式1,和方式2,居然得到的结果不一样,图片数据也不一样,请高手看一下,可能是C语言的知识掌握的不好。
void my_sharpen(const cv::Mat &image, cv::Mat &result)
{
result.create (image.size(), image.type ());
for(int j=1; j<image.rows-1; j++)
{
uchar* output = result.ptr<uchar>(j);
for(int i=1; i<image.cols-1; i++)
{
/* 方式1
*output++ = cv::saturate_cast<uchar> (5*image.ptr<const uchar>(j)[i] -image.ptr<const uchar>(j)[i-1]
-image.ptr<const uchar>(j)[i+1]-image.ptr<const uchar>(j-1)[i]-image.ptr<const uchar>(j+1)[i]);
*/
/* 方式2
result.ptr <uchar>(j)[i] = cv::saturate_cast<uchar> (5*image.ptr<const uchar>(j)[i] -image.ptr<const uchar>(j)[i-1]
-image.ptr<const uchar>(j)[i+1]-image.ptr<const uchar>(j-1)[i]-image.ptr<const uchar>(j+1)[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));
}