MATLAB: MATLAB conv2 giving wrong answer as compare to manual with Valid

image processingMATLAB

When I use conv2 the 'valid' its gives negative answers.. like
A= 3 0 1 2 7 4
1 5 8 9 3 1
2 7 2 5 1 3
0 1 3 1 7 8
4 2 1 6 2 8
2 4 5 2 3 9
b= 1 0 -1
1 0 -1
1 0 -1
manually conv of A with b =
-5 -4 0 8
-10 -2 2 3
0 -2 -4 -7
-3 -2 – 3 -16
but MATLAB i get
5 4 0 -8
10 2 -2 -3
0 2 4 7
3 2 3 16
i cant understand the reason

Best Answer

You did not fliplr() the convolution kernel when you calculated by hand. MATLAB uses the convention that the convolution kernel is mirrored; this convention fits with the definition of integral convolution involving integral of f(tau)*g(t-tau) -- notice the implicit time reversal of g