Docstoc

Introduction to Computer Vision

Document Sample
Introduction to Computer Vision Powered By Docstoc
					Introduction to Computer Vision

            Lecture 07
         Roger S. Gaborski




                   GaborskiRoger S.
          Roger S. Roger S. Gaborski Gaborski   1
        Linear Filtering in MATLAB
  g = imfilter(f, w, filtering mode, boundary, size)

• filters the imput image f with the filter mask w.
   – f is input image. It can be of any class (logical/numeric)
       and dimension.
   – g is output image

• filter mode:
        - 'corr' : correlation, and default mode
        - 'conv' : convolution

                            Roger S. Gaborski                     2
                        Parameters
• g = imfilter(f, w, filtering mode, boundary, size)

   Boundary options
    -X              pad boundary with value X. Default X = 0.
    - 'symmetric'   symmetric padding
    - 'replicate'   replicate padding
    - 'circular'    circular padding

   Size options
    - 'same'   g is the same size of f (default mode)
    - 'full'   g is full filtered by w, so size of g is increased


                              Roger S. Gaborski                     3
MATLAB function for filtering: imfilter
• g = imfilter(f, w, ‘replicate’)
• Correlation is the default filtering mode.
• If filters are pre-rotated 180 degrees, can simply use
  default(corr) for convolution
• If filter is symmetric, doesn’t matter




                        Roger S. Gaborski                  4
               Simple First Derivative
                  Approximation
Difference

1                            1         1        1
0     x   1 1 1       =      0         0        0
-1        Smoothing          -1        -1       -1




                      Roger S. GaborskiRoger S. Gaborski   5
               Rotate Filter


1   1    0     1      0         -1             0     1    1
1   0    -1    1      0         -1             -1    0    1
0   -1   -1    1      0         -1             -1    -1   0

Sensitive to edges at different orientations



                Roger S. GaborskiRoger S. Gaborski            6
                     Sobel Filter
 • Consider unequal weights for smoothing
   operation
1                        1         2         1
0    x   1   2   1   =   0         0         0            = Sy
-1                       -1        -2        -1




                     Roger S. GaborskiRoger S. Gaborski          7
                    Sobel Filter
• Consider unequal weights for smoothing
  operation
1                       -1        0         1
2   x   -1 0   -1   =   -2        0         2            = Sx
1                       -1        0         1




                    Roger S. GaborskiRoger S. Gaborski          8
                           House Image

>> I = imread('house1.jpg');
>> figure, imshow(I)
>> Jg = rgb2gray(J);
>> Jg = im2double(Jg);
>> figure, imshow(Jg)




                               Roger S. GaborskiRoger S. Gaborski   9
            Horizontal Edge Detection

>> f = fspecial('sobel')

f=

   1    2   1
   0    0   0
  -1   -2   -1

>> imEdge = imfilter(Jg, f );
>> figure, imshow(imEdge,[ ]);




                           Roger S. GaborskiRoger S. Gaborski   10
>> figure, imshow(abs(imEdge),[])




                          Roger S. GaborskiRoger S. Gaborski   11
>> figure, hist(abs(imEdge(:)),100)




                          Roger S. GaborskiRoger S. Gaborski   12
figure, imshow(imEdge>.5)




                        Roger S. GaborskiRoger S. Gaborski   13
                        Vertical Edges

>> fv = f'

fv =

   1    0    -1
   2    0    -2
   1    0    -1

>> imEdgeV = imfilter(Jg, fv );
>> figure, imshow(imEdgeV,[]);




                           Roger S. GaborskiRoger S. Gaborski   14
 Both Vertical and Horizontal Edges




figure, subplot(1,2,1),imshow(abs(Eh)>.5)
>> subplot(1,2,2),imshow(abs(Ev)>.5)
                            Roger S. GaborskiRoger S. Gaborski   15
figure, imshow((abs(Eh)+abs(Ev))/2,[])




          Roger S. GaborskiRoger S. Gaborski   16
 build1.jpg




Roger S. GaborskiRoger S. Gaborski   17
Edge image




Roger S. GaborskiRoger S. Gaborski   18
~ Operator




Roger S. GaborskiRoger S. Gaborski   19
Is there a better way to remove
   noise than the simple Sobel
            approach?




          Roger S. GaborskiRoger S. Gaborski   20
                       Canny
• Image is smoothed with 2D Gaussian Function
• Canny uses two thresholds
  – One threshold detects strong edges
  – Second threshold detects weak edges connected
    to strong edges




                Roger S. GaborskiRoger S. Gaborski   21
      RECALL: 2D Gaussian Distribution
• The two-dimensional Gaussian distribution is
  defined by:




• From this distribution, can generate
  smoothing masks whose width depends upon
  the standard deviation, :
                Roger S. GaborskiRoger S. Gaborski   22
Sigma Determines Spread of Filter



Variance, 2 = .25




Variance, 2 = 4.0
                     Roger S. GaborskiRoger S. Gaborski   23
      Creating Gaussian Kernels
• The mask weights are evaluated from the
  Gaussian distribution:

                                     i2 + j2
            W(i,j) = k * exp (-           )
                                      2 2

