Amir
Amir

Reputation: 11096

My function's output differs from conv2() output

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

Upvotes: 1

Views: 409

Answers (1)

chappjc
chappjc

Reputation: 30579

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.

Upvotes: 2

Related Questions