In opecv, how to implement get_gradientXY of CImg

139 views Asked by At

I am currently working on implementing the function of CImg, which is get_gradientXY, using the interface of OpenCV. And I found that cvSobel in OpenCV may have the same effect of get_gradientXY, but after experimenting on a sample graph, the output graph is totally different. I am stuck with this.

Here is my testing code:

imgCv.Load("1.jpg");
imgCimg.Load("1.jpg");

IplImage* pSrcImage = imgCv.GetOpenCVImpPtr();//get pointer of src graph
IplImage* grad_x = cvCreateImage(cvGetSize(pSrcImage), pSrcImage->depth, 3);
IplImage* grad_y = cvCreateImage(cvGetSize(pSrcImage), pSrcImage->depth, 3);
cvSobel(pSrcImage,grad_x,1,0,3);
cvSobel(pSrcImage,grad_y,0,1,3);

std::string filename1 = "gradcvx.jpg";
std::string filename2 = "gradcvy.jpg";
cvSaveImage(filename1.data(), grad_x);
cvSaveImage(filename2.data(), grad_y);
//*****


cimg_library::CImgList<unsigned char> gradImages =  imgCimg.GetCImg().get_gradientXY(2);

gradImages[0].save("gradcimgx.jpg");
gradImages[1].save("gradcimgy.jpg");

And gradcvx.jpg is totally different with gradcimgx.jpg. I am wondering why. Thank you.

1

There are 1 answers

0
Andrey  Smorodov On

You can try implement Sobel filter using CvFilter2d function and look if it correct, and experiment with kernel.

Here is usage example: http://feelmare.blogspot.ru/2013/01/cvfilter2d-example-source-code-various.html

You also can create two test images, one with horizontal lines other with vertical, apply filter and look at pixel values. Correct values you can compute by hand. Then verify if it correct in each case.