作为代码界的菜鸟,最近在尝试着用vs实现《数字图像处理与机器视觉》一书中有关图像处理的VC++代码。目前在研究空间域增强,希望自己能够越走越远^_^
本篇是图像锐化中的Sobel锐化图像的实现。
#include <iostream>
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
using namespace std;
using namespace cv;
//Sobel垂直边缘检测
float Template_Smooth_HSobel[9] = { -1, 0, 1, -2, 0, 2, -1, 0, 1 };
//Sobel水平边缘检测
float Template_Smooth_VSobel[9] = { -1, -2, -1, 0, 0, 0, 1, 2, 1 };
void FilterSobel(Mat img, Mat &dst)
{
Mat test1 = dst.clone();
Mat test2 = dst.clone();
Template(img, test1, 3, 3, 1, 1, Template_Smooth_HSobel, 1);
Template(img, test2, 3, 3, 1, 1, Template_Smooth_VSobel, 1);
dst = test1 + test2;
}
void main()
{
Mat img = imread("2.jpg");
cvNamedWindow("原图", CV_WINDOW_FREERATIO);
imshow("原图", img);
Mat dst=img.clone();
Sobel梯度
FilterSobel(img, dst);
cvNamedWindow("Sobel锐化", CV_WINDOW_FREERATIO);
imshow("Sobel锐化", dst);
waitKey(0);
}
原图:
结果图:
这个结果真不想贴出来,丑瞎了。。。