Spatial Filtering Image Processing

download Spatial Filtering Image Processing

of 19

Transcript of Spatial Filtering Image Processing

  • 8/9/2019 Spatial Filtering Image Processing

    1/19

    Spatial Filtering

    Sankalp Kallakuri

    [email protected]

    Lecture 3

  • 8/9/2019 Spatial Filtering Image Processing

    2/19

    Spatial Filtering

    Involves moving a kernel over the image to enhance theimage

    Kernel size is

  • 8/9/2019 Spatial Filtering Image Processing

    3/19

    Spatial Filtering

    f(x-1,y-1) f(x,y-1) f(x+1,y-1)

    f(x-1,y) f(x,y) f(x+1,y)

    f(x-1,y+1) f(x,y+1) f(x+1,y+1)

    m(-1,-1) m(0,-1) m(1,-1)

    m(-1,0) m(0,0) m(1,0)

    m(-1,1) m(0,1) m(1,1)

    Mask coefficients

    Image pixels under mask

    R = m(-1,-1) f(x-1,y-1) + m(0,-1) f(x,y-1) + m(1,-1) f(x+1,y-1) + ..

    a

    as

    b

    bt

    tysxftsmyxg ),(),(),(

  • 8/9/2019 Spatial Filtering Image Processing

    4/19

    Spatial Filtering

    The operation is similar to Convolution. hence the masks are alsocalled convolution masks.

    Non linear operations such as finding median may also be done ona neighborhood.

    Near the edges parts of the masks may lie beyond the imageboundary.

    To avoid this either a smaller filtered image is accepted.

    Or zeros are padded along the image boundary.

  • 8/9/2019 Spatial Filtering Image Processing

    5/19

    Smoothing Spatial Filters

    Averaging or Low pass filters.

    Used to remove unwanted detail.

    Smooth out unwanted sharp noise transitions.

    May smooth out edges which should be sharp.

    1 2 12 4 2

    1 2 1

    Examples

    1 1 11 1 1

    1 1 1

    1/9 x 1/16 x

    Box filter Weighted Average

  • 8/9/2019 Spatial Filtering Image Processing

    6/19

    Smoothing Spatial Filters

    The box filter does a simple average.

    The weighted average filter weighs the contribution by the

    distance from the central image pixel.

    a

    as

    b

    bt

    a

    as

    b

    bt

    tsm

    tysxftsm

    yxg

    ),(

    ),(),(

    ),(

    Mathematical expressionOriginal

    3 6 9 12

  • 8/9/2019 Spatial Filtering Image Processing

    7/19

    Order Statistic Filters

    Median, Max and Min Filters

    Median Filters are particularly effective with salt peppernoise or impulse noise.

    The image pixels under the mask need to be sorted.

    Min and max filters are used to find the brightest anddarkest points.

    original Noise added Median filtered image

  • 8/9/2019 Spatial Filtering Image Processing

    8/19

    Sharpening Spatial Filters

    Use of first and second order derivatives.

    We need to know how they behave at discontinuities,edges, ramps, noise points.

    First Derivative

    1) zero in flat segments2) must be non zero at onset of edge or ramp.3)non zero along ramps

    Second Derivative1) zero in flat segments2) must be non zero at onset of edge or ramp.3) must be zero along ramps of constant slope.

  • 8/9/2019 Spatial Filtering Image Processing

    9/19

    Sharpening Spatial Filters

    )()1( xfxfxf

    First order derivative approximation

    second order derivative approximation

    )(2)1()1(2

    2

    xfxfxf

    x

    f

    -1-1-1-1-1 0 0 6 -6 0 0 0 1 2 -2 -1 0 0 0 7 0 0 0 0

    -1 0 0 0 0 1 0 6 -12 6 0 0 1 1 -4 -1 1 0 0 7 -7 0 0

    5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7 7

  • 8/9/2019 Spatial Filtering Image Processing

    10/19

    Summary of First and Second OrderDerivatives

    First Order Derivatives Generally Produce ThickerEdges.

    Second Order Derivatives have a stronger response to

    finer detail.

    First Order response is generally stronger for a greylevel step.

    Second Order derivatives produce a double response atstep changes in grey level .

  • 8/9/2019 Spatial Filtering Image Processing

    11/19

    2nd Derivative - Laplacian

    isotropic 2nd order operator2

    2

    2

    22

    y

    f

    x

    ff

    ),(2),1(),1(2

    2

    yxfyxfyxfx

    f

    ),(2)1,()1,(2

    2

    yxfyxfyxf

    y

    f

    ),(4)]1,()1,(),1(),1([2 yxfyxfyxfyxfyxff

    Partial DoubleDerivative in Y direction

    Partial DoubleDerivative in X direction

    Digital implementation of the laplacian operator

  • 8/9/2019 Spatial Filtering Image Processing

    12/19

    Laplacian

    0 1 0

    1 -4 1

    0 1 0

    1 1 1

    1 -8 1

    1 1 1

    Isotropic for 900 Isotropic for 450

    Effect of diagonal elements is not considered in the first case

    The image of the laplacian filter is usually added to the original toimprove the Features of the original.

    ),( yxg),(),(

    2 yxfyxf

    ),(),(2 yxfyxf {=

    -ve center coeff

    +ve center coeff

  • 8/9/2019 Spatial Filtering Image Processing

    13/19

    Example : Laplacian

    Laplacian Matlab Laplacian Hand Coded

    Original Difference

  • 8/9/2019 Spatial Filtering Image Processing

    14/19

    Combined Implementation

    ),1()1([),(),( yxfxfyxfyxg

    ),(4)]1,()1,( yxfyxfyxf

    )]1,()1,(

    ),1()1([),(5

    yxfyxf

    yxfxfyxf),( yxg

    0 -1 0

    -1 5 -10 -1 0

    -1 -1 -1

    -1 9 -1-1 -1 -1

    Isotropic for 900 Isotropic for 450

  • 8/9/2019 Spatial Filtering Image Processing

    15/19

    Example: combined implementation

    Original

    laplacian

    Combined

  • 8/9/2019 Spatial Filtering Image Processing

    16/19

    Unsharp Masking and High Boost Filtering

    ),(),(),( yxfyxfyxfs

    ),(),(),()1(),( yxfyxfyxfAyxfhb

    ),(),(),( yxfyxAfyxfhb

    ),(),()1(),( yxfyxfAyxf shb

    Unsharp masking is to substract a smoothed out image from the original

    High boost is to boost up the original by factor A

    We can express the high boost in terms of the original and the sharpenedImage.

    0 -1 0

    -1 A+4 -1

    0 -1 0

    High boost filtering for A 1

    {),(),( 2 yxfyxf

    ),(),( 2 yxfyxf =hbf

    A

    A

    -ve center coeff

    +ve center coeff

  • 8/9/2019 Spatial Filtering Image Processing

    17/19

    Use of First Derivatives - Gradient

    f

    Gy

    Gx

    y

    f

    x

    f

    =

    The gradient as a vector

    f2/122

    ][ yx GG

    2/122

    y

    f

    x

    f

    =

    Magnitude of gradient

    |||| yx GGf Gradient approximatedBy absolute values

  • 8/9/2019 Spatial Filtering Image Processing

    18/19

    Gradient Masks

    0 -1

    1 0

    1 0

    0 -1

    -1 -2 -1

    0 0 0

    1 2 1

    -1 0 1

    -2 0 2

    -1 0 1

    Robert crossoperators

    SobelOperators

  • 8/9/2019 Spatial Filtering Image Processing

    19/19

    HW 2-B

    Repeat HW 2 with a triangle cropping.

    Equilateral with the coordinates ofcentroid same as coordinates of 3L/4,3L/4.

    One edge of the triangle is at 125 degreesto the bottom edge of the image.

    Edge length of the triangle is 30. DUE at same time as HW -2.