image filter and convolution.pdf

  • Upload
    zsyed92

  • View
    217

  • Download
    0

Embed Size (px)

Citation preview

  • 7/29/2019 image filter and convolution.pdf

    1/34

    Convolution, Edge Detection, Sampling

    15-463: Computational PhotographyAlexei Efros, CMU, Fall 2006Some slides from Steve Seitz

  • 7/29/2019 image filter and convolution.pdf

    2/34

    Fourier spectrum

  • 7/29/2019 image filter and convolution.pdf

    3/34

    Fun and games with spectra

  • 7/29/2019 image filter and convolution.pdf

    4/34

    4

    Gaussian filtering

    A Gaussian kernel gives less weight to pixels further from the centerof the window

    This kernel is an approximation of a Gaussian function:

    0000000000

    00000009000

    0000000000

    009090909090000

    00909090090000

    009090909090000

    009090909090000

    009090909090000

    0000000000

    0000000000

    121

    242

    121

  • 7/29/2019 image filter and convolution.pdf

    5/34

    Convolution

    Remember cross-correlation:

    A convolution operation is a cross-correlation where the filter isflipped both horizontally and vertically before being applied tothe image:

    It is written:

    Suppose H is a Gaussian or mean kernel. How does convolutiondiffer from cross-correlation?

  • 7/29/2019 image filter and convolution.pdf

    6/34

    The Convolution Theorem

    The greatest thing since sliced (banana) bread!

    The Fourier transform of the convolution of two

    functions is the product of their Fourier transforms

    The inverse Fourier transform of the product of twoFourier transforms is the convolution of the twoinverse Fourier transforms

    Convolution in spatial domain is equivalent tomultiplication in frequency domain!

    ]F[]F[]F[ hghg =

    ][F][F][F 111 hggh =

  • 7/29/2019 image filter and convolution.pdf

    7/34

    Fourier Transform pairs

  • 7/29/2019 image filter and convolution.pdf

    8/34

    2D convolution theorem example

    *

    f(x,y)

    h(x,y)

    g(x,y)

    |F(sx,sy)|

    |H(sx,sy)|

    |G(sx,sy)|

  • 7/29/2019 image filter and convolution.pdf

    9/34

    Low-pass, Band-pass, High-pass filters

    low-pass:

    band-pass:

    whats high-pass?

  • 7/29/2019 image filter and convolution.pdf

    10/34

    Edges in images

  • 7/29/2019 image filter and convolution.pdf

    11/34

    Image gradient

    The gradient of an image:

    The gradient points in the direction of most rapid change in intensity

    The gradient direction is given by:

    how does this relate to the direction of the edge?

    The edge strength is given by the gradient magnitude

  • 7/29/2019 image filter and convolution.pdf

    12/34

    Effects of noise

    Consider a single row or column of the image Plotting intensity as a function of position gives a signal

    Where is the edge?

    How to compute a derivative?

  • 7/29/2019 image filter and convolution.pdf

    13/34

    Where is the edge?

    Solution: smooth first

    Look for peaks in

  • 7/29/2019 image filter and convolution.pdf

    14/34

    Derivative theorem of convolution

    This saves us one operation:

  • 7/29/2019 image filter and convolution.pdf

    15/34

    Laplacian of Gaussian

    Consider

    Laplacian of Gaussianoperator

    Where is the edge? Zero-crossings of bottom graph

  • 7/29/2019 image filter and convolution.pdf

    16/34

    2D edge detection filters

    is the Laplacian operator:

    Laplacian of Gaussian

    Gaussian derivative of Gaussian

  • 7/29/2019 image filter and convolution.pdf

    17/34

    MATLAB demo

    g = f speci al ( ' gaussi an' , 15, 2) ;i magesc( g)

    sur f l ( g)gcl own = conv2( cl own, g, ' same' ) ;i magesc( conv2( cl own, [ - 1 1] , ' same' ) ) ;i magesc( conv2( gcl own, [ - 1 1] , ' same' ) ) ;dx = conv2( g, [ - 1 1] , ' same' ) ;i magesc( conv2( cl own, dx, ' same' ) ) ;l g = f speci al ( ' l og' , 15, 2) ;

    l cl own = conv2( cl own, l g, ' same' ) ;i magesc( l cl own)i magesc( cl own + . 2*l cl own)

  • 7/29/2019 image filter and convolution.pdf

    18/34

    Image Scaling

    This image is too big to

    fit on the screen. Howcan we reduce it?

    How to generate a half-

    sized version?

  • 7/29/2019 image filter and convolution.pdf

    19/34

    Image sub-sampling

    Throw away every other row and

    column to create a 1/2 size image- called image sub-sampling

    1/4

    1/8

  • 7/29/2019 image filter and convolution.pdf

    20/34

    Image sub-sampling

    1/4 (2x zoom) 1/8 (4x zoom)

    Why does this look so crufty?

    1/2

  • 7/29/2019 image filter and convolution.pdf

    21/34

    Even worse for synthetic images

  • 7/29/2019 image filter and convolution.pdf

    22/34

    Really bad in video

  • 7/29/2019 image filter and convolution.pdf

    23/34

    Alias: n., an assumed name

    Picket fence recedingInto the distance willproduce aliasing

    Input signal:

    x = 0:.05:5; imagesc(sin((2. x).*x))

    Matlab output:

    WHY?

    Aj-aj-aj:Alias!

    Not enough samples

  • 7/29/2019 image filter and convolution.pdf

    24/34

    Aliasing occurs when your sampling rate is not high enough to capture the

    amount of detail in your image

    Can give you the wrong signal/imagean alias

    Where can it happen in images? During image synthesis:

    sampling continous singal into discrete signal

    e.g. ray tracing, line drawing, function plotting, etc.

    During image processing: resampling discrete signal at a different rate e.g. Image warping, zooming in, zooming out, etc.

    To do sampling right, need to understand the structure of your

    signal/imageEnter Monsieur Fourier

  • 7/29/2019 image filter and convolution.pdf

    25/34

    Fourier transform pairs

  • 7/29/2019 image filter and convolution.pdf

    26/34

    Sampling

    w

    Spatial domain Frequency domain

    1/w

    sampling

    pattern

    sampled

    signal

  • 7/29/2019 image filter and convolution.pdf

    27/34

    Reconstruction

    Frequency domain

    1/ww

    Spatial domain

    sincfunction

    reconstructed

    signal

  • 7/29/2019 image filter and convolution.pdf

    28/34

    What happens when

    the sampling rate

    is too low?

  • 7/29/2019 image filter and convolution.pdf

    29/34

    NyquistRate

    Whats the minimum Sampling Rate 1/w to get rid ofoverlaps?

    Frequency domain

    1/ww

    Spatial domain

    sincfunction

    Sampling Rate 2 * max frequency in the imagethis is known as the Nyquist Rate

  • 7/29/2019 image filter and convolution.pdf

    30/34

    Antialiasing

    What can be done?Sampling rate 2 * max frequency in the image

    1. Raise sampling rate by oversampling

    Sample at k times the resolution continuous signal: easy

    discrete signal: need to interpolate

    2. Lower the max frequency by prefiltering Smooth the signal enough

    Works on discrete signals

    3. Improve sampling quality with better sampling

    Nyquist is best case! Stratified sampling (jittering)

    Importance sampling (salaries in Seattle)

    Relies on domain knowledge

  • 7/29/2019 image filter and convolution.pdf

    31/34

    Sampling

    Good sampling:Sample often or,Sample wisely

    Bad sampling:see aliasing in action!

  • 7/29/2019 image filter and convolution.pdf

    32/34

    Gaussian pre-filtering

    G 1/4G 1/8

    Gaussian 1/2

    Solution: filter the image, then subsample

  • 7/29/2019 image filter and convolution.pdf

    33/34

    Subsampling with Gaussian pre-filtering

    G 1/4 G 1/8Gaussian 1/2

    Solution: filter the image, then subsample

  • 7/29/2019 image filter and convolution.pdf

    34/34

    Compare with...

    1/4 (2x zoom) 1/8 (4x zoom)1/2