78
Lecture 3: Binary image analysis Thursday, Sept 6

Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

  • Upload
    dothuan

  • View
    220

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Lecture 3: Binary image analysis

Thursday, Sept 6

Page 2: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

• Sudheendra’s office hours– Mon, Wed 1-2 pm– ENS 31NR

• Forsyth and Ponce book

Page 3: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Binary images

• Two pixel values• Foreground and background• Regions of interest

Page 4: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Constrained image capture setting

R. Nagarajan et al. A real time marking inspection schemefor semiconductor industries, 2006

Page 5: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Documents, text

Page 6: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Medical, bio data

Page 7: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Intermediate low-level cues

- =

Edges

Motion

Orientation

NASA robonauthttp://robonaut.jsc.nasa.gov/status/October_prime.htm

Page 8: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Shape

Silhouette

visual hulls

Medial axis

Page 9: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Outline

• Thresholding• Connected components• Morphological operators• Region properties

– Spatial moments– Shape

• Distance transforms– Chamfer distance

Page 10: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Thresholding

• Grayscale -> binary mask• Useful if object of interest’s intensity

distribution is distinct from background

• Examplehttp://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/FITZGIBBON/simplebinary.html

Page 11: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Selecting thresholds

• Partition a bimodal histogram• Fit Gaussians• Dynamic or local thresholds

Page 12: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

A nice case: bimodal intensity histograms

Ideal histogram, light object on dark background

Actual observed histogram with noise

Images: http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/OWENS/LECT2/node3.html

Page 13: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

• Example• Thresholding a bimodal histogram

• Otsu method (1979) : automatically select threshold by minimizing the weighted within-group variance of the two groups of pixels separated by the threshold.

A nice case: bimodal intensity histograms

Page 14: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Not so nice cases

• Threshold selection is an art, not a science

Shapiro and Stockman

Page 15: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Connected components

• Identify distinct regions

Shapiro and Stockman

Page 16: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Connected components

P. Duygulu

Page 17: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Connectedness

• Which pixels are considered neighbors

Image from http://www-ee.uta.edu/Online/Devarajan/ee6358/BIP.pdf

4-connected 8-connected

Page 18: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Connected components

• Various algorithms to compute– Recursive (in memory)– Two rows at a time (image not necessarily in

memory)– Parallel propagation strategy

Page 19: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Recursive connected components

• Demo http://www.cosc.canterbury.ac.nz/mukundan/covn/Label.html

• Find an unlabeled pixel, assign it a new label

• Search to find its neighbors, and recursively repeat to find their neighbors tilthere are no more

• Repeat

Page 20: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Sequential connected components

Slide from J. Neira

Page 21: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After
Page 22: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Morphological operators

• Dilation• Erosion

• Open, close

Page 23: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Dilation• Expands connected components• Grow features• Fill holes

Before dilation After dilation

Page 24: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Structuring elements

• Masks of varying shapes used to perform morphology

• Scan mask across foreground pixels to transform the binary image

etc

Page 25: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Dilation / Erosion

• Dilation: if current pixel is foreground, set all pixels under S to foreground in output (OR)

• Erosion: if every pixel under S is foreground, leave as is; otherwise, set current pixel to background in output

Page 26: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Dilation (1D)

