边缘检测的各种微分算子比较(Sobel,Robert,Prewitt,Laplacian,Canny)
http://blog.sina.com.cn/s/blog_60a0e97e0101b595.html
###################################################
图像处理中各种边缘检测的微分算子简单比较(Sobel,Robert, Prewitt,Laplacian,Canny)
http://blog.csdn.net/xiaojiegege123456/article/details/7714863
##################################################3
/* Smoothes array (removes noise) */ CVAPI(void) cvSmooth( const CvArr* src, CvArr* dst, int smoothtype CV_DEFAULT(CV_GAUSSIAN), int size1 CV_DEFAULT(3), int size2 CV_DEFAULT(0), double sigma1 CV_DEFAULT(0), double sigma2 CV_DEFAULT(0));
"平滑处理"也称“模糊处理”(blurring)
主要功能:减少图像上的噪声或者失真
/* Runs canny edge detector */ CVAPI(void) cvCanny( const CvArr* image, CvArr* edges, double threshold1, double threshold2, int aperture_size CV_DEFAULT(3) );
image:输入图像(源图像)
edges:边缘检测图像(结果图像)
threshold1:低阈值 (上下限阈值比为2:1或3:1之间较好)
threshold2:高阈值
canny算子原理:首先在x和y方向求一阶倒数,然后组合为4个方向的导数。这些方向倒数达到局部最大值的点就是组成边缘的候选点
canny算子有两个阈值,如果一个像素的梯度大于上限阈值,则被认为是边缘像素,如果低于下限阈值,则被抛弃,如果介于二者之间,只有当其与高于上限阈值的像素连接时才会被接受。
note:cvCanny()函数需要输入一幅灰度图,输出图也一定是灰度图像
程序:进行平滑处理后的canny()算子检测图和未进行平滑处理的检测图
//cvCanny void canny(void) { IplImage *src=cvLoadImage("lena.jpg", CV_LOAD_IMAGE_GRAYSCALE); IplImage *dst_NoSmooth=cvCreateImage(cvGetSize(src), src->depth, src->nChannels); IplImage *dst_Smooth=cvCreateImage(cvGetSize(src), src->depth, src->nChannels); if (src == NULL || dst_NoSmooth == NULL || dst_Smooth == NULL) exit(0); cvCanny(src, dst_NoSmooth, 100, 150, 3); cvSmooth(src, src, CV_GAUSSIAN, 3, 3);//平滑图像处理-高斯模糊 cvCanny(src, dst_Smooth, 100, 150, 3); cvNamedWindow("src"); cvNamedWindow("dst_Smooth"); cvNamedWindow("dst_NoSmooth"); cvShowImage("src", src); cvShowImage("dst_Smooth", dst_Smooth); cvShowImage("dst_NoSmooth", dst_NoSmooth); cvWaitKey(0); cvReleaseImage(&src); cvReleaseImage(&dst_Smooth); cvReleaseImage(&dst_NoSmooth); cvDestroyAllWindows(); }