# How to perform Spatial derivative calculation?

I'm trying to solve the following question about "Harris Corner Detection".

Consider the following image:

As the first step of the "Harris Corner Detection", we should compute the derivatives using the differentiation kernels shown above. No normalization (division by 2) is needed.

What I did: $$I_{x}=\frac{\partial I(x,y)}{\partial x}=I(x+1,y)-I(x-1,y)=\begin{bmatrix}4 & 9 & 12\\ 8 & 11 & 14\\ 10 & 15 & 16 \end{bmatrix}-\begin{bmatrix}0 & 1 & 4\\ 0 & 5 & 7\\ 4 & 9 & 12 \end{bmatrix}=\begin{bmatrix}4 & 8 & 8\\ 8 & 6 & 7\\ 6 & 6 & 4 \end{bmatrix}$$ But the solution should be (source):

I'm a bit confused about spatial derivative calculation. I took the formula from here. What am I missing?

I quite don't get how to calculate: $$M=\sum_{x,y}w(x,y)\begin{bmatrix}I_{x}^{2} & I_{x}I_{y}\\ I_{x}I_{y} & I_{y}^{2} \end{bmatrix}$$ I'm also a bit confused about terminology. Is $$I_x$$ actually that matrix or is it some value? function?

Is it possible to show how can I calculate $$M$$ using the following formula I provided above?

• Your $I_x$ is actually moving in the $y$ axis (vertical axis) not the $x$ axis (horizontal axis). That will make the answer match the blue figures in the image.
– Peter K.
Mar 16 at 17:41

What you should do instead to calculate $$I_x$$:
\begin{align} I_{x}(x,y)&=\frac{\partial I(x,y)}{\partial x}\\ &=I(x+1,y)-I(x-1,y)\\ &= \begin{bmatrix}5& 7 & 11\\ 9 & 12 & 16\\ 11 & 14 & 16 \end{bmatrix}-\begin{bmatrix}1 & 0 & 5\\ 1 & 4 & 9\\ 3 & 8 & 11 \end{bmatrix}\\ &=\begin{bmatrix} \bf\color{blue} 4 & \bf\color{blue}7 & \bf\color{blue}6\\ \bf\color{blue}8 & \bf\color{blue}8 & \bf\color{blue}7\\ \bf\color{blue}8 & \bf\color{blue}6 & \bf\color{blue}5 \end{bmatrix} \end{align} which matches the expected output.
Checking on your source, it seems that $$M$$ is mis-transcribed:
Here, the $$W$$ is a window into the image, not a weighting as is written in the equation for $$M$$ in the original post. This just means that $$x$$ and $$y$$ are varied to capture the window and the sum of the four different items is computed.
To calculate this $$H$$, all you need is the $$I_x$$ above and the equivalent in the $$y$$ direction: \begin{align} I_{y}(x,y)&=\frac{\partial I(x,y)}{\partial y}\\ &=I(x,y+1)-I(x,y+1)\\ \end{align}