Reputation: 144
I know that sobel filter to find gradient on x is 1/8 .* [-1 0 1;-2 0 2;-1 0 1].
So,Instead of using imgradientxy to get the gradients of x and y, I tried to use sobel filter directly using normxcorr2 to correlate the filter with the image. However, the results looks completely different as shown below.
Note: I first normalized the original image to range [-1,1] instead of [0,255]
I understand that normxcorr2 is correlating the kernel with the image, and if I use sobel filter on x as indicated above, then it should it give me similar result as using imgradientxy.
What is wrong in my understanding?
Sobel filter correlated with the image using normxcorr2:
Image 1: Sobel filter correlated with the image using normxcorr2
Gradient on x using imgradientxy:
Image 2: Gradient on x using imgradientxy
Upvotes: 0
Views: 233
Reputation: 3279
imgradientxy(I) calculate the gradient in X and Y directions using a convolution with the Sobel filter without normalizing each location the kernel runs on.
normxcorr2(I,template) normalize the template and the region under the template and only than calculates the correlation.
So if you want to implement imgradientxy your self use the following code
sobelX = [-1 0 1;-2 0 2;-1 0 1];
gradX = conv2(double(I),sobelX,'same');
Upvotes: 1