Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

gradient filter

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.

image description

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.

image description

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 !

click to hide/show revision 2
No.2 Revision

gradient filter

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.

image description

Mat gradient(Matdst, IplImage img) *img) {
Matnew_dst(256, 256, DataType<int>::type);
uchardata;
uchar*data;
data= (uchar*)img->imageData;

(uchar*)img->imageData; intheight, width, i, j; height= img->height; width= img->width; IplImage*imgavg = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);

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])+ j-1))*(filter[0][0])+(dst.at<int>(i-1,j))*(filter[0][1])+ (dst.at<int>(i-1, j+1))(filter[0][2]) j+1))*(filter[0][2]) +(dst.at<int>(i , j-1))(filter[1][0]) + (dst.at<int>(i,j))(filter[1][1]) j-1))*(filter[1][0]) + (dst.at<int>(i,j))*(filter[1][1]) + (dst.at<int>(i, j+1))(filter[1][2]) j+1))*(filter[1][2]) +(dst.at<int>(i+1, j-1))(filter[2][0]) + (dst.at<int>(i+1,j))(filter[2][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)

(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.

image description

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 !