Image Enhancement II: Neighborhood Operations Image Enhancement:Spatial Filtering Operation Idea: Use a mask to alter piel values according to local operation Aim: De)-Emphasize some spatial requencies in the image.
3 Overview o Spatial Filtering Local linear oprations on an image Input:,), Output: g,) g, ) w, ) w w, ) w 8, ) 9, ) Moving average We replace each piel with a weighted average o its neighborhood The weights are called the ilter kernel What are the weights or the average o a 33 neighborhood? bo ilter Source: D. Lowe
5 Spatial Filtering: Blurring Eample Averaging Mask: /9 6 Image Enhancement:Spatial Filtering Operation Local linear oprations on an image Input:,), Output: g,): Input Image g, ) w Mask 8, ) w w, ) w 9 Output Image, ), ) Usuall odd 3
Deining convolution Let be the image and g be the kernel. The output o convolving with g is denoted * g. g)[ m, n] k, l [ m k, n l] g[ k, l] Convention: kernel is lipped MATLAB: conv vs. ilter also imilter) Source: F. Durand Ke properties Linearit: ilter + ) = ilter ) + ilter ) Shit invariance: same behavior regardless o piel location: iltershit)) = shitilter)) Theoretical result: an linear shit-invariant operator can be represented as a convolution 4
g Important details What is the size o the output? MATLAB: ilterg,, shape) shape = ull : output size is sum o sizes o and g shape = same : output size is same as shape = valid : output size is dierence o sizes o and g ull same valid g g g g g g g g g g g Image Enhancement:Spatial Filtering Operation An important point: Edge Eects To compute all piel values in the output image, we need to ill in a border Mask dimension = M+ Border dimension = M 5
Image Enhancement:Spatial Filtering Operation An important point: Edge Eects E.: 55 Mask) How to ill in a border Zeros Ringing) Replication Better) d b c a c a a d b b Relection Best ) b a a b d c c d Procedure: Replicate row-wise Replicate column-wise Appl iltering Remove borders Implementation What about near the edge? the ilter window alls o the edge o the image need to etrapolate methods MATLAB): clip ilter black): imilter, g, ) wrap around: imilter, g, circular ) cop edge: imilter, g, replicate ) relect across edge: imilter, g, smmetric ) Source: S. Marschner 6
What about near the edge? the ilter window alls o the edge o the image need to etrapolate methods: clip ilter black) wrap around cop edge relect across edge Source: S. Marschner 4 Image Enhancement:Spatial Filtering Operation 55 Blurring with -padding 55 Blurring with relected padding 7
Eamples o linear ilters? Original Source: D. Lowe Practice with linear ilters Original Filtered no change) Source: D. Lowe 8
Practice with linear ilters? Original Source: D. Lowe Practice with linear ilters Original Shited let B piel Source: D. Lowe 9
Practice with linear ilters? Original Source: D. Lowe Practice with linear ilters Original Blur with a bo ilter) Source: D. Lowe
Practice with linear ilters -? Original Note that ilter sums to ) Source: D. Lowe Practice with linear ilters - Original Sharpening ilter - Accentuates dierences with local average Source: D. Lowe
Sharpening Source: D. Lowe 4 Eamples o some other smoothing or low-pass ilters: 5 5 5 5
Gaussian Kernel.3.3..3.3.3.59.97.59.3..97.59.97..3.59.97.59.3.3.3..3.3 5 5, = special gauss,5,) Constant actor at ront makes volume sum to can be ignored, as we should re-normalize weights to sum to in an case) Source: C. Rasmussen Choosing kernel width Gaussian ilters have ininite support, but discrete ilters use inite kernels Source: K. Grauman 3
Choosing kernel width Rule o thumb: set ilter hal-width to about 3 σ Eample: Smoothing with a Gaussian 4
Mean vs. Gaussian iltering Gaussian ilters Remove high-requenc components rom the image low-pass ilter) Convolution with sel is another Gaussian So can smooth with small-width kernel, repeat, and get same result as larger-width kernel would have Convolving two times with Gaussian kernel o width σ is same as convolving once with kernel o width σ Separable kernel Factors into product o two D Gaussians 5
Separabilit o the Gaussian ilter Source: D. Lowe Sharpening revisited What does blurring take awa? = original smoothed 55) detail Let s add it back: + α = original detail sharpened 6
33 More on Linear Operations: Sharpening Filters Sharpening ilters use masks that tpicall have + and numbers in them. The are useul or highlighting or enhancing details and high-requenc inormation e.g. edges) The can and oten are) based on derivativetpe operations in the image whereas smoothing operations were based on integral tpe operations) Dierentiation and convolution Recall, or D unction,,): lim,, We could approimate this as n, n, This is linear and shit invariant, so must be the result o a convolution. which is obviousl a convolution with kernel - Source: D. Forsth, D. Lowe 7
8 35 Derivative-tpe Filters ), ), ), ), ), ), ), ), ), ), Laplacian: 4 36 Variations o the Laplacian Filter Laplacian: 4 Same response in row/column directions 4 Consider: Same response in diagonal directions Together: 8 4 4 Isotropic ilter
9 37 38 Sharpening Using the Laplacian Filter ), ), ), A g 8 A Boosting High Frequencies
Gaussian Unsharp Mask Filter g) ) g ) e g) image blurred image unit impulse identit) unit impulse Gaussian Laplacian o Gaussian Edge detection Goal: Identi sudden changes discontinuities) in an image Intuitivel, most semantic and shape inormation rom the image can be encoded in the edges More compact than piels Ideal: artist s line drawing but artist is also using object-level knowledge) Source: D. Lowe
Characterizing edges An edge is a place o rapid change in the image intensit intensit unction image along horizontal scanline) irst derivative edges correspond to etrema o derivative Image gradient The gradient o an image: The gradient points in the direction o most rapid increase in intensit How does this direction relate to the direction o the edge? The gradient direction is given b The edge strength is given b the gradient magnitude Source: Steve Seitz
43 Using the irst derivative or enhancement: / Sobel Edge Detector: Given image appl : Compute Magnitudes and Add Edge Image 44 Application o Sobel gradient: Man other edge detecting ilters eist. Which is best?
45 Order-statistics Filters Linear ilters o the tpe we have seen with all positive coeicients) will blur the image and reduce certain kinds o noise. Nonlinear smoothing ilters can also be considered Instead o computing a weighted average over the masked area, perorm an operation on the sorted list o piels in the area. Order statistic ilters are useul or removing certain impulsive tpes o noise. 46 Order-statistics Filters 8 9 w Linear Filter w w8 w9 Inner product T g wi i w i Nonlinear operator 8 9 z w Nonlinear OS) Filter sort z z8 z9 w w8 w9 Inner product T g wi zi w z i 3
47 Eamples o Order-statistics Filters Nonlinear OS) Filter Median Filter 8 9 z w sort z z8 z9 w w8 w9 Min Filter Ma Filter Trimmed Mean Filter Inner product T g wi zi w z i 4 4 48 For Gaussian noise removal: Use linear smoothing ilter For impulsive Salt+Pepper, heavtailed,..): Use order statistic ilter 4