SExfxg ⊕= )()(

1101110001Input image

Structuring Element

11Output Image

111

Adapted from T. Moeslund

Page 27: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Dilation

1101110001Input image

Structuring Element

11Output Image

111

Page 28: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Dilation

1101110001Input image

Structuring Element

011Output Image

111

Page 29: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Dilation

1101110001Input image

Structuring Element

0011Output Image

111

Page 30: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Dilation

1101110001Input image

Structuring Element

111011Output Image

111

Page 31: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Dilation

1101110001Input image

Structuring Element

1111011Output Image

111

Page 32: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Dilation

1101110001Input image

Structuring Element

11111011Output Image

111

Page 33: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Dilation

1101110001Input image

Structuring Element

11111011Output Image

111

Page 34: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Dilation

1101110001Input image

Structuring Element

1111111011Output Image

111

The object gets bigger and holes are filled!

Page 35: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

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

Before erosion After erosion

Page 36: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Erosion (1D)

1101110001Input image

Structuring Element

0Output Image

111SExfxg O)()( = _

Page 37: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Erosion (1D)

1101110001Input image

Structuring Element

00Output Image

111SExfxg O)()( = _

Page 38: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Erosion

1101110001Input image

Structuring Element

000Output Image

111

Page 39: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Erosion

1101110001Input image

Structuring Element

0000Output Image

111

Page 40: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Erosion

1101110001Input image

Structuring Element

00000Output Image

111

Page 41: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Erosion

1101110001Input image

Structuring Element

100000Output Image

111

Page 42: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Erosion

1101110001Input image

Structuring Element

0100000Output Image

111

Page 43: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Erosion

1101110001Input image

Structuring Element

00100000Output Image

111

Page 44: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Erosion

1101110001Input image

Structuring Element

000100000Output Image

111

Page 45: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Example for Erosion

1101110001Input image

Structuring Element

1000100000Output Image

111

The object gets smaller

Page 46: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Dilation / Erosion

• Dilation: if current pixel is foreground, set all pixels under S to foreground in output (OR)

• Erosion: if every pixel under S is foreground, leave as is; otherwise, set current pixel to background in output

Images by P. Duygulu

Page 47: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Opening

• Erode, then dilate• Remove small objects, keep original shape

Before opening After opening

Page 48: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

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

Before closing After closing

Page 49: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Application: blob tracking

Absolute differences from frame to frame

Page 50: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Threshold

Page 51: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Erode

Page 52: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Application: blob tracking

• Background subtraction + blob tracking

Page 53: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Application: segmentation of a liver

Slide credit: Li Shen

Page 54: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Region properties

Some useful features can be extracted once we have connected components, including

• Area• Centroid• Extremal points, bounding box• Circularity• Spatial moments

Page 55: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Area and centroid

Shapiro & Stockman

Page 56: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Circularity

Shapiro & Stockman

[Haralick]

Page 57: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Invariant descriptors

[a1, a2, a3,…] [b1, b2, b3,…] Feature space distance

Often want features independent of position, orientation, scale.

Page 58: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Central moments

S is a subset of pixels (region).Central (j,k)th moment defined as:

• Invariant to translation of S.

Page 59: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Central moments

• 2nd central moment: variance• 3rd central moment: skewness• 4th central moment: kurtosis

Page 60: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Axis of least second moment

• Invariance to orientation? Need a common alignment

Axis for which the squared distance to 2d object points is minimized.

Page 61: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Distance transform

• Image reflecting distance to nearest point in point set (e.g., foreground pixels).

4-connected adjacency

8-connected adjacency

Page 62: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Distance transform

Edge image Distance transform image

Page 63: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Distance transform (1D)

Adapted from D. Huttenlocher

Page 64: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Distance Transform (2D)

Adapted from D. Huttenlocher

Page 65: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Chamfer distance

• Average distance to nearest feature

Edge image Distance transform image

D. Gavrila, DAGM 1999

Page 66: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Chamfer distance

D. Gavrila, DAGM 1999

Edge image Distance transform image

More on this and other distances later

Page 67: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Generalized distance transforms

• Same forward/backward algorithm applicable with different initialization

• Initialize with function values F(x,y):

Page 68: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

The University of

Ontario

The University of

Ontario

Distance Transform vs.Generalized Distance Transform

Assuming

thenis standard Distance Transform (of image features)

⎭⎬⎫

⎩⎨⎧

∞=

..0

)(WO

featureimageisppixelifpF

)( pF

)( pD

∞+ ∞+∞+

Locations of binary image features

p

||||min)}(||{||min)(0)(:

qpqFqppDqFqq

−=+−==

Slide credit Y. Boykov

Page 69: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

The University of

Ontario

The University of

Ontario

Distance Transform vs.Generalized Distance Transform

For general

is Generalized Distance Transform of

)}(||{||min)( qFqppDq

+−=

)( pF

F(p) may represent non-binary image features (e.g. image intensity gradient)

)( pF

)( pF

)( pD

Slide credit Y. Boykov

Location of q is close to p, and F(q) is small there

Page 70: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

Binary images

• Pros– Can be fast to compute, easy to store– Simple processing techniques available– Lead to some useful compact shape descriptors

• Cons– Hard to get “clean” silhouettes, noise common in

realistic scenarios– Can be too coarse of a representation– Not 3d

Page 71: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

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);• [D,L] = bwdist(BW,METHOD);

Page 72: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

• Everything is matrix

Tutorial adapted from W. Freeman, MIT 6.896

Page 73: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

• Matrix index

Page 74: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

• Manipulate matrices

Page 75: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

• Manipulate matrices

Page 76: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

• Scripts and functions– Scripts are m-files containing MATLAB statements

– Functions are like any other m-file, but they accept arguments

– Name the function file the same as the function name

Page 77: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

• Try to code in matrix ways

Page 78: Lecture 3: Binary image analysis - Department of …grauman/courses/378/slides/lecture3...• Erode, then dilate • Remove small objects, keep original shape Before opening After

• whos• help• lookfor• clear / clear x• save• load