Image Enhancement (Spatial Filtering ) Dr. Samir H. Abdul-Jauwad Electrical Engineering Department College o Engineering Sciences King Fahd University o Petroleum & Minerals Dhahran Saudi Arabia samara@kupm.edu.sa
Contents In this lecture we will look at more spatial iltering techniques Spatial iltering reresher Sharpening ilters 1 st derivative ilters nd derivative ilters Combining iltering techniques
Spatial Filtering Reresher Origin Simple 3*3 Neighbourhood e x 3*3 Filter y Image (x, y) a b c d e g h i Original Image Pixels * r s t u v w x y z Filter e processed = v*e + r*a + s*b + t*c + u*d u + w* w + x*g + y*h + z*i Th b i t d i l i th The above is repeated or every pixel in the original image to generate the smoothed image
Sharpening Spatial Filters Previously we have looked at smoothing ilters which remove ine detail Sharpening spatial ilters seek to highlight ine detail Remove blurring rom images Highlight ht edges Sharpening ilters are based on spatial dierentiation
Spatial Dierentiation Dierentiation measures the rate o change o a unction Let s consider a simple 1 dimensional example
Spatial Dierentiation A B
1 st Derivative The ormula or the 1 st derivative o a unction is as ollows: x ( x 1) ( x ) It s just the dierence between subsequent values and measures the rate o change o the unction
1 st Derivative (cont ) 8 7 6 5 4 3 1 0 5 5 4 3 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7 0-1 -1-1 -1 0 0 6-6 0 0 0 1 - -1 0 0 0 7 0 0 0 8 6 4 0 - -4-6 -8
nd Derivative The ormula or the nd derivative o a unction is as ollows: ( x 1) ( x 1) ( x ) x Simply takes into account the values both beore and ater the current value
nd Derivative (cont ) 8 7 6 5 4 3 1 0 5 5 4 3 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7-1 0 0 0 0 1 0 6-1 6 0 0 1 1-4 1 1 0 0 7-7 0 0 10 5 0-5 -10-15
Using Second Derivatives For Image Enhancement The nd derivative is more useul or image enhancement than the 1 st derivative Stronger response to ine detail Simpler implementation We will come back to the 1 st order derivative later on The irst sharpening ilter we will look at is the Laplacian Isotropic One o the simplest sharpening ilters We will look at a digital implementation
The Laplacian The Laplacian The Laplacian is deined as ollows: y x where the partial 1 st order derivative in the x direction is deined as ollows: y x ), ( ) 1, ( ) 1, ( y x y x y x and in the y direction as ollows: x ), ( 1), ( 1), ( y x y x y x y
The Laplacian (cont ) So, the Laplacian can be given as ollows: [ ( x 1, y) ( x 1, y) ( x, y 1) ( x, y 1)] 4 ( x, y) We can easily build a ilter based on this 0 1 0 1-4 1 0 1 0
The Laplacian (cont ) Applying the Laplacian to an image we get a new image that highlights edges and other discontinuities Original Laplacian Laplacian Image Filtered Image Filtered Image Scaled or Display
But That Is Not Very Enhanced! The result o a Laplacian iltering is not an enhanced image We have to do more work in order to get our inal image Subtract the Laplacian result rom the original image to generate our inal sharpened enhanced image Laplacian Filtered Image Scaled or Display g ( x, y ) ( x, y )
Laplacian Image Enhancement - = Original Image Laplacian Filtered Image Sharpened Image In the inal sharpened image edges and ine detail are much more obvious
Laplacian Image Enhancement
Simpliied Image Enhancement The entire enhancement can be combined into a single iltering operation g ( x, y ) ( x, y ) ( x, y) [ ( x 1, y) ( x 1, y) ( x, y 1) ( x, y 4 ( x, y )] 1) 5 ( x, y) ( x 1, y) ( x 1, y) ( x, y 1) ( x, y 1)
Simpliied Image Enhancement (cont ) This gives us a new ilter which does the whole job or us in one step 0-1 0-1 5-1 0-1 0
Simpliied Image Enhancement (cont )
Variants On The Simple Laplacian There are lots o slightly dierent versions o the Laplacian that can be used: 0 1 0 1 1 1 1-4 1 Simple Laplacian 1-8 1 0 1 0 1 1 1 Variant o Laplacian -1-1 -1-1 9-1 -1-1 -1
Simple Convolution Tool In Java A great tool or testing out dierent ilters From the book Image Processing tools in Java Available rom webct later on today Available rom webct later on today To launch: java ConvolutionTool Moon.jpg
1 st Derivative Filtering Implementing 1 st derivative ilters is diicult in practice For a unction (x, y) the gradient o at coordinates (x, y) is given as the column vector: G x G y x y
1 st Derivative Filtering (cont ) The magnitude o this vector is given by: mag( ) 1 G G x G y x y For practical reasons this can be simpliied as: G x G y 1
1 st Derivative Filtering (cont ) There is some debate as to how best to calculate these gradients but we will use: z z z z z z 7 8 9 1 z z z z z z 3 6 9 1 which is based on these coordinates 4 3 7 z 1 z z 3 z 4 z 5 z 6 z 7 z 8 z 9
Sobel Operators Based on the previous equations we can derive the Sobel Operators -1 - -1-1 0 1 0 0 0-0 1 1-1 0 1 To ilter an image it is iltered using both operators the results o which are added together
Sobel Example An image o a contact lens which is enhanced in order to make deects (at our and ive o clock in the image) more obvious Sobel ilters are typically used or edge detection
st & nd Derivatives 1 st Comparing the 1 st and nd derivatives we can conclude the ollowing: 1 st order derivatives generally produce thicker edges nd order derivatives have a stronger response to ine detail e.g. thin lines 1 st order derivatives have stronger response to grey level step nd order derivatives produce a double response at step changes in grey level
Summary In this lecture we looked at: Sharpening ilters 1 st derivative ilters nd derivative ilters Combining iltering techniques
Combining Spatial Enhancement Methods Successul image enhancement is typically not achieved using a single operation Rather we combine a range o techniques in order to achieve a inal result This example will ocus on enhancing the bone scan to the right gt
Combining Spatial Enhancement Methods (cont ) (a) Laplacian ilter o bone scan (a) (b) Sharpened version o bone scan achieved (c) by subtracting (a) and (b) Sobel ilter o bone scan (a) (d)
Combining Spatial Enhancement Methods The product o (c) and (e) which will be used as a mask (e) (cont ) Sharpened image which is sum o (a) and () () Result o applying a power-law trans. to (g) (g) (h) Image (d) smoothed with a 5*5 averaging ilter
Combining Spatial Enhancement Methods (cont ) Compare the original and inal images