Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Image processing spatialfiltering

Image processing spatialfiltering

  1. 1. 1of19Digital Image ProcessingImage Enhancement-Spatial FilteringFrom:Digital Image Processing, Chapter 3Refael C. Gonzalez & Richard E. Woods
  2. 2. 2of19ContentsNext, we will look at spatial filteringtechniques:– What is spatial filtering?– Smoothing Spatial filters.– Sharpening Spatial Filters.– Combining Spatial Enhancement Methods
  3. 3. 3of19Neighbourhood OperationsNeighbourhood operations simply operateon a larger neighbourhood of pixels thanpoint operationsNeighbourhoods aremostly a rectanglearound a central pixelAny size rectangleand any shape filterare possibleOrigin xy Image f (x, y)(x, y)Neighbourhood
  4. 4. 4of19Neighbourhood OperationsFor each pixel in the origin image, theoutcome is written on the same location atthe target image.Origin xy Image f (x, y)(x, y)NeighbourhoodTargetOrigin
  5. 5. 5of19Simple Neighbourhood OperationsSimple neighbourhood operations example:– Min: Set the pixel value to the minimum inthe neighbourhood– Max: Set the pixel value to the maximum inthe neighbourhood
  6. 6. 6of19The Spatial Filtering Processj k lm n op q rOrigin xy Image f (x, y)eprocessed = n*e +j*a + k*b + l*c +m*d + o*f +p*g + q*h + r*iFilter (w)Simple 3*3Neighbourhoode 3*3 Filtera b cd e fg h iOriginal ImagePixels*The above is repeated for every pixel in theoriginal image to generate the filtered image
  7. 7. 7of19Spatial Filtering: Equation Form∑∑−= −=++=aasbbttysxftswyxg ),(),(),(Filtering can be givenin equation form asshown aboveNotations are basedon the image shownto the leftImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)
  8. 8. 8of19Smoothing Spatial FiltersOne of the simplest spatial filteringoperations we can perform is a smoothingoperation– Simply average all of the pixels in aneighbourhood around a central value– Especially usefulin removing noisefrom images– Also useful forhighlighting grossdetail1/91/91/91/91/91/91/91/91/9Simpleaveragingfilter
  9. 9. 9of19Smoothing Spatial Filtering1/91/91/91/91/91/91/91/91/9Origin xy Image f (x, y)e = 1/9*106 +1/9*104 + 1/9*100 + 1/9*108 +1/9*99 + 1/9*98 +1/9*95 + 1/9*90 + 1/9*85= 98.3333FilterSimple 3*3Neighbourhood1061049995100 1089890 851/91/91/91/91/91/91/91/91/93*3 SmoothingFilter104 100 10899 106 9895 90 85Original ImagePixels*The above is repeated for every pixel in theoriginal image to generate the smoothed image
  10. 10. 10of19Image Smoothing ExampleThe image at the top leftis an original image ofsize 500*500 pixelsThe subsequent imagesshow the image afterfiltering with an averagingfilter of increasing sizes– 3, 5, 9, 15 and 35Notice how detail beginsto disappearImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)
  11. 11. 11of19Image Smoothing ExampleImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)
  12. 12. 12of19Image Smoothing ExampleImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)
  13. 13. 13of19Image Smoothing ExampleImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)
  14. 14. 14of19Image Smoothing ExampleImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)
  15. 15. 15of19Image Smoothing ExampleImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)
  16. 16. 16of19Image Smoothing ExampleImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)
  17. 17. 17of19Weighted Smoothing FiltersMore effective smoothing filters can begenerated by allowing different pixels in theneighbourhood different weights in theaveraging function– Pixels closer to thecentral pixel are moreimportant– Often referred to as aweighted averaging1/162/161/162/164/162/161/162/161/16Weightedaveraging filter
  18. 18. 18of19Another Smoothing ExampleBy smoothing the original image we get ridof lots of the finer detail which leaves onlythe gross features for thresholdingImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)Original Image Smoothed Image Thresholded Image* Image taken from Hubble Space Telescope
  19. 19. 19of19Averaging Filter Vs. Median FilterExampleFiltering is often used to remove noise fromimagesSometimes a median filter works better thanan averaging filterOriginal ImageWith NoiseImage AfterAveraging FilterImage AfterMedian FilterImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)
  20. 20. 20of19Averaging Filter Vs. Median FilterExampleImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)Original
  21. 21. 21of19Averaging Filter Vs. Median FilterExampleImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)AveragingFilter
  22. 22. 22of19Averaging Filter Vs. Median FilterExampleImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)MedianFilter
  23. 23. 23of19Strange Things Happen At The Edges!Origin xy Image f (x, y)eeeeAt the edges of an image we are missingpixels to form a neighbourhoode ee
  24. 24. 24of19Strange Things Happen At The Edges!(cont…)There are a few approaches to dealing withmissing edge pixels:– Omit missing pixels• Only works with some filters• Can add extra code and slow down processing– Pad the image• Typically with either all white or all black pixels– Replicate border pixels– Truncate the image
  25. 25. 25of19Correlation & ConvolutionThe filtering we have been talking about sofar is referred to as correlation with the filteritself referred to as the correlation kernelConvolution is a similar operation, with justone subtle differenceFor symmetric filters it makes no differenceeprocessed = v*e +z*a + y*b + x*c +w*d + u*e +t*f + s*g + r*hr s tu v wx y zFiltera b cd e ef g hOriginal ImagePixels*
  26. 26. 26of19Sharpening Spatial FiltersPreviously we have looked at smoothingfilters which remove fine detailSharpening spatial filters seek to highlightfine detail– Remove blurring from images– Highlight edgesSharpening filters are based on spatialdifferentiation
  27. 27. 27of19Spatial DifferentiationDifferentiation measures the rate of change ofa functionLet’s consider a simple 1 dimensionalexampleImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)
  28. 28. 28of19Spatial DifferentiationImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)A B
  29. 29. 29of191stDerivativeThe formula for the 1stderivative of afunction is as follows:It’s just the difference between subsequentvalues and measures the rate of change ofthe function)()1( xfxfxf−+=∂∂
  30. 30. 30of191stDerivative (cont…)5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 70 -1 -1 -1 -1 0 0 6 -6 0 0 0 1 2 -2 -1 0 0 0 7 0 0 0f(x)f’(x)
  31. 31. 31of192ndDerivativeThe formula for the 2ndderivative of afunction is as follows:Simply takes into account the values bothbefore and after the current value)(2)1()1(22xfxfxfxf−−++=∂∂
  32. 32. 32of192ndDerivative (cont…)5 5 4 3 2 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 -12 6 0 0 1 1 -4 1 1 0 0 7 -7 0 0f(x)f’’(x)
  33. 33. 33of191stand 2ndDerivativef(x)f’(x)f’’(x)
  34. 34. 34of19Using Second Derivatives For ImageEnhancementThe 2ndderivative is more useful for imageenhancement than the 1stderivative– Stronger response to fine detail– Simpler implementation– We will come back to the 1storder derivativelater onThe first sharpening filter we will look at isthe Laplacian– Isotropic– One of the simplest sharpening filters– We will look at a digital implementation
  35. 35. 35of19The LaplacianThe Laplacian is defined as follows:where the partial 1storder derivative in the xdirection is defined as follows:and in the y direction as follows:yfxff 22222∂∂+∂∂=∇),(2),1(),1(22yxfyxfyxfxf−−++=∂∂),(2)1,()1,(22yxfyxfyxfyf−−++=∂∂
  36. 36. 36of19The Laplacian (cont…)So, the Laplacian can be given as follows:We can easily build a filter based on this),1(),1([2yxfyxff −++=∇)]1,()1,( −+++ yxfyxf),(4 yxf−0 1 01 -4 10 1 0
  37. 37. 37of19The Laplacian (cont…)Applying the Laplacian to an image we get anew image that highlights edges and otherdiscontinuitiesImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)OriginalImageLaplacianFiltered ImageLaplacianFiltered ImageScaled for Display
  38. 38. 38of19But That Is Not Very Enhanced!The result of a Laplacian filteringis not an enhanced imageWe have to do more work inorder to get our final imageSubtract the Laplacian resultfrom the original image togenerate our final sharpenedenhanced imageLaplacianFiltered ImageScaled for DisplayImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)fyxfyxg 2),(),( ∇−=
  39. 39. 39of19Laplacian Image EnhancementIn the final sharpened image edges and finedetail are much more obviousImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)- =OriginalImageLaplacianFiltered ImageSharpenedImage
  40. 40. 40of19Laplacian Image EnhancementImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)
  41. 41. 41of19Simplified Image EnhancementThe entire enhancement can be combinedinto a single filtering operation),1(),1([),( yxfyxfyxf −++−=)1,()1,( −+++ yxfyxf)],(4 yxf−fyxfyxg 2),(),( ∇−=),1(),1(),(5 yxfyxfyxf −−+−=)1,()1,( −−+− yxfyxf
  42. 42. 42of19Simplified Image Enhancement (cont…)This gives us a new filter which does thewhole job for us in one step0 -1 0-1 5 -10 -1 0ImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)
  43. 43. 43of19Simplified Image Enhancement (cont…)ImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)
  44. 44. 44of19Variants On The Simple LaplacianThere are lots of slightly different versions ofthe Laplacian that can be used:0 1 01 -4 10 1 01 1 11 -8 11 1 1-1 -1 -1-1 9 -1-1 -1 -1SimpleLaplacianVariant ofLaplacianImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)
  45. 45. 45of19Unsharp Mask & Highboost FilteringUsing sequence of linear spatial filters inorder to get Sharpening effect.-Blur- Subtract from original image- add resulting mask to original image
  46. 46. 46of19Highboost Filtering
  47. 47. 47of191stDerivative FilteringImplementing 1stderivative filters is difficult inpracticeFor a function f(x, y) the gradient of f atcoordinates (x, y) is given as the columnvector:∂∂∂∂==∇yfxfGGyxf
  48. 48. 48of191stDerivative Filtering (cont…)The magnitude of this vector is given by:For practical reasons this can be simplified as:)f(∇=∇ magf[ ] 2122yx GG +=2122∂∂+∂∂=yfxfyx GGf +≈∇
  49. 49. 49of191stDerivative Filtering (cont…)There is some debate as to how best tocalculate these gradients but we will use:which is based on these coordinates( ) ( )321987 22 zzzzzzf ++−++≈∇( ) ( )741963 22 zzzzzz ++−+++z1 z2 z3z4 z5 z6z7 z8 z9
  50. 50. 50of19Sobel OperatorsBased on the previous equations we canderive the Sobel OperatorsTo filter an image it is filtered using bothoperators the results of which are addedtogether-1 -2 -10 0 01 2 1-1 0 1-2 0 2-1 0 1
  51. 51. 51of19Sobel ExampleSobel filters are typically used for edgedetectionImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)An image of acontact lens whichis enhanced inorder to makedefects (at fourand five o’clock inthe image) moreobvious
  52. 52. 52of191st& 2ndDerivativesComparing the 1stand 2ndderivatives we canconclude the following:– 1storder derivatives generally produce thickeredges– 2ndorder derivatives have a stronger responseto fine detail e.g. thin lines– 1storder derivatives have stronger responseto grey level step– 2ndorder derivatives produce a doubleresponse at step changes in grey level
  53. 53. 53of19Combining Spatial EnhancementMethodsSuccessful imageenhancement is typicallynot achieved using a singleoperationRather we combine a rangeof techniques in order toachieve a final resultThis example will focus onenhancing the bone scan tothe rightImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)
  54. 54. 54of19Combining Spatial EnhancementMethods (cont…)ImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)Laplacian filter ofbone scan (a)Sharpened version ofbone scan achievedby subtracting (a)and (b) Sobel filter of bonescan (a)(a)(b)(c)(d)
  55. 55. 55of19Combining Spatial EnhancementMethods (cont…)ImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)The product of (c)and (e) which will beused as a maskSharpened imagewhich is sum of (a)and (f)Result of applying apower-law trans. to(g)(e)(f)(g)(h)Image (d) smoothed witha 5*5 averaging filter
  56. 56. 56of19Combining Spatial EnhancementMethods (cont…)Compare the original and final imagesImagestakenfromGonzalez&Woods,DigitalImageProcessing(2002)

    Be the first to comment

    Login to see the comments

  • mboilla

    Jul. 21, 2013
  • Hailstorm786110

    Jul. 13, 2014
  • ulkapatil7758

    Oct. 31, 2014
  • z0oom

    Jan. 3, 2017
  • NehaSahar

    Mar. 23, 2017
  • jemalayderus

    Dec. 24, 2017

Views

Total views

1,956

On Slideshare

0

From embeds

0

Number of embeds

5

Actions

Downloads

0

Shares

0

Comments

0

Likes

6

×