Sobel Filter Rad PDF
Sobel Filter Rad PDF
Sobel Filter Rad PDF
1. Introduction
Spatial feature manipulations are the processes which help to emphasize or deemphasize data
of various spatial frequencies. The term spatial frequency represents the tonal variations in
the images such that higher values indicate rough tonal variations whereas lower values
indicate smoother variations in the tone.
Spatial feature manipulations are generally local operations where the pixel values in the
original image are changed with respect to the gray levels of the neighboring pixels. It may
be applied to either spatial domain or frequency domain. Filtering techniques and the edge
enhancement techniques are some of the commonly used local operations for image
enhancement.
This lecture explains the mechanics of filtering and edge enhancement as applied to the
remote sensing satellite images.
2. Filtering Techniques
If a vertical or horizontal section is taken across a digital image and the image values are
plotted against distance, a complex curve is produced. An examination of this curve would
show sections where the gradients are low (corresponding to smooth tonal variations on the
image) and sections where the gradients are high (locations where the digital numbers change
by large amounts over short distances). Filtering is the process by which the tonal variations
in an image, in selected ranges or frequencies of the pixel values, are enhanced or suppressed.
Or in other words, filtering is the process that selectively enhances or suppresses particular
wavelengths or pixel DN values within an image.
Two widely used approaches to digitally filter images are convolution filtering in the spatial
domain and Fourier analysis in the frequency domain. This lecture explains the filtering
techniques with special reference only to the spatial domain.
A filter is a regular array or matrix of numbers which, using simple arithmetic operations,
allows the formation of a new image by assigning new pixel values depending on the results
of the arithmetic operations.
Consider the pixel having value e. A 3x3 window is considered in this case. The 8 neighbors
of the 3x3 window are marked in the figure. The figure also shows the corresponding 3x3
filter and the filter coefficients marked in it. The filter is applied to the neighborhood window
or the filter mask, and the modified pixel value ep is estimated. When the filter is applied to
the original image, this ep replaces the original value e.
The mechanics of the spatial filtering involves the movement of the filter mask over the
image and calculation of the modified pixel value at the center of the filter mask at every
location of the filter. Thus values of all the pixels are modified. When the spatial filter is
applied to the image, the ep values are estimated by using some pre-defined relationship using
the filter coefficients and the pixel values in the neighborhood or filter mask selected.
Convolution filter is a good example.
Filtering in the spatial domain manipulates the original pixel DN values. On the other hand,
frequency domain filtering techniques used the Fourier analysis to first transform the image
into the frequency domain and the filtering is performed on the transformed image, which is
the plot of frequencies at every pixel. The filter application in the frequency domain thus
gives frequency enhanced image.
Convolution filter is one of the most commonly used filters in image enhancement in the
spatial domain. In convolution filter, the filter mask is called convolution mask or
convolution kernel. The convolution kernels are square in shape and are generally of odd
number of pixels in size viz., 3x3, 5x5, 7x7 etc.
The kernel is moved over the input image for each pixel. A linear transformation function
involving the kernel coefficients and the pixel values in the neighborhood selected is used to
derive the modified DN of the pixel at the centre of the kernel, in the output image. Each
coefficient in the kernel is multiplied by the corresponding DN in the input image, and
averaged to derive the modified DN value of the centre pixel.
For example, the filter shown in Fig. 1 is a convolution filter of kernel size 3x3. DN value of
the centre pixel in the input image is e. The modified DN value is obtained as given below.
Based on the elements used in the matrix and the procedure used for calculating the new
digital number, different digital filters are developed for different purposes. Using different
kernels, different type of enhancement can be achieved. For example, high pass and low pass
filters are special types of convolution filters, which emphasize the high frequency and low
frequency features, respectively.
Low pass filters are also called averaging filters as the filter output is the average pixel value
of all the pixels in the neighborhood. When such filter is applied on an image, it will replace
every pixel with the average of the surrounding pixel values. Thus, the low frequency values
in the image are highlighted after filtering. Low pass filter reduces the effects of noise
component of an image.
High pass filter, on the other hand, enhances the high frequency values in an image.
Accordingly, in the resulting image, low frequency values are de-emphasized.
Directional gradient filters help to highlight the features oriented in any specific direction.
For example: 30oNW and 45o NE. They are particularly useful in detecting and enhancing
linear features with a specific orientation.
Emboss filter when applied to an image, highlights the features that are having gradient in the
specified direction.
Prewitt gradient and Sobel gradients are used to estimate the digital gradient in an image, and
are useful for edge detection. The kernels of these filters when moved over an image
highlight the higher gradients corresponding to edges and make the lower values smooth.
Laplace filter is also useful in edge enhancement. It helps to detect sharp changes in the pixel
values and hence enhances fine edges.
In Fig. 3 image enhancement obtained using high pass and low pass filter kernels are
compared. ASTER Global DEM of 30m resolution is used as the input image.
In Fig.4 the input image is compared with that obtained after the application of NW
embossed filter.
Fig 5(a) shows the original input image. The NW emboss filtered output is combined with the
input data. This operation helps to retain much of the information from the input image,
however with enhanced edges as shown in Fig. 5(b).
Fig. 6 shows the images enhanced using Sobel gradient and Laplace filter. Sobel filter
enhanced the higher values, whereas the lower values are compressed. Laplace filter on the
other hand, enhances not only the high values, but edges in all orientations are also enhanced.
(a) (b)
(c) (d)
Fig. 3 (a) Input image : ASTER GDEM (b) 3x3 low pass filtered image (c ) 11x11 low pass
filtered image and (d) 3x3 high pass filtered image
Gradients in the
NW direction are
highlighted
(a) (b)
Fig. 4 (a) Original image: ASTER GDEM (b) Image filtered using NW emboss filter
(a) (b)
Fig.5 (a) original image (b) Combination of original image and NW emboss filtered image
(a) (b)
It may be noted that filtering decreases the size of the original image depending on the kernel
size. In the case of 3 x 3 digital filter, there won’t be any filtered values for the pixels in first
row, last row, first column and last column, as these pixels cannot become central pixels for
any placement of 3 x 3 digital filter. Thus the filtered image from a 3 x 3 kernel will not
contain first row, last row, first column and last column of the original image.
3. Edge enhancement
Edges in the images are generally formed by long linear features such as ridges, rivers, roads,
railways, canals, folds and faults. Such linear features (edges) are important to geologists and
Civil Engineers. Some linear features occur as narrow lines, whereas some edges are marked
by pronounced differences that may be difficult to be recognized. Such narrow linear features
in the image can be enhanced using appropriate filtering techniques.
Fig. 7 (a) shows a part of IRS LISS III Band 4 (Near Infrared) data showing a portion of
Uttara Kannada district in Karnataka state, India. The image shows a river and the Arabian
Sea on the left. Fig.7 (b) shows the edges extracted from the image. Linear features such as
shore line and the river banks are extracted using the edge enhancement and edge detection
algorithms.
(a)
(b)
Fig. 7 (a) IRS LISS-III Band 4 image (b) Edges detected from the image using the digital
edge detection algorithm
Digital filters used for edge enhancement in images are of two broad categories:
Directional filters
Non-directional filters
Directional filters will enhance linear features which are having specified orientation (say
those oriented to 300 North) whereas non-directional filters will enhance linear features in
almost all orientations.
Pewitt gradient, Sobel, Canny and Lapalaican filters are some of the examples of non-
directional filters.
This section explains directional filter and the Laplacian non-directional filter in detail
Directional filter will enhance linear features with a specific orientation (direction). Direction
in which the edges are to be enhanced is specified in degrees with respect to North. Angles
within the North-East quadrant are considered with negative sign and those falling in the
North-West quadrant are considered with positive sign (Fig. 8).
Fig.8 Concept of orientation angle of the linear features as used in directional filter
Directional filters consist of two kernels of size 3x3 pixels, which are referred as left and
right kernels. Both left and right kernels are moved over the original image and the pixel
values are multiplied using the kernel coefficients. The values obtained for the nine pixels
within the filter mask are added up for each kernel separately. The value added up for the
right kernel is multiplied by Sin(A), where A is the angle specified. Similarly, the value
added up for the left kernel is multiplied by Cos(A). The resulting two kernel values are
summed up to obtain the directional filter value.
In the original image, if there is any sharp gradient between the pixels in the specified
direction, the resultant directional filter would show the maximum absolute pixel value for
the corresponding pixels, and thereby highlight the edges. The directional filter gives
negative values if the feature is aligned in the NE direction and positive values if the feature
is aligned in the NW direction.
For example, Fig.9 shows the application of a directional filter (Fig. 9.a) to a hypothetical
sample data (Fig. 9.b). The data shows a sharp gradient from pixel value 50 to 45 aligned
approximately at 45 degrees in the NE direction (angle A = - 45o).
The right kernel is first applied to the data and the resulting 9 values are summed up. For the
3x3 window marked in the figure, the resulting value is 10. The left kernel is then applied to
the image. For the same 3x3 window, the resultant value is obtained as -10.
The value obtained from the right kernel is multiplied with the sine of the angle [sin (- 45o) =
-0.71] and that obtained from the left kernel is multiplied with the cosine of the angle [cos (-
45o) = 0.71] and both are added up. Thus for the pixel at the center of the selected window,
the kernel value is obtained as -14. This procedure is repeated for all the pixels in the input
data. The resulting kernel values are shown in Fig. 9(c). Absolute values of the kernel values
are the maximum (14) along the line where there is a sharp change in the pixel values. Thus
the edge of the linear feature can be easily identified.
The kernel values are then added to the original data to generate the filtered output, which is
also shown in the Fig. 9(d).
Contrast ratio of the lineament in the original data set is 50/45 = 1.11. Application of the
directional filter increases the contrast ratio along the linear features in the specified
direction. Thus in the filtered output the contrast ratio is increased 50/31 = 1.61. Thus, in this
example, the contrast along the lineament has been enhanced 45 percent [100*(1.61-
1.11)/1.11 = 45].
-1 0 1 1 1 1
Cos A * -1 0 1 + Sin A * 0 0 0
-1 0 1 -1 -1 -1
a. Directional Filter
50 50 50 50 50 50
50 50 50 50 50 45
50 50 50 50 45 45
50 50 50 45 45 45
50 50 45 45 45 45
50 45 45 45 45 45
b. Original Data
0 0 0 0 -7 -14 50 50 50 50 43 36
0 0 0 -7 -14 -14 50 50 50 43 36 31
0 0 -7 -14 -14 -7 50 50 43 36 31 38
0 -7 -14 -14 -7 0 50 43 36 31 38 45
-7 -14 -14 -7 0 0 43 36 31 38 45 45
-14 -14 -7 0 0 0 36 31 38 45 45 45
The directional filter also enhances the linear features in directions other than the specified
direction. In this example the filter passing through the N45oW direction also enhances linear
features that tend obliquely to the direction of filter movement. As a result, many additional
edges of diverse orientations get enhanced.
Fig. 10 (a) shows a small area from Landsat ETM+ band-5 image. A linear feature with NW
orientation, a river, can be observed in the image. Fig.10 (b) shows the filtered image
obtained after applying the right diagonal edge enhancement filter to the original image. The
edges formed by the main river are highlighted in the right diagonal edge enhancement. Fig
10 (c) shows the left diagonal edge enhanced output of the same image. The main river
channel which is oriented in the NW direction is not emphasized in the filtered image. On the
other hand, other linear features that have orientation mainly in the NE direction are
highlighted in this image.
Horizontal edge enhanced output is also shown in Fig 10 (d)
(a) (b)
(c) (d)
Fig. 10 (a) Landsat ETM+ Band-5 image and the output of (b) right diagonal edge
enhancement (c ) left diagonal edge enhancement (d) horizontal edge enhancement
Linear features in an image are identified using the contrast between the pixels on either side
of it. Contrast between the pixels varies with the difference in the pixel values between them.
For example, in Table 1 the contrast between the pixels (x+1) and x depends on the
difference in the pixel values ax+1 and ax, which is the first derivative of the pixel values. For
the sample data, pixels values (a) and the 1st and 2nd derivatives of the pixel values are shown
in Table 1.
A first order derivative simply shows the difference in the pixel value for adjacent pixels. In
Table 1, the first order derivative is found less capable of highlighting the edges and the noise
in the pixel 9. On the other hand, second order derivative shows the difference in the first
derivative and is better capable of identifying the thin linear features and noises in the image.
As seen from Table 1, the second derivative gives sharper contrast along the edges as shown
by the higher magnitudes along pixels 2 and 6. It also gives very high values for the pixels
corresponding to the noises in the data (Pixel 9).
Table 1. Sample data showing the application of first and second order derivatives in edge
enhancement
Laplacian filter is a non-directional filter based on the second spatial derivative of the pixel
values.
The second order derivative in the x and y direction may be represented as given in Fig. 11
and Eq. 1-3.
ax,y+1
ax,y-1
2a
a x 1 a x 1 2a x (1)
2 x2
2a
a y 1 a y 1 2a y (2)
2 y2
2a 2a
a
2
a x 1, y a x 1, y a x , y 1 a x , y 1 4a x , y (3)
2 x2 2 y2
This equation is implemented using a kernel with -4 at the center, and 1 at the 4 adjacent
directions as shown in Fig 12.
0 1 0
1 -4 1
0 1 0
For example, consider the application of the above mentioned Laplace filter to a sample data
given in Fig.13 (Source: http://www.ciesin.org/docs/005-477/005-477.html). Fig.13 (a)
shows the Laplace filter kernel and the sample data. Profile of the pixel values along the
section AB is shown in Fig. 13 (c). Contrast ratio along the edges is only 1.14 (40/35).
Fig.13(b) shows the filtered data set obtained using Laplace filter. The contrast ratio has been
increased to 45/30 = 1.5 (31% increase).
Fig. 14 compares the Landsat ETM+ Band-5 image with the edge enhanced image obtained
after applying the Laplace filter of kernel shown in Fig.12. As compared to the images in Fig.
10, edges in all important directions are enhanced by applying the Laplace filter.
Fig. 14 (a) Landsat ETM+ Band-5 image and (b) Edge enhanced image using Laplace filter
Having considered the variation in the 4 adjacent directions, the kernel shown in Fig.12 gives
isotropic results for rotation in 90o increments.
The 4 diagonals can also be incorporated in the second derivative by adding two more terms
to Eq.3, for the diagonal corrections. The resultant kernel can be represented as shown in the
Fig. 15
1 1 1
1 -8 1
1 1 1
Fig. 15 Laplace filter kernel for isotropic results for rotation in multiples of 45o
Having incorporated the corrections in the 8 neighboring directions, the kernel gives isotropic
results for all rotations in 45o increments. Due to this property, the Laplacian filters are
considered to be highly effective in detecting the edges irrespective of the orientation of the
lineament.
During edge enhancement using Laplacian filter, the kernel is placed over 3x3 array of
original pixels and each pixel is multiplied by the corresponding value in the kernel. The nine
resulting values are summed and resultant kernel value is combined with the central pixel of
3x3 array. This number replaces the original DN of central pixel and the process is repeated
for all the pixels in the input image.
Laplacian filter will enhance edges in all the directions excepting those in the direction of the
movement of the filter (i.e., linear features with east-west orientation will not get enhanced).