Lecture 11

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 49

Edge detection: Gradients

Basis of Edges

surface normal discontinuity


depth discontinuity
surface color discontinuity
illumination discontinuity
In a real image
Depth
discontinuity:
Reflectance change: object boundary
appearance
information, texture
Cast shadows

Discontinuity
in surface
orientation
Edge detection__ Reduced Set
Recall images as functions...

Edges look like steep cliffs


Edge Detection
Basic idea: look for a neighborhood with strong
signs of change.

Problems:
81 82 26 24
• neighborhood size 82 33 25 25
81 82 26 24
• how to detect change
Derivatives and edges
An edge is a place of rapid change in the image
intensity function.
intensity function
image

Source: S. Lazebnik
Derivatives and edges
An edge is a place of rapid change in the image
intensity function. finding edges …. finding peaks in the derivative.
image intensity function first derivative
(along horizontal scanline)

edges correspond to
Source: S. Lazebnik
extrema of derivative
Differential Operators
• Differential operators -when applied to the image
returns some derivatives.
• Model these "operators" as masks/kernels that
compute the image gradient function.
• Threshold this gradient function to select the
edge pixels.
What's a gradient?
Gradient is the vector that's made up of derivatives.

Multivariate Functions
Image gradient
The gradient of an image:

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


and the magnitude of that vector is how much its changing as
function of a unit step in that direction.
Image gradient
The gradient of an image:

The gradient direction is given by:

The edge strength is given by the


gradient magnitude:
Discrete gradient
For 2D function, f(x,y), the partial derivative is:
Discrete gradient- Finite Differences
For discrete data, we can approximate using
finite differences:

“right derivative”
Finite differences finite difference Img/gradient img

Source: D.A. Forsyth


Finite differences - x or y?

Source: D. Forsyth
Partial derivatives of an image

(correlation filters)
Partial derivatives of an image

(correlation filters)
Partial derivatives of an image

(correlation filters)
The discrete gradient
• We want an "operator" (mask/kernel) that we
can apply to the image that implements:

How would you implement this as a cross-correlation?


The discrete gradient
Example: Sobel operator
Sobel Operator on Blocks Image

original image gradient thresholded


magnitude gradient
magnitude
Some Well-Known Gradients Masks
Matlab does gradients

filt = fspecial('sobel')

filt =
1 2 1
0 0 0
-1 -2 -1

outim = imfilter(double(im),filt);
imagesc(outim);
colormap gray;
But in the real world...
Consider a single row or column of the image
(plotting intensity as a function of x)

Apply derivative operator

where's
the edge?
Finite differences responding to noise

Increasing noise
(this is zero mean additive Gaussian noise)
Source: D. Forsyth
Solution: smooth first
Solution: smooth first
Solution: smooth first
Solution: smooth first
Solution: smooth first
Where is the
edge?

Look for peaks


Derivative theorem of convolution

This saves us one operation:


Derivative theorem of convolution
This saves us one operation:
2nd derivative of Gaussian
we get this nice zero crossing with this strong slope. And that's what corresponds
to our edge.

We don't have to find general maxima, we just have to find any place where the
value is zero and that nearby has a strong gradient.
Gradient Direction
Computation and Representation
Here is an image that has clearly defined edges and
distinct angles.
// This function returns a pair of matrices, the first one being the gradient in x
Direction and the second one in the y direction.
we should scale them to the appropriate range to normalize the gradient images.
This is what the gradient magnitude looks like.
As the gradient direction is an angle computed as the tan inverse of y by x gradient
values. The result is returned in degrees ranging from minus -180 to +180. Where 0
degree corresponds with the positive x-axis, and increasing angle rotates
counterclockwise. The right edge has gradient pointing at 0 degrees.

You might also like