# Compute the Second Order Derivative of Digital Image with Finite Differences

I was looking for how to compute second order derivative of an image and came across the question kernels to Compute Second Order Derivative of Digital Image. In the top voted answer, it gives an example to get $$3\times 3$$ kernel $$I_{xx}$$ and $$I_{xy}$$. The 1st order derivative filter is defined as $$\left( \begin{array}{cc} -1 & 1 \\ -1 & 1 \\ \end{array} \right)$$

Then

$$I_{xx} = I_x \cdot I_x = \left( \begin{array}{cc} -1 & 1 \\ -1 & 1 \\ \end{array} \right)\cdot\left( \begin{array}{cc} -1 & 1 \\ -1 & 1 \\ \end{array} \right)=\left( \begin{array}{ccc} 1 & -2 & 1 \\ 2 & -4 & 2 \\ 1 & -2 & 1 \\ \end{array} \right)$$

and

$$I_{xy} = I_y \cdot I_x = \left( \begin{array}{cc} -1 & -1 \\ 1 & 1 \\ \end{array} \right)\cdot\left( \begin{array}{cc} -1 & 1 \\ -1 & 1 \\ \end{array} \right)=\left( \begin{array}{ccc} 1 & 0 & -1 \\ 0 & 0 & 0 \\ -1 & 0 & 1 \\ \end{array} \right)$$

The computation of $$I_{xx}$$ makes sense to me, however, for $$I_{xy}$$, shouldn't it be defined as below?

$$I_{xy} = I_x \cdot I_y = \left( \begin{array}{cc} -1 & 1 \\ -1 & 1 \\ \end{array} \right)\cdot\left( \begin{array}{cc} -1 & -1 \\ 1 & 1 \\ \end{array} \right)=\left( \begin{array}{ccc} -1 & 0 & 1 \\ 0 & 0 & 0 \\ 1 & 0 & -1 \\ \end{array} \right)$$

Pay attention that convolution mean flipping the kernel both on the x and y axis.
Hence the first element is a multiplication of $$-1 \cdot -1$$ which yields $$1$$ as in the answer in the original post.

Pay attention that this is a discrete approximation of the gradient based on Finite Differences. This specific one is based on the Sobel 1st derivative filter.
In Finite Differences Coefficients you may find more variations.
As usual, the longer the filter the better the accuracy of the approximation with longer tarnsients.

• Ah! I was only flipping the kernel on the x axis only... Actually there is no difference between (Iy * Ix) and (Ix * Iy). Thanks!
– ciel
Jan 12, 2021 at 6:15
• The longer it is means the longer its transient as well. Feb 19, 2021 at 6:56
• @David, You're correct. I will add that.
– Royi
Feb 19, 2021 at 6:59