Digital Image Processing Lecture 6 (Enhancement) Bu-Ali Sina University Computer Engineering Dep. Fall 009
Outline Image Enhancement in Spatial Domain Spatial Filtering Smoothing Filters Median Filter Sharpening High Boost ilter Derivative ilter
Spatial Filtering Image enhancement in the spatial domain can be represented as: The transormation T maybe linear or nonlinear. We will mainly study linear operators T but will see one important nonlinear operation. How to speciy T I the operator T is linear and shit invariant (LSI), characterized by the point-spread sequence (PSS) h(m, n), then (recall convolution):
Spatial Filtering Origin x a b c r s t d e * u v w g h i x y z Simple 3*3 eighbourhood y Image (x, y) e 3*3 Filter Original Image Pixels Filter e processed = v*e + r*a + s*b + t*c + u*d + w* + x*g + y*h + z*i The above is repeated or every pixel in the original image to generate the smoothed image
Chapter 3: Image Enhancement (Spatial Filtering) Spatial Filtering I h(m, n) is a 3 by 3 mask given by :
Chapter 3: Image Enhancement (Spatial Filtering) Spatial Filtering- Smoothing Filters o Image smoothing reers to any image-to-image transormation designed to smooth or latten the image by reducing the rapid pixel-to-pixel variation in grayvalues. o Smoothing ilters are used or: o Blurring: This is usually a preprocessing step or removing small (unwanted) details beore extracting the relevant (large) object, bridging gaps in lines/curves, o oise reduction: Mitigate the eect o noise by linear or nonlinear operations. o Image smoothing by averaging (lowpass spatial iltering) o Smoothing is accomplished by applying an averaging mask. o An averaging mask is a mask with positive weights, which sum to 1. It computes a weighted average o the pixel values in a neighborhood. This operation is sometimes called neighborhood averaging.
Chapter 3: Image Enhancement (Spatial Filtering) Spatial Filtering- Smoothing Filters Some 3 x 3 averaging masks:
Chapter 3: Image Enhancement (Spatial Filtering) Spatial Filtering- Smoothing Filters This operation is equivalent to lowpass iltering. Example o Image Blurring
Chapter 3: Image Enhancement (Spatial Filtering) Spatial Filtering- Smoothing Filters
Chapter 3: Image Enhancement (Spatial Filtering) Spatial Filtering- Smoothing Filters Example o noise reduction :
Chapter 3: Image Enhancement (Spatial Filtering) Spatial Filtering- Median Filter The averaging ilter is best suited or noise whose distribution is Gaussian: The averaging ilter typically blurs edges and sharp details. The median ilter usually does a better job o preserving edges. Median ilter is particularly suited i the noise pattern exhibits strong (positive and negative) spikes. Example: salt and pepper noise. Median ilter is a nonlinear ilter, that also uses a mask. Each pixel is replaced by the median o the pixel values in a neighborhood o the given pixel. Suppose are the pixel values in a neighborhood o a given pixel with Then : Note: Median o a set o values is the center value, ater sorting. For example: I A = {0,1,,4,6,6,10,1,15}, then median(a) = 6.
Spatial Filtering- Median Filter
Chapter 3: Image Enhancement (Spatial Filtering) Spatial Filtering- Median Filter Example o noise reduction :
Chapter 3: Image Enhancement (Spatial Filtering) Spatial Filtering- Median Filter
Chapter 3: Image Enhancement (Spatial Filtering) Spatial Filtering- Median Filter
Spatial Filtering- Sharpening Filter To highlight ine detail or to enhance blurred detail. smoothing ~ integration sharpening ~ dierentiation Categories o sharpening ilters: Derivative operators Basic highpass spatial iltering High-boost iltering
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 8 7 6 5 4 3 1 0 8 6 4 0 - -4-6 -8 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
nd Derivative The ormula or the nd derivative o a unction is as ollows: x = ( x + 1) + ( x ( x) Simply takes into account the values both beore and ater the current value 1)
nd Derivative 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 One o the simplest sharpening ilters We will look at a digital implementation
The Laplacian The Laplacian is deined as ollows: where the partial 1 st order derivative in the x direction is deined as ollows: and in the y direction as ollows: y x + = ), ( ) 1, ( ) 1, ( y x y x y x x + + = ), ( 1), ( 1), ( y x y x y x y + + =
The Laplacian So, the Laplacian can be given as ollows: = [ ( x + 1, y) + ( x 1, y) We can easily build a ilter based on this + ( x, y + 1) + ( x, y 1)] 4 ( x, y) 0 1 0 1-4 1 0 1 0
The Laplacian Applying the Laplacian to an image we get a new image that highlights edges and other discontinuities Original Image Laplacian Filtered Image Laplacian 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 ) 1, ( ) 1, ( [ ), ( y x y x y x + + = 1), ( 1), ( + + + y x y x )], ( 4 y x y x y x g ), ( ), ( = ) 1, ( ) 1, ( ), ( 5 y x y x y x + = 1), ( 1), ( + y x y x
Simpliied Image Enhancement 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
Variants On The Simple Laplacian There are lots o slightly dierent versions o the Laplacian that can be used: 0 1 0 1-4 1 0 1 0 Simple Laplacian 1 1 1 1-8 1 1 1 1 Variant o Laplacian -1-1 -1-1 9-1 -1-1 -1
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 G x y = x y
1 st Derivative Filtering The magnitude o this vector is given by: For practical reasons this can be simpliied as: ( ) = mag [ ] 1 x G y G + = 1 + = y x G x G y +
1 st Derivative Filtering 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 0 0 0 1 1-1 0 1-0 -1 0 1 To ilter an image it is iltered using both operators the results o which are added together
Sobel Example Sobel ilters are typically used or edge detection 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
1st Derivative Filtering Chapter 3: Image Enhancement (Spatial Filtering) We may use the approximation : This can implemented using the masks: As ollows: Alternatively, we may use the approximation: This can implemented using the masks: As ollows:
Roberts cross-gradient operator Chapter 3: Image Enhancement (Spatial Filtering) The resulting masks are called Roberts cross-gradient operators. The Roberts operators and the Prewitt/Sobel operators (described later) are used or edge detection and are sometimes called edge detectors. Example: Roberts cross-gradient operator :
Prewitt operators Chapter 3: Image Enhancement (Spatial Filtering) Better approximations to the gradient can be obtained by: This can be implemented using the masks: as ollows: The resulting masks are called Prewitt operators.
Chapter Prewitt 3: Image operators Enhancement (Spatial Filtering)
1 st & nd Derivatives 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
Spatial Filtering- High-boost iltering This is a ilter whose output g is produced by subtracting a lowpass (blurred) version o rom an ampliied version o : This is also reerred to as unsharp masking. Observe that : For A >1, part o the original image is added back to the highpass iltered version o. The result is the original image with the edges enhanced relative to the original image.
Spatial Filtering- High-boost iltering
Chapter Spatial3: Filtering- Image Enhancement High-Boost (Spatial Filtering Filtering)
Chapter Spatial3: Filtering- Image Enhancement Derivative(Spatial ilter Filtering)
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
Combining Spatial Enhancement Methods (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) 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 Compare the original and inal images