i am try to make gradient filter which is
intfilter[filterHeight][filterWidth]{ -1,-1, -1, -1, 0, 1, 1, 1, 1 };
and the code is like below.
Mat gradient(Matdst, IplImage img) { Matnew_dst(256, 256, DataType<int>::type); uchardata; data= (uchar*)img->imageData;
intheight, width, i, j; height= img->height; width= img->width; IplImage*imgavg = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
if(img != 0){ cvSmooth(img, imgavg, CV_BLUR, 1);//3*3의 이웃 픽셀값의 평균 cvNamedWindow("AvgFilter", CV_WINDOW_AUTOSIZE); cvShowImage("AvgFilter", imgavg); }
for(i = 2; i < width-2; i++) { for(j = 2; j < height-2; j++) { new_dst.at<int>(i,j) = {(dst.at<int>(i-1, j-1))(filter[0][0])+(dst.at<int>(i-1,j))(filter[0][1])+ (dst.at<int>(i-1, j+1))(filter[0][2]) +(dst.at<int>(i , j-1))(filter[1][0]) + (dst.at<int>(i,j))(filter[1][1]) + (dst.at<int>(i, j+1))(filter[1][2]) +(dst.at<int>(i+1, j-1))(filter[2][0]) + (dst.at<int>(i+1,j))(filter[2][1]) + (dst.at<int>(i+1, j+1))*(filter[2][2])}; }//forj (height) }//fori (width)
IplImage*imgn; imgn= cvCreateImage(cvSize(512, 512), IPL_DEPTH_8U, 1); imgn->imageData= (char *)new_dst.data; cvShowImage("Hooooooo",imgn); returnnew_dst; }
so i got the result like this. the result of gradient filter that i made is the first pic.
i havent any idea that why the result comes out like this.
Here is my question. If you have any idea about that filter, please let me know.
Also I you can please advice me that what is wrong about my code.
Also, if there is any route that i can see the filter library which is served by opencv please let me know.
Thanks !