• This can be rewritten as:
             W(i,j)                i2 + j2
                    = exp (-              )
              k                     2   2




                  Roger S. GaborskiRoger S. Gaborski   24
                                                                     Example
• Choose  = 2. and n = 7, then:
                   2


                                   j
              -3       -2     -1       0        1      2         3
         -3
         -2
         -1
     i   0
         1

         2

         3




                            Roger S. GaborskiRoger S. Gaborski                 25
7x7 Gaussian Filter




                      Roger S. GaborskiRoger S. Gaborski   26
Building1 gray level image




       Roger S. GaborskiRoger S. Gaborski   27
31x31Gaussian, sigma = 3




      Roger S. GaborskiRoger S. Gaborski   28
63x63 Gaussian, sigma = 10




       Roger S. GaborskiRoger S. Gaborski   29
Canny Edge Detector




    Roger S. GaborskiRoger S. Gaborski   30
                 Implement Canny using
                 MATLAB edge Function
EDGE Find edges in intensity image.
  EDGE takes an intensity or a binary image I as its input, and returns a
  binary image BW of the same size as I, with 1's where the function
  finds edges in I and 0's elsewhere.

  EDGE supports six different edge-finding methods:

The Sobel method finds edges using the Sobel approximation to the derivative.
The Prewitt method finds edges using the Prewitt approximation to the derivative.
The Roberts method finds edges using the Roberts approximation to the derivative.
The Laplacian of Gaussian method finds edges by looking for zero crossings after
    filtering I with a Laplacian of Gaussian filter.
The zero-cross method finds edges by looking for zero crossings after filtering I
    with a filter you specify.
The Canny method finds edges by looking for local maxima of the
   gradient of I. The gradient is calculated using the derivative of a Gaussian filter.
   The method uses two thresholds, to detect strong and weak edges, and
    includes the weak edges in the output only if they are connected to strong
    edges. This method is therefore less likely than the others to be "fooled" by
                                 Roger
    noise, and more likely to detectS. GaborskiRoger S. Gaborski
                                       true weak edges.                                   31
[g,t]=edge(im,'canny',[ ],.5)




 [ ] : Edge function determines the two thresholds

 CHANGING SIGMA OF GAUSSIAN, in this example = .5

                Roger S. GaborskiRoger S. Gaborski   32
[g,t]=edge(im,'canny',[ ],1)




 CHANGING SIGMA OF GAUSSIAN



            Roger S. GaborskiRoger S. Gaborski   33
[g,t]=edge(im,'canny',[ ],2)




 CHANGING SIGMA OF GAUSSIAN



            Roger S. GaborskiRoger S. Gaborski   34
[g,t]=edge(im,'canny',[ ],3)




 CHANGING SIGMA OF GAUSSIAN



            Roger S. GaborskiRoger S. Gaborski   35
[g,t]=edge(im,'canny',[ ],5)




 CHANGING SIGMA OF GAUSSIAN



            Roger S. GaborskiRoger S. Gaborski   36
    Second Derivative Edge Detection
               Methods

• Second derivative is noisy
• First smooth the image, then apply
  second derivative
• Consider
  – Effect of smoothing filter.
  – Gaussian:


                   Roger S. GaborskiRoger S. Gaborski   37
        RECALL: Second Derivative
             Approximation
• Discrete version of 2nd Partial Derivation of
  f(x,y) in x direction is found by taking the
  difference of Eq1 and Eq2:
•  2 f(x,y) /  x2 = Eq1-Eq2
      = 2f(x,y)-f(x-1,y)-f(x+1,y)
In y direction:
•  2 f(x,y) /  y2 = Eq3-Eq4
      = 2f(x,y)-f(x,y-1)-f(x,y+1)

                Roger S. GaborskiRoger S. Gaborski   38
Derivative Approximation for
          Laplacian
 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)



               Roger S. GaborskiRoger S. Gaborski            39
                       Laplacian
• Independent of edge orientation
• Combine  2 f(x,y)/ x2 and  2 f(x,y)/ y2
    =4 f(x,y) - f(x-1,y) – f(x+1,y) – f(x,y-1) – f(x,y+1)

                      0              -1             0
                      -1             4              -1
                      0              -1             0


                     Roger S. GaborskiRoger S. Gaborski     40
                                LoG
• Laplacian of the Gaussian




  is a circularly symmetric operator.
• Second derivative is linear operation
 Therefore: convolving an image with 2 G(x,y) is the same
  as first convolving first with smoothing filter (Gaussian)
  then computing Laplacian of result.
• Edge are location of zero crossings
                     Roger S. GaborskiRoger S. Gaborski   41
                           LoG




Also called the Mexican hat operator.


                Roger S. GaborskiRoger S. Gaborski   42
2 Controls of the Size of the Filter




     2 = 0.5                                        2 = 2.0

                Roger S. GaborskiRoger S. Gaborski              43
Human Visual System Receptive Field
         Approximation
                                                 17 x 17


      5x5




            Roger S. GaborskiRoger S. Gaborski             44
