The algorithm: Each image is an MxN matrix of pixel values.
----------------
| x0 | x1 | x2 |
----------------
| x3 | x4 | x5 |
----------------
| x6 | x7 | x8 |
----------------
To compute the value of each pixel in the resulting image for a number of various image processing algorithms, the following format is used:
(w0 * x0) + (w1 * x1) + (w2 * x2) + (w3 * x3) + (w4 * x4) + (w5 * x5) + (w6 * x6) + (w7 * x7) + (w8 * x8)
x4' = ---------------------------------------------------------------------------------------------------------
9
The values w0,...,w8 are referred to as a mask.
----------------
| w0 | w1 | w2 |
----------------
| w3 | w4 | w5 |
----------------
| w6 | w7 | w8 |
----------------
The edge detection algorithm using the Sobel operators requires 2 masks
---------------- ----------------
| -1 | -2 | -1 | | -1 | 0 | 1 |
---------------- ----------------
| 0 | 0 | 0 | and | -2 | 0 | 2 |
---------------- ----------------
| 1 | 2 | 1 | | -1 | 0 | 1 |
---------------- ----------------
mask 1 mask 2
Each mask is performed on the original values of the image. Say the result of the value of a pixel after applying mask 1 is x4'' and the result of the value of a pixel after applying mask 2 is x4'''. Then the value of x4' is the addition of the absolute values of x4'' and x4''':
x4' = |x4''| + |x4'''|
How do you handle the border values? Just put a border of 0's around the image(also known as ghost cells). More about this will be presented in discussion.