How do I compute the gradient vector of pixels in an image? I'm trying to find the curvature of the features in an image and I was advised to calculate the gradient vector of pixels. So if the matrix below are the values from a grayscale image, how would I go about calculating the gradient vector for the pixel with the value '99'?
21 20 22 24 18 11 23
21 20 22 24 18 11 23
21 20 22 24 18 11 23
21 20 22 99 18 11 23
21 20 22 24 18 11 23
21 20 22 24 18 11 23
21 20 22 24 18 11 23

Apologies for asking such an open ended question, I've never done much maths and am not sure how to start tackling this.

The theoretical thing you may want to read up on is convolution and especially discrete convolution.

Since there already are practical approaches in a few computer languages I might as well add one that will work in Matlab & GNU Octave. We start out by feeding in our image. It is typed in as a matrix:
lImage = [21,20,22,24,18,11,23;
          21,20,22,24,18,11,23;
          21,20,22,24,18,11,23;
          21,20,22,99,18,11,23;
          21,20,22,24,18,11,23;
          21,20,22,24,18,11,23;
          21,20,22,24,18,11,23];

Then the command "conv2" creates a 2 dimensional convolution, first we can do one in the x direction by feeding it a row vector with the [1,0,-1] filter:
dx = conv2(lImage,[1,0,-1],'valid')

which gives us the output:
dx =

   1    4   -4  -13    5
   1    4   -4  -13    5
   1    4   -4  -13    5
   1   79   -4  -88    5
   1    4   -4  -13    5
   1    4   -4  -13    5
   1    4   -4  -13    5 

and the y direction we can easily do by just applying a transpose (denoted by ') on the x filter row vector:
dy = conv2(lImage,[1,0,-1]','valid')

gives us the output:
dy= 

   0    0    0    0    0    0    0
   0    0    0   75    0    0    0
   0    0    0    0    0    0    0
   0    0    0  -75    0    0    0
   0    0    0    0    0    0    0

