A question about sharpen image
Added by ni mingzhe over 12 years ago
Hello everyone.
Here is the code from the book OpenCV 2 Computer Vision Application Programming Cookbook and I used vs2010 in Windows system to compile it.
#include <opencv2/opencv.hpp>
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++)
{ // for all rows
// (except first and last)
const uchar* previous=
image.ptr<const uchar>(j-1); // previous row
const uchar* current=
image.ptr<const uchar>(j); // current row
const uchar* next=
image.ptr<const uchar>(j+1); // next row
uchar* output= result.ptr<uchar>(j); // output row
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]);
}
}
}
int main(int argc, char* argv[])
{
const char* imagename = "E:\\library\\Pictures\\grayLena.jpg";
Mat img = imread(imagename);
if(img.empty())
{
fprintf(stderr, "Can not load image %s\n", imagename);
system("pause");
return -1;
}
Mat result;
result.create(img.size(),img.type());
sharpen(img,result);
imshow("image", img);
imshow("result",result);
waitKey();
return 0;
}
2/3 of the result image is a gray rectangle. I don't know why and how to solve it.
Thank you for your attention.