edges and binary images dan witzner hansen. previously???

93
Edges and Binary Images Dan Witzner Hansen

Upload: joan-clarissa-hardy

Post on 17-Dec-2015

225 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Edges and Binary Images Dan Witzner Hansen. Previously???

Edges and Binary Images

Dan Witzner Hansen

Page 2: Edges and Binary Images Dan Witzner Hansen. Previously???

Previously???

Page 3: Edges and Binary Images Dan Witzner Hansen. Previously???

What filter is likely to have produced this image output?

original filtered output

Page 4: Edges and Binary Images Dan Witzner Hansen. Previously???

5 x 5 median filter

25 x 25 median filter 50 x 50 median filter

Is the meadian filter a linear filter (convolution)?

Page 5: Edges and Binary Images Dan Witzner Hansen. Previously???

Edge detection• Goal: map image from 2d array of pixels to a set of curves

or line segments or contours.• Why?

• Main idea: look for strong gradients, post-process

Figure from J. Shotton et al., PAMI 2007

Page 6: Edges and Binary Images Dan Witzner Hansen. Previously???

What can cause an edge?

Depth discontinuity: object boundary

Change in surface orientation: shape

Cast shadows

Reflectance change: appearance information, texture

Page 7: Edges and Binary Images Dan Witzner Hansen. Previously???

Derivatives and edges

imageintensity function

(along horizontal scanline) first derivative

edges correspond toextrema of derivative

Source: L. Lazebnik

An edge is a place of rapid change in the image intensity function.

Page 8: Edges and Binary Images Dan Witzner Hansen. Previously???

Recall : Images as functions

• Edges look like steep cliffs

Source: S. Seitz

Page 9: Edges and Binary Images Dan Witzner Hansen. Previously???

Differentiation and convolution

For 2D function, f(x,y), the partial derivative is:

For discrete data, we can approximate using finite differences:

