Question

Below is the code I have written to convolve an image with a x-direction Sobel mask. The function inputs a gray-scale image along with a kernel to be convolved with. However, the result I am getting is different compared to the result I get from the built-in conv2() function. Why is that? What am I doing wrong?

Here's my function's output:

enter image description here

Here's conv2() output:

enter image description here

Was it helpful?

Solution

You are computing the correlation. The 2D convolution is a 180 degree rotation (flip both axes) of the kernel.

h = rot90(h,2);

You won't notice the difference with a symmetric filter, like a Gaussian or an averaging kernel, but a derivative will be reversed in both directions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top