Sobel,LoG,Canny边缘提取算法的实现和比较
2013-02-13 18:36
447 查看
#include "stdafx.h" #include "cv_LoG.h" #include "highgui.h" #include "cv.h" /* opencv_core231d.lib opencv_highgui231d.lib opencv_imgproc231d.lib e:\\a_square.jpg */ #ifdef _DEBUG #define new DEBUG_NEW #endif CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; if(argc<2) { printf("Input Wrong!\n"); return 0; } IplImage *img; img=cvLoadImage(argv[1],0); IplImage *imgLoG,*img16S,*imgSobel,*imgSobelx,*imgSobely,*imgCanny; CvScalar mean; img16S=cvCreateImage(cvSize(img->width,img->height),IPL_DEPTH_16S,img->nChannels); imgLoG=cvCreateImage(cvSize(img->width,img->height),img->depth,img->nChannels); cvSmooth(img,img,CV_GAUSSIAN,3,3); //高斯模糊 cvLaplace(img,img16S,3); //拉普拉斯算子 cvConvertScaleAbs(img16S,imgLoG,1); //mean=cvAvg(imgLoG); //cvThreshold(imgLoG,imgLoG,mean.val[0],256,CV_THRESH_BINARY); imgSobel=cvCreateImage(cvSize(img->width,img->height),img->depth,img->nChannels); imgSobelx=cvCreateImage(cvSize(img->width,img->height),img->depth,img->nChannels); imgSobely=cvCreateImage(cvSize(img->width,img->height),img->depth,img->nChannels); cvSobel(img,img16S,1,0,3); cvConvertScaleAbs(img16S,imgSobelx,1); cvSobel(img,img16S,0,1,3); cvConvertScaleAbs(img16S,imgSobely,1); cvAdd(imgSobelx,imgSobely,imgSobel); //使用两个方向的梯度绝对值和近似梯度模 //mean=cvAvg(imgSobel); //cvThreshold(imgSobel,imgSobel,mean.val[0],256,CV_THRESH_BINARY); imgCanny=cvCreateImage(cvSize(img->width,img->height),img->depth,img->nChannels); cvCanny(img,imgCanny,150,50); cvSaveImage("E:\\EdgeImages\\img.jpg",img); cvSaveImage("E:\\EdgeImages\\imgLoG.jpg",imgLoG); cvSaveImage("E:\\EdgeImages\\imgSobel.jpg",imgSobel); cvSaveImage("E:\\EdgeImages\\imgCanny.jpg",imgCanny); cvNamedWindow("Original Image"); cvShowImage("Original Image",img); cvNamedWindow("LoG Image"); cvShowImage("LoG Image",imgLoG); cvNamedWindow("Sobel Image"); cvShowImage("Sobel Image",imgSobel); cvNamedWindow("Canny Image"); cvShowImage("Canny Image",imgCanny); cvWaitKey(0); cvReleaseImage(&img); cvReleaseImage(&imgLoG); cvReleaseImage(&imgSobel); cvReleaseImage(&imgCanny); cvReleaseImage(&imgSobelx); cvReleaseImage(&imgSobely); cvReleaseImage(&img16S); return 1; return nRetCode; }
结果:
相关文章推荐
- 图像sobel、laplacian、canny边缘检测算法基础实现
- 几种边缘检测算子的比较Roberts,Sobel,Prewitt,LOG,Canny
- Canny边缘检测算法原理及其VC实现详解(一)
- Canny边缘检测算法原理及其VC实现详解(二)
- Canny边缘检测算法原理及其VC实现详解(三)
- paper 82:边缘检测的各种微分算子比较(Sobel,Robert,Prewitt,Laplacian,Canny)
- 边缘检测的各种微分算子比较(Sobel,Robert,Prewitt,Laplacian,Canny)
- Canny边缘检测算法的实现
- Canny边缘检测算法的实现
- Canny边缘检测算法原理及其VC实现详解(一)
- Canny边缘检测算法原理及其VC实现详解(二)
- Canny边缘检测算法原理及其VC实现详解(一)
- Canny边缘检测算法原理及其VC实现详解(一)
- Matlab自己实现Sobel边缘提取和ROA边缘提取
- OpenCV之imgproc 模块. 图像处理(2)实现自己的线性滤波器 给图像添加边界 Sobel 导数 Laplace 算子 Canny 边缘检测
- [转载]边缘检测的各种微分算子比较(Sobel,Robert,Prewitt,Laplacian,Canny)
- Canny边缘检测算法原理及其VC实现详解(二)
- Canny边缘检测算法原理及其VC实现详解(二)
- Canny边缘检测算法原理及其VC实现详解(三)
- Canny边缘检测算法原理及其VC实现详解(一)