To implement above as convolution, what would be the associated filter?

),(),(lim

),(0

yxfyxf

x

yxf

1

),(),1(),( yxfyxf

x

yxf

Page 10: Edges and Binary Images Dan Witzner Hansen. Previously???

Partial derivatives of an image

Which shows changes with respect to x?

-1 1

1 -1

or?

-1 1

x

yxf

),(

y

yxf

),(

(showing flipped filters)

Page 11: Edges and Binary Images Dan Witzner Hansen. Previously???

Assorted finite difference filters

>> My = fspecial(‘sobel’);>> outim = imfilter(double(im), My); >> imagesc(outim);>> colormap gray;

Page 12: Edges and Binary Images Dan Witzner Hansen. Previously???

The gradient direction (orientation of edge normal) is given by:

The edge strength is given by the gradient magnitude

Image gradientThe gradient of an image:

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

Slide credit S. Seitz

Page 13: Edges and Binary Images Dan Witzner Hansen. Previously???

Eye Image example

Page 14: Edges and Binary Images Dan Witzner Hansen. Previously???

Effects of noiseConsider a single row or column of the image

– Plotting intensity as a function of position gives a signal

Where is the edge?

Page 15: Edges and Binary Images Dan Witzner Hansen. Previously???

Where is the edge?

Solution: smooth first

Look for peaks in

Page 16: Edges and Binary Images Dan Witzner Hansen. Previously???

Derivative theorem of convolution

Differentiation property of convolution.

Page 17: Edges and Binary Images Dan Witzner Hansen. Previously???

Derivative of Gaussian filter

11 0.0030 0.0133 0.0219 0.0133 0.0030 0.0133 0.0596 0.0983 0.0596 0.0133 0.0219 0.0983 0.1621 0.0983 0.0219 0.0133 0.0596 0.0983 0.0596 0.0133 0.0030 0.0133 0.0219 0.0133 0.0030

)()( hgIhgI

Why is this preferable?

Page 18: Edges and Binary Images Dan Witzner Hansen. Previously???

Derivative of Gaussian filters

x-direction y-direction

Source: L. Lazebnik

Page 19: Edges and Binary Images Dan Witzner Hansen. Previously???

Laplacian of GaussianConsider

Laplacian of Gaussianoperator

Where is the edge? Zero-crossings of bottom graph

Page 20: Edges and Binary Images Dan Witzner Hansen. Previously???

2D edge detection filters

• is the Laplacian operator (trace of Hessian):

Laplacian of Gaussian

Gaussian derivative of Gaussian

H =

∂ 2 f

∂x 2

∂ 2 f

∂x∂y∂ 2 f

∂x∂y

∂ 2 f

∂y 2

⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥

Page 21: Edges and Binary Images Dan Witzner Hansen. Previously???

Derivatives of Gaussian

Page 22: Edges and Binary Images Dan Witzner Hansen. Previously???

Mask properties• Smoothing

– Values positive – Sum to 1 constant regions same as input– Amount of smoothing proportional to mask size– Remove “high-frequency” components; “low-pass” filter

• Derivatives– Opposite signs used to get high response in regions of high contrast– Sum to 0 no response in constant regions– High absolute value at points of high contrast

• Filters act as templates• Highest response for regions that “look the most like the filter”• Dot product as correlation

Page 23: Edges and Binary Images Dan Witzner Hansen. Previously???

Gradients -> edges

Primary edge detection steps:1. Smoothing: suppress noise2. Edge enhancement: filter for contrast3. Edge localization

Determine which local maxima from filter output are actually edges vs. noise

• Threshold, Thin ( more about this later)

Page 24: Edges and Binary Images Dan Witzner Hansen. Previously???

Smoothing with a GaussianRecall: parameter σ is the “scale” / “width” / “spread” of the Gaussian kernel, and controls the amount of smoothing.

Page 25: Edges and Binary Images Dan Witzner Hansen. Previously???

Effect of on derivatives

The apparent structures differ depending on Gaussian’s scale parameter.

Larger values: larger scale edges detectedSmaller values: finer features detected

σ = 1 pixel σ = 3 pixels

Page 26: Edges and Binary Images Dan Witzner Hansen. Previously???

So, what scale to choose?

Too fine of a scale…can’t see the forest for the trees.Too coarse of a scale…can’t tell the maple grain from the cherry.

Page 27: Edges and Binary Images Dan Witzner Hansen. Previously???

Original image

Page 28: Edges and Binary Images Dan Witzner Hansen. Previously???

Thresholding gradient with a lower threshold

Page 29: Edges and Binary Images Dan Witzner Hansen. Previously???

Canny edge detector• Filter image with derivative of Gaussian • Find magnitude and orientation of gradient• Non-maximum suppression:

– Thin multi-pixel wide “ridges” down to single pixel width• Linking and thresholding (hysteresis):

– Define two thresholds: low and high– Use the high threshold to start edge curves and the low

threshold to continue them

• MATLAB: edge(image, ‘canny’);• >>help edge

Source: D. Lowe, L. Fei-Fei

Page 30: Edges and Binary Images Dan Witzner Hansen. Previously???

The Canny edge detector

original image (Lena)

Page 31: Edges and Binary Images Dan Witzner Hansen. Previously???

The Canny edge detector

norm of the gradient

Page 32: Edges and Binary Images Dan Witzner Hansen. Previously???

The Canny edge detector

thresholding

Page 33: Edges and Binary Images Dan Witzner Hansen. Previously???

The Canny edge detector

thresholding

How to turn these thick regions of the gradient into curves?

Page 34: Edges and Binary Images Dan Witzner Hansen. Previously???

Non-maximum suppression

Check if pixel is local maximum along gradient direction, select single max across width of the edge– requires checking interpolated pixels p and r

Page 35: Edges and Binary Images Dan Witzner Hansen. Previously???

The Canny edge detector

thinning(non-maximum suppression)

Problem: pixels along this edge didn’t survive the thresholding

Page 36: Edges and Binary Images Dan Witzner Hansen. Previously???

Hysteresis thresholding• Check that maximum gradient value is sufficiently

large– drop-outs? use hysteresis

• use a high threshold to start edge curves and a low threshold to continue them.

Source: S. Seitz

Page 37: Edges and Binary Images Dan Witzner Hansen. Previously???

Hysteresis thresholding

original image

high threshold(strong edges)

low threshold(weak edges)

hysteresis threshold

Source: L. Fei-Fei

Page 38: Edges and Binary Images Dan Witzner Hansen. Previously???

Object boundaries vs. edges

Background Texture Shadows

Page 39: Edges and Binary Images Dan Witzner Hansen. Previously???

Seam Carving uses edges to be able to resize images

• Try it.

Page 40: Edges and Binary Images Dan Witzner Hansen. Previously???

Thresholding

• What is thresholding?

• Choose a threshold value t• Set any pixels less than t to zero (off)• Set any pixels greater than or equal to t to one (on)

Page 41: Edges and Binary Images Dan Witzner Hansen. Previously???

Binary images

Page 42: Edges and Binary Images Dan Witzner Hansen. Previously???

Binary images

• Two pixel values– Foreground and background– Mark region(s) of interest

Page 43: Edges and Binary Images Dan Witzner Hansen. Previously???

Thresholding• Given a grayscale image or an intermediate matrix

threshold to create a binary output.

Gradient magnitude

Looking for pixels where gradient is strong.

fg_pix = find(gradient_mag > t);

Example: edge detection

Page 44: Edges and Binary Images Dan Witzner Hansen. Previously???

=-

Thresholding• Given a grayscale image or an intermediate matrix

threshold to create a binary output.

Example: background subtraction

Looking for pixels that differ significantly from the “empty” background.fg_pix = find(diff > t);

Page 45: Edges and Binary Images Dan Witzner Hansen. Previously???

Thresholding• Given a grayscale image or an intermediate matrix

threshold to create a binary output.

Example: intensity-based detection

Looking for dark pixels

fg_pix = find(im < 65);

Page 46: Edges and Binary Images Dan Witzner Hansen. Previously???

Thresholding• Given a grayscale image or an intermediate matrix

threshold to create a binary output.

Example: color-based detection

Looking for pixels within a certain hue range.

fg_pix = find(hue > t1 & hue < t2);

Page 47: Edges and Binary Images Dan Witzner Hansen. Previously???

Issues

• How to indentify multiple regions of interest? – Count objects– Compute further features per object

• What to do with “noisy” binary outputs?– Holes– Extra small fragments

Page 48: Edges and Binary Images Dan Witzner Hansen. Previously???

Issues

• How to demarcate multiple regions of interest? – Count objects– Compute further features per object

• What to do with “noisy” binary outputs?– Holes– Extra small fragments

Page 49: Edges and Binary Images Dan Witzner Hansen. Previously???

Morphological operators

• Change the shape of the foreground regions/ objects.

• Useful to clean up result from thresholding

• Basic operators are:– Dilation– Erosion

• Combine– Opening– Closing

Page 50: Edges and Binary Images Dan Witzner Hansen. Previously???

Dilation• Expands connected components• Grow features• Fill holes

Before dilation After dilation

Page 51: Edges and Binary Images Dan Witzner Hansen. Previously???

Erosion• Erode connected components• Shrink features• Remove bridges, branches, noise

Before erosion After erosion

Page 52: Edges and Binary Images Dan Witzner Hansen. Previously???

Structuring elements

• Masks of varying shapes and sizes used to perform morphology, for example:

• Scan mask across foreground pixels to transform the binary image

>> help strel

Page 53: Edges and Binary Images Dan Witzner Hansen. Previously???

Dilation vs. Erosion

At each position:• Dilation: if current pixel is foreground, OR the

structuring element with the input image.

Page 54: Edges and Binary Images Dan Witzner Hansen. Previously???

Example for Dilation

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

1 1Output Image

111

SExfxg )()(

Page 55: Edges and Binary Images Dan Witzner Hansen. Previously???

Example for Dilation

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

1 1 0Output Image

111

Page 56: Edges and Binary Images Dan Witzner Hansen. Previously???

Example for Dilation

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

1 1 0 0Output Image

111

Page 57: Edges and Binary Images Dan Witzner Hansen. Previously???

Example for Dilation

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

1 1 0 1 1 1Output Image

111

Page 58: Edges and Binary Images Dan Witzner Hansen. Previously???

Example for Dilation

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

1 1 0 1 1 1 1Output Image

111

Page 59: Edges and Binary Images Dan Witzner Hansen. Previously???

Example for Dilation

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

1 1 0 1 1 1 1 1Output Image

111

Page 60: Edges and Binary Images Dan Witzner Hansen. Previously???

Example for Dilation

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

1 1 0 1 1 1 1 1Output Image

111

Page 61: Edges and Binary Images Dan Witzner Hansen. Previously???

Example for Dilation

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

1 1 0 1 1 1 1 1 1 1Output Image

111

Note that the object gets bigger and holes are filled.>> help imdilate

Page 62: Edges and Binary Images Dan Witzner Hansen. Previously???

Dilation vs. Erosion

At each position:• Dilation: if current pixel is foreground, OR the

structuring element with the input image.• Erosion: if every pixel under the structuring

element’s nonzero entries is foreground, OR the current pixel with S.

Page 63: Edges and Binary Images Dan Witzner Hansen. Previously???

Example for Erosion (1D)

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

0Output Image

111

SExfxg O)()( _

Page 64: Edges and Binary Images Dan Witzner Hansen. Previously???

Example for Erosion (1D)

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

0 0Output Image

111

SExfxg O)()( _

Page 65: Edges and Binary Images Dan Witzner Hansen. Previously???

Example for Erosion

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

0 0 0Output Image

111

Page 66: Edges and Binary Images Dan Witzner Hansen. Previously???

Example for Erosion

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

0 0 0 0Output Image

111

Page 67: Edges and Binary Images Dan Witzner Hansen. Previously???

Example for Erosion

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

0 0 0 0 0Output Image

111

Page 68: Edges and Binary Images Dan Witzner Hansen. Previously???

Example for Erosion

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

0 0 0 0 0 1Output Image

111

Page 69: Edges and Binary Images Dan Witzner Hansen. Previously???

Example for Erosion

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

0 0 0 0 0 1 0Output Image

111

Page 70: Edges and Binary Images Dan Witzner Hansen. Previously???

Example for Erosion

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

0 0 0 0 0 1 0 0Output Image

111

Page 71: Edges and Binary Images Dan Witzner Hansen. Previously???

Example for Erosion

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

0 0 0 0 0 1 0 0 0Output Image

111

Page 72: Edges and Binary Images Dan Witzner Hansen. Previously???

Example for Erosion

1 0 0 0 1 1 1 0 1 1Input image

Structuring Element

0 0 0 0 0 1 0 0 0 1Output Image

111

Note that the object gets smaller>> help imerode

Page 73: Edges and Binary Images Dan Witzner Hansen. Previously???

Erosion example

Page 74: Edges and Binary Images Dan Witzner Hansen. Previously???

Opening• Erode, then dilate• Remove small objects, keep original shape• Idempotent: Repeated operations has no further

effects!

Before opening After opening

Page 75: Edges and Binary Images Dan Witzner Hansen. Previously???

Closing• Dilate, then erode • Fill holes, but keep

original shape• Idempotent

Before closing After closing

Page 76: Edges and Binary Images Dan Witzner Hansen. Previously???

Combine Open and close

Page 77: Edges and Binary Images Dan Witzner Hansen. Previously???

Morphology operators on grayscale images

• Dilation and erosion typically performed on binary images.• If image is grayscale: for dilation take the neighborhood max, for erosion take

the min.

original dilated eroded

Page 78: Edges and Binary Images Dan Witzner Hansen. Previously???

Matlab• N = hist(Y,M)• L = bwlabel (BW,N);• STATS = regionprops(L,PROPERTIES) ;

– 'Area'– 'Centroid' – 'BoundingBox' – 'Orientation‘, …

• IM2 = imerode(IM,SE);• IM2 = imdilate(IM,SE);• IM2 = imclose(IM, SE);• IM2 = imopen(IM, SE);

Page 79: Edges and Binary Images Dan Witzner Hansen. Previously???

Example using binary image analysis: segmentation of a liver

Slide credit: Li Shen

Page 80: Edges and Binary Images Dan Witzner Hansen. Previously???

Example using binary image analysis:Bg subtraction + blob detection

Page 81: Edges and Binary Images Dan Witzner Hansen. Previously???

Connected components• Identify distinct regions of “connected pixels”

Shapiro and Stockman

Page 82: Edges and Binary Images Dan Witzner Hansen. Previously???

Connectedness

• Defining which pixels are considered neighbors

4-connected 8-connected

Page 83: Edges and Binary Images Dan Witzner Hansen. Previously???

Connected components

• We’ll consider a sequential algorithm that requires only 2 passes over the image.

• Input: binary image• Output: “label” image, where

pixels are numbered per their component

• [Note, in this example, “foreground” is denoted with black.]

Page 84: Edges and Binary Images Dan Witzner Hansen. Previously???

Depth First Search

• Goal. Find all vertices connected to s.

• Depth first search. To visit a vertex v:– Mark v as visited.– Recursively visit all unmarked vertices w

adjacent to v.

• Running time. O(E) since each edgeexamined at most twice.

Page 85: Edges and Binary Images Dan Witzner Hansen. Previously???

Reachability Application: Flood Fill• Flood fill. Given lime green pixel in an image, change color of entire blob of

neighboring lime pixels to blue.– Vertex: pixel.– Edge: two neighboring lime pixels.– Blob: all pixels reachable from chosen lime pixel.

recolor lime green blob to bluerecolor lime green blob to blue

Page 86: Edges and Binary Images Dan Witzner Hansen. Previously???

Slide from J. Neira

Sequential connected components

Page 87: Edges and Binary Images Dan Witzner Hansen. Previously???

Sequential connected components

Page 88: Edges and Binary Images Dan Witzner Hansen. Previously???

Region properties• Given connected components, can compute simple

features per blob, such as:– Area (number of pixels in the region)– Centroid (average x and y position of pixels in the region)– Bounding box (min and max coordinates)

• How could such features be useful?

A1=200A2=170

Page 89: Edges and Binary Images Dan Witzner Hansen. Previously???

Summary• Filters allow local image neighborhood to influence our

description and features– Smoothing to reduce noise

– Derivatives to locate contrast, gradient

– Templates, matched filters to find designated pattern.

• Edge detection processes the image gradient to find curves, or chains of edges.

• Binary image analysis useful to manipulate regions of interest– Connected components

– Morphological operators (local operator, but different than convolution)

Page 90: Edges and Binary Images Dan Witzner Hansen. Previously???

Assignment1 – Eye /Gaze tracking

Page 91: Edges and Binary Images Dan Witzner Hansen. Previously???

What to be done

• Week 5. Simple eye tracking• Week 6. Contour detection & Fitting• Week 7. Gaze estimation (may be subject to

change)

Page 92: Edges and Binary Images Dan Witzner Hansen. Previously???

• Try the techniques learned today in the assignment to see if they could can improve your results . You might be lucky

Page 93: Edges and Binary Images Dan Witzner Hansen. Previously???

Summary• Operations, tools

• Features, representations

Edges, gradients

Blobs/regions

Color distributions

Local patterns

Derivative filters

Smoothing, morphology

Thresholding

Connected components

Matched filters

Histograms