Image Fileter

Embed Size (px)

Citation preview

  • 8/10/2019 Image Fileter

    1/49

    Motion illusion, rotating snakes

  • 8/10/2019 Image Fileter

    2/49

    Slide credit Fei Fei Li

  • 8/10/2019 Image Fileter

    3/49

    Slide credit Fei Fei Li

  • 8/10/2019 Image Fileter

    4/49

    Slide credit Fei Fei Li

  • 8/10/2019 Image Fileter

    5/49

    Image Filtering

    Computer Vision

    James Hays, Brown

    09/11/2013

    Many slides by Derek Hoiem

  • 8/10/2019 Image Fileter

    6/49

    Next three classes: three views of filtering

    Image filters in spatial domain Filter is a mathematical operation of a grid of numbers

    Smoothing, sharpening, measuring texture

    Image filters in the frequency domain Filtering is a way to modify the frequencies of images

    Denoising, sampling, image compression

    Templates and Image Pyramids Filtering is a way to match a template to the image

    Detection, coarse-to-fine registration

  • 8/10/2019 Image Fileter

    7/49

    Image filtering

    Image filtering: compute function of local

    neighborhood at each position

    Really important! Enhance images

    Denoise, resize, increase contrast, etc.

    Extract information from images

    Texture, edges, distinctive points, etc.

    Detect patterns

    Template matching

  • 8/10/2019 Image Fileter

    8/49

    111

    111

    111

    Slide credit: David Lowe (UBC)

    ],[g

    Example: box filter

  • 8/10/2019 Image Fileter

    9/49

    0 0 0 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 0 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 90 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    0

    0 0 0 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 0 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 90 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    Credit: S. Seitz

    ],[],[],[,

    lnkmflkgnmhlk

    [.,.]h[.,.]f

    Image filtering

    111

    111

    111

    ],[g

  • 8/10/2019 Image Fileter

    10/49

    0 0 0 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 0 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 90 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    0 10

    0 0 0 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 0 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 90 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    [.,.]h[.,.]f

    Image filtering

    111

    111

    111

    ],[g

    Credit: S. Seitz

    ],[],[],[,

    lnkmflkgnmhlk

  • 8/10/2019 Image Fileter

    11/49

    0 0 0 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 0 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 90 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    0 10 20

    0 0 0 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 0 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 90 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    [.,.]h[.,.]f

    Image filtering

    111

    111

    111

    ],[g

    Credit: S. Seitz

    ],[],[],[,

    lnkmflkgnmhlk

  • 8/10/2019 Image Fileter

    12/49

    0 0 0 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 0 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 90 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    0 10 20 30

    0 0 0 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 0 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 90 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    [.,.]h[.,.]f

    Image filtering

    111

    111

    111

    ],[g

    Credit: S. Seitz

    ],[],[],[,

    lnkmflkgnmhlk

  • 8/10/2019 Image Fileter

    13/49

    0 10 20 30 30

    0 0 0 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 0 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 90 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    [.,.]h[.,.]f

    Image filtering

    111

    111

    111

    ],[g

    Credit: S. Seitz

    ],[],[],[,

    lnkmflkgnmhlk

  • 8/10/2019 Image Fileter

    14/49

    0 10 20 30 30

    0 0 0 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 0 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 90 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    [.,.]h[.,.]f

    Image filtering

    111

    111

    111

    ],[g

    Credit: S. Seitz

    ?

    ],[],[],[,

    lnkmflkgnmhlk

  • 8/10/2019 Image Fileter

    15/49

    0 10 20 30 30

    50

    0 0 0 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 0 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 90 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    [.,.]h[.,.]f

    Image filtering

    111

    111

    111

    ],[g

    Credit: S. Seitz

    ?

    ],[],[],[,

    lnkmflkgnmhlk

  • 8/10/2019 Image Fileter

    16/49

    0 0 0 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 90 0 90 90 90 0 0

    0 0 0 90 90 90 90 90 0 0

    0 0 0 0 0 0 0 0 0 0

    0 0 90 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 0 0

    0 10 20 30 30 30 20 10

    0 20 40 60 60 60 40 20

    0 30 60 90 90 90 60 30

    0 30 50 80 80 90 60 30

    0 30 50 80 80 90 60 30

    0 20 30 50 50 60 40 20

    10 20 30 30 30 30 20 10

    10 10 10 0 0 0 0 0

    [.,.]h[.,.]f

    Image filtering111

    111

    111],[g

    Credit: S. Seitz

    ],[],[],[,

    lnkmflkgnmhlk

  • 8/10/2019 Image Fileter

    17/49

    What does it do?

    Replaces each pixel with

    an average of itsneighborhood

    Achieve smoothing effect

    (remove sharp features)

    111

    111

    111

    Slide credit: David Lowe (UBC)

    ],[g

    Box Filter

  • 8/10/2019 Image Fileter

    18/49

    Smoothing with box filter

  • 8/10/2019 Image Fileter

    19/49

    Practice with linear filters

    000

    010

    000

    Original

    ?

    Source: D. Lowe

  • 8/10/2019 Image Fileter

    20/49

    Practice with linear filters

    000

    010

    000

    Original Filtered(no change)

    Source: D. Lowe

  • 8/10/2019 Image Fileter

    21/49

    Practice with linear filters

    000

    100

    000

    Original

    ?

    Source: D. Lowe

  • 8/10/2019 Image Fileter

    22/49

    Practice with linear filters

    000

    100

    000

    Original Shifted leftBy 1 pixel

    Source: D. Lowe

  • 8/10/2019 Image Fileter

    23/49

  • 8/10/2019 Image Fileter

    24/49

    Practice with linear filters

    Original

    111

    111

    111

    000

    020

    000

    -

    Sharpening filter- Accentuates differences with local

    average

    Source: D. Lowe

  • 8/10/2019 Image Fileter

    25/49

    Sharpening

    Source: D. Lowe

  • 8/10/2019 Image Fileter

    26/49

    Other filters

    -101

    -202

    -101

    Vertical Edge

    (absolute value)

    Sobel

  • 8/10/2019 Image Fileter

    27/49

    Other filters

    -1-2-1

    000

    121

    Horizontal Edge

    (absolute value)

    Sobel

  • 8/10/2019 Image Fileter

    28/49

    Filtering vs. Convolution

    2d filtering

    h=filter2(g,f); or

    h=imfilter(f,g);

    2d convolution

    h=conv2(g,f);

    ],[],[],[,

    lnkmflkgnmhlk

    f=imageg=filter

    ],[],[],[

    ,

    lnkmflkgnmh

    lk

  • 8/10/2019 Image Fileter

    29/49

    Key properties of linear filters

    Linearity:filter(f1+ f2) = filter(f1) + filter(f2)

    Shift invariance:same behavior regardless of

    pixel location

    filter(shift(f)) = shift(filter(f))

    Any linear, shift-invariant operator can be

    represented as a convolution

    Source: S. Lazebnik

  • 8/10/2019 Image Fileter

    30/49

    More properties

    Commutative: a* b= b* a

    Conceptually no difference between filter and signal

    But particular filtering implementations might break this equality

    Associative: a* (b* c) = (a* b) * c

    Often apply several filters one after another: (((a* b1) * b2) * b3)

    This is equivalent to applying one filter: a * (b1* b2* b3)

    Distributes over addition: a* (b+ c) = (a* b) + (a* c)

    Scalars factor out: ka * b = a * kb = k (a* b)

    Identity: unit impulse e= [0, 0, 1, 0, 0],

    a* e= a Source: S. Lazebnik

    I t t filt G i

  • 8/10/2019 Image Fileter

    31/49

    Weight contributions of neighboring pixels by nearness

    0.003 0.013 0.022 0.013 0.003

    0.013 0.059 0.097 0.059 0.013

    0.022 0.097 0.159 0.097 0.022

    0.013 0.059 0.097 0.059 0.0130.003 0.013 0.022 0.013 0.003

    5 x 5, = 1

    Slide credit: Christopher Rasmussen

    Important filter: Gaussian

    S thi ith G i filt

  • 8/10/2019 Image Fileter

    32/49

    Smoothing with Gaussian filter

    Smoothing ith bo filter

  • 8/10/2019 Image Fileter

    33/49

    Smoothing with box filter

  • 8/10/2019 Image Fileter

    34/49

    Gaussian filters

    Remove high-frequency components from the

    image (low-pass filter) Images become more smooth

    Convolution with self is another Gaussian

    So can smooth with small-width kernel, repeat, andget same result as larger-width kernel would have

    Convolving two times with Gaussian kernel of width

    is same as convolving once with kernel of width 2

    Separable kernel

    Factors into product of two 1D Gaussians

    Source: K. Grauman

  • 8/10/2019 Image Fileter

    35/49

    Separability of the Gaussian filter

    Source: D. Lowe

    b l l

  • 8/10/2019 Image Fileter

    36/49

    Separability example

    *

    *

    =

    =

    2D convolution(center location only)

    Source: K. Grauman

    The filter factors

    into a product of 1D

    filters:

    Perform convolution

    along rows:

    Followed by convolution

    along the remaining column:

    b l

  • 8/10/2019 Image Fileter

    37/49

    Separability

    Why is separability useful in practice?

    S i l

  • 8/10/2019 Image Fileter

    38/49

    Some practical matters

    P i l

  • 8/10/2019 Image Fileter

    39/49

    How big should the filter be?

    Values at edges should be near zero Rule of thumb for Gaussian: set filter half-width to

    about 3

    Practical matters

    P i l

  • 8/10/2019 Image Fileter

    40/49

    Practical matters

    What about near the edge?

    the filter window falls off the edge of the image

    need to extrapolate

    methods:

    clip filter (black)

    wrap around

    copy edge

    reflect across edge

    Source: S. Marschner

    P i lQ?

  • 8/10/2019 Image Fileter

    41/49

    Practical matters

    methods (MATLAB):

    clip filter (black): imfilter(f, g, 0) wrap around: imfilter(f, g, circular)

    copy edge: imfilter(f, g, replicate)

    reflect across edge: imfilter(f, g, symmetric)

    Source: S. Marschner

    P ti l tt

  • 8/10/2019 Image Fileter

    42/49

    Practical matters

    What is the size of the output?

    MATLAB: filter2(g, f, shape)

    shape= full: output size is sum of sizes of f and g

    shape= same: output size is same as f

    shape= valid: output size is difference of sizes of f and g

    f

    gg

    gg

    f

    gg

    gg

    f

    gg

    gg

    full same valid

    Source: S. Lazebnik

    M di filt

  • 8/10/2019 Image Fileter

    43/49

    2006 Steve Marschner 45

    Median filters

    A Median Filteroperates over a window byselecting the median intensity in the window.

    What advantage does a median filter have over

    a mean filter?

    Is a median filter a kind of convolution?

    Slide by Steve Seitz

    C i lt d i

  • 8/10/2019 Image Fileter

    44/49

    2006 Steve Marschner 46

    Comparison: salt and pepper noise

    Slide by Steve Seitz

    P j t 1 H b id I

  • 8/10/2019 Image Fileter

    45/49

    Project 1: Hybrid Images

    Gaussian Filter!

    Laplacian Filter!

    A. Oliva, A. Torralba, P.G. Schyns,

    Hybrid Images,SIGGRAPH 2006

    Gaussianunit impulse Laplacian of Gaussian

    T k h

    http://cvcl.mit.edu/hybridimage.htmhttp://cvcl.mit.edu/hybridimage.htm
  • 8/10/2019 Image Fileter

    46/49

    Take-home messages

    Linear filtering is sum of dotproduct at each position

    Can smooth, sharpen, translate

    (among many other uses)

    Be aware of details for filter size,

    extrapolation, cropping

    111

    111

    111

    P ti ti

  • 8/10/2019 Image Fileter

    47/49

    Practice questions

    1. Write down a 3x3 filter that returns a positive

    value if the average value of the 4-adjacentneighbors is less than the center and a

    negative value otherwise

    2. Write down a filter that will compute the

    gradient in the x-direction:

    gradx(y,x) = im(y,x+1)-im(y,x) for each x, y

    Practice questions

  • 8/10/2019 Image Fileter

    48/49

    Practice questions

    3. Fill in the blanks:a) _ = D * B

    b) A = _ * _

    c) F = D * _

    d) _ = D * D

    A

    B

    C

    D

    E

    F

    G

    H I

    Filtering Operator

    Next class Thinking in Frequency

  • 8/10/2019 Image Fileter

    49/49

    Next class: Thinking in Frequency