LoG (7x7, sigma = 2)




    Roger S. GaborskiRoger S. Gaborski   45
LoG (15x15, sigma = 4)




     Roger S. GaborskiRoger S. Gaborski   46
  Summarizing: Laplacian of Gaussian
                (LoG)
• Gaussian function:
  h(r) = -exp(-r2/22)
• Applying the Gaussian has a smoothing or
  blurring effect
• Blurring depends on sigma
• THEN Laplacian of Gaussian (Second
  Derivative)


                Roger S. GaborskiRoger S. Gaborski   47
                MATLAB edge Function
EDGE Find edges in intensity image.
  EDGE takes an intensity or a binary image I as its input, and returns a
  binary image BW of the same size as I, with 1's where the function
  finds edges in I and 0's elsewhere.

  EDGE supports six different edge-finding methods:

The Sobel method finds edges using the Sobel approximation to the derivative.
The Prewitt method finds edges using the Prewitt approximation to the derivative.
The Roberts method finds edges using the Roberts approximation to the derivative.
The Laplacian of Gaussian method finds edges by looking for zero crossings after
    filtering I with a Laplacian of Gaussian filter.
The zero-cross method finds edges by looking for zero crossings after filtering I
    with a filter you specify.
The Canny method finds edges by looking for local maxima of the
   gradient of I. The gradient is calculated using the derivative of a Gaussian filter.
   The method uses two thresholds, to detect strong and weak edges, and
    includes the weak edges in the output only if they are connected to strong
    edges. This method is therefore less likely than the others to be "fooled" by
                                 Roger
    noise, and more likely to detectS. GaborskiRoger S. Gaborski
                                       true weak edges.                                   48
Implementation: Laplacian of Gaussian
               (LoG)
• Syntax:

  [g] = edge(f, ‘log’, T, sigma);
  Ignores edges that are not stronger than T
  If T not provided, MATLAB automatically chooses T




                 Roger S. GaborskiRoger S. Gaborski   49
                     Building




What’s important??

               Roger S. GaborskiRoger S. Gaborski   50
[g,t]=edge(im,'log',[ ],1);
        sigma = 1




      Roger S. GaborskiRoger S. Gaborski   51
[g,t]=edge(im,'log',[ ],2);




       Roger S. GaborskiRoger S. Gaborski   52
[g,t]=edge(im,'log',[ ],3)




      Roger S. GaborskiRoger S. Gaborski   53
  Exploring the LoG Parameter Space




[g, t] = edge(f, 'log',[],2);   Default threshold, t= .918, sigma = 2

WHAT IF WE CHANGE SIGMA??


                                  Roger S. GaborskiRoger S. Gaborski    54
                  t= .918




Sigma = 1   Sigma = 3 (more smoothing)



            Roger S. GaborskiRoger S. Gaborski   55
                 t = .500




Sigma = 1   Sigma = 3



            Roger S. GaborskiRoger S. Gaborski   56
                 t = 1.500




Sigma = 1.0          Sigma = 3.0



              Roger S. GaborskiRoger S. Gaborski   57
                          DoG
• Difference of Gaussians is an approximation to
  Laplacian of Gaussian




                Roger S. GaborskiRoger S. Gaborski   58
Comparison of Canny and LoG
                                                   LoG
                                                   St dev = 2




Canny,
Std dev = 1

              Roger S. GaborskiRoger S. Gaborski                60
                  The fern image




[g,t]=edge(fernGray,'canny',[ ],2);
The structure of the image affects the performance of edge detection
                       Roger S. GaborskiRoger S. Gaborski              61
[g,t]=edge(fernGray,'canny',[ ],3);




           Roger S. GaborskiRoger S. Gaborski   62
                 Resize image first




>> sm=imresize(fernGray, .5, 'bicubic');
>> [g,t]=edge(sm,'canny',[ ],2);


                         Roger S. GaborskiRoger S. Gaborski   63
>> [g,t]=edge(sm,'canny',[ ],3);
>> figure, imshow(g)

                         Roger S. GaborskiRoger S. Gaborski   64
             Other Features
• Could color be used as a second feature to
  locate the fern?
• Texture?




                Roger S. GaborskiRoger S. Gaborski   65
Canny, sigma = 3
                   Roger S. GaborskiRoger S. Gaborski   66
Canny, sigma = 2
                   Roger S. GaborskiRoger S. Gaborski   67
Canny, sigma = 1   Roger S. GaborskiRoger S. Gaborski   68
Canny, sigma = .5   Roger S. GaborskiRoger S. Gaborski   69
2 Sigma             3 Sigma




          Roger S. GaborskiRoger S. Gaborski   70
Box Image




Roger S. GaborskiRoger S. Gaborski   71
         Box Sobel edge image




Horizontal Edges
                   Roger S. GaborskiRoger S. Gaborski   72
Note missing Horizontal Edges




         Roger S. GaborskiRoger S. Gaborski   73
Canny Example




 Roger S. GaborskiRoger S. Gaborski   74
Canny with larger Sigma




      Roger S. GaborskiRoger S. Gaborski   75

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:0
posted:4/10/2014
language:Latin
pages:75