The Sobel masks for edge detection
It is possible to combine more than one operation in a single mask. A good example is given by the Sobel masks for edge detection, which combine the vertical and horizontal differencing operations with some smoothing to reduce the effects of noise or very local texture.
The masks look like:
---------------- ----------------
| -1 | 0 | 1 | | -1 | -2 | -1 |
|----+----+----| |----+----+----|
| -2 | 0 | 2 | | 0 | 0 | 0 |
|----+----+----| |----+----+----|
| -1 | 0 | 1 | | 1 | 2 | 1 |
---------------- ----------------
The single values used in the simple differencers above are replaced by averages over 3 pixels, weighted towards the centre in each case. In addition, the positive and negative parts are separated by a one-pixel gap; by increasing the baseline for differencing this too has a smoothing effect, and it allows the mask to be more symmetrical, so that the results are "centred" in a way that is not true for the smaller difference operators.
You should now easily be able to set up the Sobel masks and look at their effects. Compare the outputs from the Sobel masks with the results of smoothing the image and then taking vertical or horizontal differences - the results should be similar, though not identical.