#include <cv.h>
#include <highgui.h>
#include <iostream>
using namespace std;
int main(int argc,constchar * argv[]) {
IplImage *pImage=NULL,*pImgSobelgray=NULL,*pImg8u=NULL,*pImg8uSmooth=NULL,*pImgColor=NULL,*pImgSobelcolor=NULL;
IplImage *pImgPlanes[3]={0,0,0};
IplImage *img=cvLoadImage("/Users/guofeng/Documents/sobelTest/test.bmp");
pImage=cvCloneImage(img);
pImg8u=cvCreateImage(cvGetSize(pImage),IPL_DEPTH_8U,1);
pImg8uSmooth=cvCreateImage(cvGetSize(pImage),IPL_DEPTH_8U,1);
cvCvtColor(pImage, pImg8u,CV_BGR2GRAY);
cvSmooth(pImg8u, pImg8uSmooth,CV_GAUSSIAN,3,0,0);
pImgSobelgray=cvCreateImage(cvGetSize(pImage),IPL_DEPTH_16S,1);
cvSobel(pImg8uSmooth,pImgSobelgray,0,1,3);
cvConvertScaleAbs(pImgSobelgray, pImg8u,1,0);
cvNamedWindow("img",1);
cvNamedWindow("gaussin",1);
cvNamedWindow("sobelgray",1);
cvShowImage("img", img);
cvShowImage("gaussin", pImg8uSmooth);
cvShowImage("sobelgray", pImg8u);
cvSaveImage("/Users/guofeng/Documents/sobelTest/sobelgray.jpg", pImg8u);
cvNamedWindow("laplace",1);
cvLaplace(pImg8uSmooth,pImgSobelgray,3);
cvConvertScaleAbs(pImgSobelgray, pImg8u,1,0);
cvShowImage("laplace", pImg8u);
cvSaveImage("/Users/guofeng/Documents/sobelTest/laplace.jpg", pImg8u);
cvCanny(pImg8uSmooth, pImg8u,50, 50);
cvNamedWindow("canny",1);
cvShowImage("canny", pImg8u);
cvSaveImage("/Users/guofeng/Documents/sobelTest/canny.jpg", pImg8u);
for(int i=0;i<3;i++)
pImgPlanes[i]=cvCreateImage(cvGetSize(pImage),IPL_DEPTH_8U,1);
pImgSobelcolor=cvCreateImage(cvGetSize(pImage),IPL_DEPTH_16S,1);
pImgColor=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U, img->nChannels);
cvCvtPixToPlane(pImage,pImgPlanes[0],pImgPlanes[1],pImgPlanes[2],0);
for(int i=0;i<3;i++)
{
cvSobel(pImgPlanes[i], pImgSobelcolor,0, 1,3);
cvConvertScaleAbs(pImgSobelcolor, pImgPlanes[i]);
}
cvCvtPlaneToPix(pImgPlanes[0],pImgPlanes[1],pImgPlanes[2],0,pImgColor);
cvNamedWindow("sobelcolor",1);
cvShowImage("sobelcolor", pImgColor);
cvSaveImage("/Users/guofeng/Documents/sobelTest/Sobelcolor.jpg", pImgColor);
cvWaitKey(0);
cvDestroyAllWindows();
cvReleaseImage(&pImgColor);
cvReleaseImage(&pImage);
cvReleaseImage(&pImgSobelcolor);
cvReleaseImage(&pImgSobelgray);
cvReleaseImage(&pImg8u);
cvReleaseImage(&pImg8uSmooth);
//cvReleaseImage(&pImgPlanes);
return0;
}