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).