matlab – Calculates the normal direction from a pixel image

I'm trying to calculate the normal direction in a grayscale image using a pixel neighborhood like this.

Suppose I have a matrix

| 148 141 145 |
| 144 140 148 |
| 146 147 148 |

The normal direction I want to calculate is the difference in gray scale from the central pixel. if the difference in grayscale is greater than a value, the final normal direction of this plurality is a sum of the normal direction.

How to implement this method effectively in MATLAB?