0
$\begingroup$

The image gradient is the rate of change over any given pixel of an image, either in the horizontal or vertical direction. An image can be thought of as a large matrix of values [0, 255]. A common horizontal matrix for taking an image gradient is [1, 0, -1], or the value to the left of our pixel minus the value to the right of our pixel.

I understand this conceptually, but in practice I'm not sure how to apply it to the edges of an image (eg the value to the left or the right of the pixel doesn't exist).

http://en.wikipedia.org/wiki/Image_gradient#Math

1 Answers 1

0

Check out the documentation for the matlab function 'imfilter'. The first box on that page has the title 'Boundary Options'. It list four options, for example: 'replicate' Input array values outside the bounds of the array are assumed to equal the nearest array border value.

This is a standard problem when filtering an image (and you are approximating the gradient with a filter), and there are many ways to deal with it that are more or less equally good.