1
Lecture Outline Basics o Spatial Filtering Smoothing Spatial Filters Averaging ilters Order-Statistics ilters Sharpening Spatial Filters Laplacian ilters High-boost ilters Gradient Masks Combining Spatial Enhancement Methods
Spatial Domain Spatial Domain Operations procedures that operate directl on piels g = T[F] where is the input image g is the processed image T is an operator on deined over some neighborhood o 4
Mask / Filter Neighborhood o a point can be deined b using a square/rectangular commonl used or circular subimage area centered at mask or ilter The center o the subimage is moved rom piel to piel starting at the top let corner o the image 5
Spatial Filtering Use ilter can also be called as mask / kernel / template / window The values o a ilter subimage are reerred to as coeicients rather than piel intensities. Our ocus will be on masks o odd sizes e.g. 3X3 55. Can a ilter be o even size? 6
Spatial Filtering Process Simpl move the ilter mask rom point to point in an image At each point the response o the ilter at that point is calculated using a predeined relationship R = w z w z... = 1 mn i= i 1 w z i i w mn z mn Linear Filtering 7
Spatial Filtering Approaches Linear Filtering Non-linear Filtering Order-Statistics iltering Morphological iltering Adaptive Filtering 8
How Does Linear Filtering Work? 9
Linear Filtering Linear Filtering o an image o size MN b ilter b mask o size mn is given b the epression a g = s=a To generate a complete iltered image this equation must be applied or = 1... M-1 and = 1... N-1 Convolution process b t=b where a = m-1/ and b = n-1/ w s t s t 1
What Happens at the Borders? The mask alls outside the edge! Solutions? Ignore the edges The resultant image is smaller than the original Pad with zeros Introducing unwanted artiacts What else? 11
Smoothing Spatial Filters Use: For blurring images & noise reduction Blurring is used in preprocessing steps such as Removal o small details rom an image prior to object etraction Bridging o small gaps in lines or curves Noise Reduction can be accomplished b blurring with linear or non-linear ilters 1
Smoothing Linear Filters Output is simpl the average o the piels contained in the neighborhood o the ilter mask Also reerred to as averaging ilters or lowpass ilters eplained in uture lecture 13
Averaging Filter: An Intuitive Approach Replace each piel b the average o piels in a square window surrounding this piel 33 averaging ilter What happens i we use an averaging ilter with a larger window? 14
Eample: Appling 33 Averaging Filter Assume edges ignored thus resultant image is 33 15
More Eamples Original image size 55 piels Results o smoothing with averaging ilter masks o size n=3 5 9 15 35 respectivel order: let to right top to bottom 16
Eample: Space Imager 17
Smoothing Linear Filters Able to reduce sharp transitions in gra levels Random noise in the image Edges o objects in the image Smoothing can reduce noises desirable and blur edges undesirable 18
33 Smoothing Linear Filters bo ilter weighted average 19
Weighted Averaging Filter Instead o averaging all the piel values in the window give the closer-b piels higher weighting and ar-awa piels lower weighting Reduce value o coeicients as a unction o increasing distance rom the origin An attempt to reduce blurring in the smoothing process
1 General orm: Smoothing Mask Filter o size m n m and n odd = = = = = a a s b b t a a s b b t t s w t s t s w g Summation o all coeicients o the mask
Eample: Lena 'Smoothen'
Other Common Smoothing Filters Criteria or designing a smoothing ilter ws t unction as averaging a s=a b t=b w st =1 mean value is preserved Another popular smoothing ilter: Gaussian ilter 3
Order-Statistics Filters Non-linear ilters Response is based on ordering ranking the piels contained in the image area encompassed b the ilter Eample: Median ilter: Ma ilter: Min ilter: R=median z k k=1...n n R=ma z k k=1...n n R=min z k k=1...n n Note: n n is the size o the mask 4
Median Filters Replaces the value o a piel b the median o the gra levels in the speciied neighborhood o that piel Original value o the piel is included in the computation o the median Popularl used or certain tpes o random noise impulse noise salt and pepper noise Ecellent noise-reduction capabilities Less blurring eect that linear smoothing ilters o similar size Intuitivel how do the work? 5
Eample: Fighting Salt and Pepper Noise 6
Sharpening Spatial Filters Sharpening: to enhance line structures or other details in an image Sharpening Spatial Filters: To highlight ine detail or edges in an image To enhance and ocus on details that has been blurred either in error or as a natural eect o a particular method o image acquisition 7
Image Sharpening g = ± c Blur the original image Add the Laplacian 6
Blurring vs. Sharpening Blurring can be done in spatial domain b piel averaging in the neighborhood o a piel Since averaging is analogous to integration... Can we conclude that sharpening is accomplished b spatial dierentiation? 8
Derivative Operator The strength o the response o a derivative operator is proportional to the degree o discontinuit o the image at the point at which the operator is applied Image dierentiation Enhances edges and other discontinuities such as noise De-emphasizes area with slowl varing gra-level values 9
First-order Derivative A basic deinition o the irst-order derivative o a one-dimensional unction is the dierence = 1 3
Second-order Derivative Similarl the second-order derivative o a onedimensional unction is the dierence = 1 1 31
3 First & Second Derivatives o Consider an image unction o two variables we are dealing with partial derivatives along the two spatial aes. = = = Laplacian operator Gradient operator
33 Discrete orm o Laplacian From ield 1 1 = 1 1 = ] 4 1 1 1 1 [ =
Laplacian Mask The Laplacian mask contains the coeicients o the Laplacian operator second-order derivatives 34
Laplacian Mask witih Diagonal Terms This Laplacian mask is implemented dierentl b incorporating the diagonal directions. The center value is now -8 due to the total subtracted rom the dierence terms. 35
Other Implementations o Laplacian Masks These masks dierence in sign give the same result as the previous two masks. The dierence in sign must be kept in mind when combining add / subtract a Laplacian-iltered image with another image 36
Eect o Laplacian Operator Tends to produce images that have Graish edge lines and other discontinuities in brighter intensities all superimposed on a dark eatureless background To correct the eect o eatureless background Add the original and Laplacian-iltered image together Be careul with the Laplacian ilter used g = i the center coeicient o the Laplacian mask is negative i the center coeicient o the Laplacian mask is positive 37
Eample: Moon Images Image o the moon Laplacian-iltered image with 1 1 1 1-8 1 1 1 1 Laplacian image scaled or displa purposes Image enhanced sharpened b adding Laplacian-iltered image to the original image Note: let to right top to bottom 38
39 Simpliications To simpli the computation we can create a mask which do both operations Laplacian ilter and Addition o original image Composite Laplacian Mask 1] 1 1 1 [ 5 4 1] 1 1 1 [ = = g -1-1 5-1 -1
Composite Laplacian Mask 4
Composite Laplacian Mask Which composite mask normal Laplacian / Laplacian with diagonal terms can produce better image sharpening? -1-1 -1 5-1 -1 9-1 -1-1 41
4 Composite Laplacian Mask -1-1 9-1 -1-1 -1 5-1 -1 = g 1-1 -1 4-1 -1 = 1-1 -1 8-1 -1 =
Unsharp Masking A process used man ears in the publishing industr to sharpen images Sharpened image: Subtracting a blurred version o an image rom the image itsel s = sharpened image = original image blurred image 43
Unsharp Masking Can ou make sense o unsharp masking? 44
45 High-Boost Filtering High-boost Filtering: A urther generalization o unsharp masking A hb = 1 1 A A s hb = = A 1 where
High-Boost Filtering This general equation does not state eplicitl how the sharp image is obtained... I we choose to use Laplacian operator to sharpen the image we get hb = A 1 hb A = A s i the center coeicient o the Laplacian mask is negative i the center coeicient o the Laplacian mask is positive 46
High-Boost Filtering A 1 I A = 1 it becomes a standard Laplacian sharpening 47
Eample: High-Boost Filtering 48
Eample: Lena 'Sharpened' 49
5 First Derivatives: Gradient Operator First derivatives are implemented using the magnitude o the gradient = = G G 1 1 ] [ = = = G G mag The magnitude becomes nonlinear G G Approimation:
Gradient Mask On the basis o a irst-order derivative o a -D unction the simplest approimation o the gradient mask: G = = z8 z5 and G = z6 z5 1 [ G G ] = [ z8 z5 z6 z5 z 8 z5 z6 z5 ] 1 z 1 z z 3 z 4 z 5 z 6 z 7 z 8 z 9 51
Gradient Mask Roberts cross-gradient operators [1965] G = z9 z5 and G = z8 z6 z 1 z z 3 1 1 = [ G G ] = [ z9 z5 z8 z6 ] z 4 z 5 z 6 z z 7 z 8 z 9 9 z5 z8 z6 5
Sobel operators 33 Gradient Mask G G = = z z 7 3 z z 8 6 G G z z 9 9 z z 1 1 z z 4 z z 3 7 z 1 z z 3 z 4 z 5 z 6 z 7 z 8 z 9 The weight value is to achieve smoothing b giving more important to the center point 53
Eample: Gradient Filtering More on gradient masks will be covered under Edge Detection Image Segmentation 54
Gradient Mask The summation o coeicients in gradient masks equals indicating that the would give a response o in an area o constant gra level 55
Figure out! The summation o coeicients in a mask equals or both gradient operators 1 st derivative and Laplacian operators nd derivative The summation o coeicients in a smoothing mask equals 1 Wh??? 56
Separable Filters In D iltering some ilters can be implemented b successive application o two simpler ilters One horizontal ollowed b another vertical This can signiicantl lower the computational compleit B how much? For a mask o size n n Originall n multiplications and n 1 additions Ater separation n multiplications and n additions 57
Values Outside the Range? Linear iltering might bring the intensit outside the displa range Solutions? Clip values = 55 Scaling transormation g L = 55 g g H L i < i 55 i > 55 Transorm values in [g L g H ] to [ 55] 58
Eample: Combining Spatial Enhancement Methods Target: To sharpen the original image and bring out more skeletal detail Problems: Narrow dnamic range o gra level High noise content makes image diicult to enhance 59
Eample: Combining Spatial Enhancement Methods Solution: I. Laplacian to highlight ine details II.Gradient to enhance prominent edges III.Gra level transormation to increase the dnamic range o gra levels 6
Eample: Combining Spatial Enhancement Methods 61
Eample: Combining Spatial Enhancement Methods 6