Image Processing Reference
In-Depth Information
Sobel(pic,winsize):=
w2 floor
winsize
2
edge_mag
←
zero(pic)
edge_dir
←
zero(pic)
for x
∈
w2..cols(pic)-1-w2
for y
∈
w2..rows(pic)-1-w2
x_mag
←
Sobel_x(submatrix(pic,y-w2,y+w2,x-w2,x+w2))
y_mag
←
Sobel_y(submatrix(pic,y-w2,y+w2,x-w2,x+w2))
magnitude(x_mag, y_mag)
mag_normalise
edge_mag
y_x
←
floor
edge_dir
y,x
←
direction(x_mag,y_mag)
(edge_mag edge_dir)
Code 4.8
Generalised Sobel operator
shown in the edge magnitude image, Figure
4.11
(b). When this is thresholded at a suitable
value, many edge points are found, as shown in Figure
4.11
(c). Note that in areas of the
image where the brightness remains fairly constant, such as the cheek and shoulder, there
is little change which is reflected by low edge magnitude and few points in the thresholded
data.
(a) Original image
(b) Sobel edge magnitude
(c) Thresholded magnitude
Figure 4.11
Applying the Sobel operator
The Sobel edge direction data can be arranged to point in different ways, as can the
direction provided by the Prewitt operator. If the templates are inverted to be of the form
shown in Figure
4.12
, the edge direction will be inverted around both axes. If only one of
the templates is inverted, then the measured edge direction will be inverted about the
chosen axis.
This gives
four
possible directions for measurement of the edge direction provided by
the Sobel operator, two of which (for the templates of Figures
4.10
and
4.12
) are illustrated