18
1 Image Analysis Segmentation by Clustering University of Ioannina - Department of Computer Science Christophoros Nikou [email protected] Images taken from: D. Forsyth and J. Ponce. Computer Vision: A Modern Approach, Prentice Hall, 2003. Computer Vision course by Svetlana Lazebnik, University of North Carolina at Chapel Hill. Computer Vision course by Kristen Grauman, University of Texas at Austin. 2 Image Segmentation Obtain a compact representation of the image to be used for further processing. Group together similar pixels Image intensity is not sufficient to perform semantic segmentation C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011 semantic segmentation Object recognition Decompose objects to simple tokens (line segments, spots, corners) Finding buildings in images Fit polygons and determine surface orientations. Video summarization Shot detection 3 Image Segmentation (cont.) – Bottom-up or top-down process? – Supervised or unsupervised? C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011 Berkeley segmentation database: http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/segbench/ image human segmentation 4 Image Segmentation (cont.) • Major approaches –Basic techniques (thresholding, region growing morphological Goal: separate an image into “coherent” regions. C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011 region growing, morphological watersheds). –Clustering. –Model fitting. –Probabilistic methods. Basic techniques also follow a clustering principle. We will examine more advanced clustering methods later. 5 Segmentation by Clustering • Grouping and the Gestalt school. • K-means • Mean shift •Spectral methods C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011 –Average association –Average cut –Normalized cut • Textons • Segmentation as a first step to image understanding. 6 Segmentation and Grouping Image analysis and computer vision are inference problems We have measurements and a model. We would like to know what Grouping (or clustering) collect together tokens (pixels, points surface elements…) that “belong together”. Fitting C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011 caused the measurement. Obtain a compact representation from an image/motion sequence/set of tokens. Should support application. Broad theory is absent at present. associate a model with tokens. – issues which model? which token goes to which element? how many elements in the model?

Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

1

Image Analysis

Segmentation by Clustering

University of Ioannina - Department of Computer Science

Christophoros [email protected]

Images taken from:D. Forsyth and J. Ponce. Computer Vision: A Modern Approach, Prentice Hall, 2003.Computer Vision course by Svetlana Lazebnik, University of North Carolina at Chapel Hill.Computer Vision course by Kristen Grauman, University of Texas at Austin.

2 Image Segmentation

• Obtain a compact representation of the image to be used for further processing.

• Group together similar pixels• Image intensity is not sufficient to perform

semantic segmentation

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

semantic segmentation– Object recognition

• Decompose objects to simple tokens (line segments, spots, corners)

– Finding buildings in images• Fit polygons and determine surface orientations.

– Video summarization• Shot detection

3 Image Segmentation (cont.)– Bottom-up or top-down process?– Supervised or unsupervised?

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Berkeley segmentation database:http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/segbench/

image human segmentation

4 Image Segmentation (cont.)

• Major approaches–Basic techniques (thresholding,

region growing morphological

Goal: separate an image into “coherent” regions.

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

region growing, morphological watersheds).

–Clustering.–Model fitting.–Probabilistic methods.

Basic techniques also follow a clustering principle. We will examine more advanced clustering methods later.

5 Segmentation by Clustering

• Grouping and the Gestalt school.• K-means• Mean shift• Spectral methods

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

p–Average association–Average cut–Normalized cut

• Textons• Segmentation as a first step to image understanding.

6 Segmentation and Grouping

• Image analysis and computer vision are inference problems

– We have measurements and a model.

– We would like to know what

• Grouping (or clustering)– collect together tokens

(pixels, points surface elements…) that “belong together”.

• Fitting

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

caused the measurement.

• Obtain a compact representation from an image/motion sequence/set of tokens.

• Should support application.• Broad theory is absent at

present.

g– associate a model with

tokens.– issues

• which model?• which token goes to

which element?• how many elements in

the model?

Page 2: Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

2

7 Perceptual Organization

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• Why do these tokens belong together? • The human visual system performs surprisingly

well.• How could we make a computer system “see”

as a human?

8 Basic ideas of grouping in humans

• Figure-ground di i i ti

• Gestalt properties– elements in a collection

of elements can have properties that result from relationships (M ll L ff t)

The Gestalt (“shape”) school: Grouping is the key to human visual perception.

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

discrimination– grouping can be seen

in terms of allocating some elements to a figure, some to ground.

– impoverished theory.

(Muller-Lyer effect)• gestaltqualitat

– A series of factors affect whether elements should be grouped together.

9 The Gestalt School

Psychologists identified series of factors that predispose sets of elements to be grouped in the human visual system.

“I stand at the window and see a house, trees, sky. Theoretically I might say there were 327

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Theoretically, I might say there were 327 brightnesses and nuances of colour. Do I have “327”? No, I have house, sky and trees.”

Max Wertheimer (1880-1943). Untersuchungen zur Lehre von der Gestalt. Psychologische Forschung, Vol. 4, pp. 301-350, 1923.

10 The Gestalt School (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• Figure-ground discrimination• White circle on a black background?• A black rectangle with a hole on it?

11 The Gestalt School (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• Subjective contours• Scattered tokens?• Occlusion?

12

• The Muller-Lyer illusion:• You can’t look at this figure and ignore the

arrowheads.

The Gestalt School (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Page 3: Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

3

13

• Elements in a collection can have properties that result from relationships.

– “The whole is greater than the sum of its parts”

subjective contours occlusion

The Gestalt School (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

subjective contours occlusion

familiar configuration

14 The Gestalt School (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

15 Gestalt factors

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Intuitive factors leading to grouping are very difficult to translate into algorithms.

16 Gestalt factors in natural images

Similarity

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

17Gestalt factors in natural images

(cont.)Symmetry

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

18Gestalt factors in natural images

(cont.)Common fate

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Page 4: Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

4

19Gestalt factors in natural images

(cont.)Proximity

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

20 Gestalt factors (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

What can you see ?

21 Gestalt factors (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

The visual system is helped by the evidence that the tokens are separated for a reason: occlusion.

22 Gestalt factors (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

What can you see ?

23 Gestalt factors (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Continuity through occlusion (is it a cube?)

24 Gestalt factors (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Elevator buttons at Computer Science building, U.C. at Berkeley.

Page 5: Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

5

25 Gestalt factors (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

26 Gestalt factors (cont.)

• Even psychologists argued which factors are more dominant than the others.

• Today, Gestalt factors are important but they should be considered as consequences

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

they should be considered as consequences of a more general grouping mechanism and not as the mechanism itself.

• Which is this mechanism?• We cannot answer yet.

27Application: Background

Subtraction• Simple segmentation

algorithms work well when we know what to look for.

• If we know what the background looks like it

• Approach:– use a weighted moving

average (over time) to estimate background image.

• Distant frames are attributed smaller weights (e g the

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

background looks like, it is easy to identify “interesting bits”.

• Applications– Person in an office– Tracking cars on a road– Surveillance

smaller weights (e.g. the weather changes smoothly from rain to sunshine).

• This is a filter smoothing a function of time.

– Subtract from current frame.

– Large absolute values are interesting pixels.

– The method is powerful at coarse scales.

28Application: Background

Subtraction (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• Every 5th frame of the sequence is shown.• The child moves from one side to the other.

29Application: Background

Subtraction (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Background estimation averaging frames of size 80x60.The child spent more time on the right side.

Pixels of a frame whose difference from the average exceed a threshold.

Pixels of a frame whose difference from the average exceed asmaller threshold.

In both thresholds, there are excess pixels and missing pixels.

30Application: Background

Subtraction (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Pixels of a frame whose difference from the average exceed a threshold.

Background estimation by a more sophisticated method (EM).

There are also excess pixels and missing pixels.

Page 6: Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

6

31Application: Background

Subtraction (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

The high frequency texture of the sofa pattern was mistaken for the child.

This is because small movements can cause misregistration of spatial content carrying high frequencies.The same results at a higher

resolution (160x120).

32Application: Shot Boundary

detection• Video sequences are composed of shots:

– Shorter subsequences showing largely the same object.

• It is very helpful to represent a video as a collection of shots

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

collection of shots– Each shot is represented by a key frame.– Video browsing retrieval.

• Approach: find frames that are significantly different from the previous frame.

– Take into account that object and background may move.

– Simple difference will not do the job.

33Application: Shot Boundary

detection (cont.)• Other approaches:

– Histogram based methods• Compute color histograms and take the difference.• Insensitive to motion and camera jitters.

– Block comparison

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• Avoids difficulties of color histograms.– A red object disappearing in the bottom is equivalent to a red

object appearing in the top.

– Edge differencing• Compare edge maps (corresponding edges between

frames).

• These are ad hoc methods but usually sufficient for standard problems.

34 Segmentation by Clustering

• Most image segmentation algorithms are based on clustering.

• Agglomerative clustering– Each data item is regarded as a cluster.

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

g– Clusters are recursively merged.

• Divisive clustering– The entire data set is regarded as a cluster.– Clusters are recursively split.

35 Segmentation by Clustering (cont.)

• Major issue:– What is a good inter-cluster distance?

• The distance between the closest elements in the clusters (single-link clustering)

– Tends to form extended clusters

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

– Tends to form extended clusters.

• The maximum distance between an element of the first and one of the second cluster (complete-link clustering)

– Tends to provide rounded clusters.

• The average distance between elements in the clusters (group average clustering)

– Tends to form rounded clusters also.

36 Segmentation by Clustering (cont.)

• Major issue:– How many clusters are there?

• Difficult to answer if there is no model for the process that generated the data.

• The hierarchy may be displayed in the form of a

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• The hierarchy may be displayed in the form of a dendrogram.

– A representation of cluster structure displaying cluster distances.

– We may determine the number of clusters from the dendrogram.

Page 7: Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

7

37 Segmentation by Clustering (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• A dendrogram obtained by agglomerative clustering.

• Selecting a particular value of distance then a horizontal line at that distance splits the dendrogram into clusters.

• It gives some insight into how good are the clusters.

38 Segmentation by Clustering (cont.)

• Common distances in image analysis involve color, texture and difference in position (to provide blobby segments).

• Problem for using agglomerative or divisive clustering: there are a lot of pixels in the image

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

clustering: there are a lot of pixels in the image.– Too big dendrograms.– Impractical to look for the best split (merge) of

clusters).• Divisive methods are modified by using a summary of a

cluster (histogram).• Agglomerative methods also use coordinates for inter-

cluster distance computation, and merging is performed on neighboring clusters.

39 K-Means for Segmentation• Choose a fixed number of

clusters.• Choose cluster centers and

point-cluster allocations to minimize error

• We can’t do this by search, b th t

• Algorithm– fix cluster centers; allocate

points to closest cluster.– fix allocation; compute best

cluster centers• We could use any set of

features for which we can

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

because there are too many possible allocations.

• It minimizes the dispersion of the data from the centers.

features for which we can compute a distance (careful about scaling each dimension).

(clusters,data) ( ) ( )th

Tj i j i

i clusters j i cluster

E x c x c∈ ∈

⎧ ⎫⎪ ⎪= − −⎨ ⎬⎪ ⎪⎩ ⎭

∑ ∑

40 K-Means for Segmentation (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011 Source: K. Grauman

41 K-Means for Segmentation (cont.)K=11 K=11

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Image Intensity-based clusters Color-based clusters

• Segments are not necessarily connected using only color.• Absence of texture features is obvious (red cabbage).

42 K-Means for Segmentation (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

K=11 (4 segments are shown here).

Page 8: Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

8

43 K-Means for Segmentation (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011 Source: K. Grauman

44 K-Means for Segmentation (cont.)K=20 (5 segments are shown here).

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• Position is also used as part of the feature vector.• Notice that the large background is broken.

45 K-Means for Segmentation (cont.)

• Pros– Very simple method.– Converges to a local minimum.

• Cons

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

– Memory-intensive.– Need to pick K.– Sensitive to initialization.– Sensitive to outliers.– Finds “spherical” clusters.

46 Segmentation by Mean Shift

• An advanced and versatile technique for clustering-based segmentation.

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

http://www.caip.rutgers.edu/~comanici/MSPAMI/msPamiResults.html

D. Comaniciu and P. Meer, Mean Shift: A Robust Approach toward Feature Space Analysis, IEEE Trans. on Pattern Analysis and Machine Intelligence, 2002.

47

• The mean shift algorithm seeks modes or local maxima of density in the feature space.

Mean shift algorithm (cont.)

imageFeature space

(L*u*v* color values)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

( )

48

Searchwindow

Center ofmass

Mean shift algorithm (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Mean Shiftvector

Slide by Y. Ukrainitz & B. Sarel

Page 9: Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

9

49

Searchwindow

Center ofmass

Mean shift algorithm (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Mean Shiftvector

Slide by Y. Ukrainitz & B. Sarel

50

Searchwindow

Center ofmass

Mean shift algorithm (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Mean Shiftvector

Slide by Y. Ukrainitz & B. Sarel

51

Searchwindow

Center ofmass

Mean shift algorithm (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Mean Shiftvector

Slide by Y. Ukrainitz & B. Sarel

52

Searchwindow

Center ofmass

Mean shift algorithm (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Mean Shiftvector

Slide by Y. Ukrainitz & B. Sarel

53

Searchwindow

Center ofmass

Mean shift algorithm (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Mean Shiftvector

Slide by Y. Ukrainitz & B. Sarel

54

Searchwindow

Center ofmass

Mean shift algorithm (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011Slide by Y. Ukrainitz & B. Sarel

Page 10: Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

10

55

• Cluster: all data points in the attraction basin of a mode.

• Attraction basin: the region for which all trajectories lead to the same mode.

Mean shift algorithm (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011Slide by Y. Ukrainitz & B. Sarel

56 Mean Shift Fundamentals

1

1( ) ( )n

ii

P Kn =

= ∑x x - xEstimate the density at a point x from a number of sample data points x1…xn

( )21 1( )E

cK

⎧ − ≤⎪= ⎨x x

x

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• Epanechnikov Kernel

• Uniform Kernel

• Normal Kernel

( ) 0 otherwise

EK ⎨⎪⎩

x

1( )

0 otherwiseUc

K⎧ ≤

= ⎨⎩

xx

21( ) exp 2NK c ⎛ ⎞= ⋅ −⎜ ⎟

⎝ ⎠x x

57 Mean Shift Fundamentals (cont.)

1

1 ( ) ( )n

ii

P Kn =

= ∑x x - x∇ ∇ Give up estimating the PDF !Estimate ONLY the gradient

2

( ) iiK ck

h⎛ ⎞

= ⎜ ⎟⎜ ⎟x - xx - xUsing the

K l f

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

( )i h⎜ ⎟⎜ ⎟⎝ ⎠Kernel form:

We get :

1

1 1

1

( )

n

i in ni

i i ni i

ii

gc cP k gn n g

=

= =

=

⎡ ⎤⎢ ⎥⎡ ⎤ ⎢ ⎥∇ = ∇ = −⎢ ⎥ ⎢ ⎥⎣ ⎦⎢ ⎥⎣ ⎦

∑∑ ∑

xx xi

Size of window

g( ) ( )k′= −x x

58 Mean Shift Fundamentals (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

1

1 1

1

( )

n

i in ni

i i ni i

ii

gc cP k gn n g

=

= =

=

⎡ ⎤⎢ ⎥⎡ ⎤ ⎢ ⎥∇ = ∇ = −⎢ ⎥ ⎢ ⎥⎣ ⎦⎢ ⎥⎣ ⎦

∑∑ ∑

xx xi

g( ) ( )k′= −x x

59 Mean Shift Fundamentals (cont.)2

21

21 1

1

( )

ni

in n ii

ini i i

i

ghc cP k g

n n hg

h

=

= =

=

⎡ ⎤⎛ ⎞⎢ ⎥⎜ ⎟⎜ ⎟⎡ ⎤⎛ ⎞ ⎢ ⎥⎝ ⎠⎢ ⎥∇ = ∇ = ⎜ ⎟ −⎢ ⎥⎜ ⎟ ⎛ ⎞⎢ ⎥ ⎢ ⎥⎝ ⎠⎣ ⎦ ⎜ ⎟⎢ ⎥⎜ ⎟

⎝ ⎠⎣ ⎦

∑∑ ∑

x - xx

x - xx x

x - xi

Density estimation with another kernel!

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Density estimation with another kernel!

Simple Mean Shift procedure:• Compute mean shift vector

•Translate the Kernel window by m(x)

2

1

2

1

( )

ni

ii

ni

i

gh

gh

=

=

⎡ ⎤⎛ ⎞⎢ ⎥⎜ ⎟⎜ ⎟⎢ ⎥⎝ ⎠= −⎢ ⎥⎛ ⎞⎢ ⎥⎜ ⎟⎢ ⎥⎜ ⎟

⎝ ⎠⎣ ⎦

x - xx

m x xx - x

g( ) ( )k′= −x x

60

• Find features (color, gradients, texture, etc).• Initialize windows at individual feature points.• Perform mean shift for each window until convergence.• Merge windows that end up near the same “peak” or mode.

Mean shift clustering/segmentation

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Page 11: Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

11

61 Mean shift segmentation results

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011http://www.caip.rutgers.edu/~comanici/MSPAMI/msPamiResults.html

62Mean shift segmentation results

(cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

63Mean shift segmentation results

(cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

64 Mean shift pros and cons

• Pros– Does not assume spherical clusters.– Just a single parameter (window size). – Finds variable number of modes.

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

– Robust to outliers.• Cons

– Output depends on window size.– Computationally expensive.– Does not scale well with dimension of feature

space.

65 Images as graphs

wiji

j

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• Node for every pixel.• Edge between every pair of pixels (or every pair

of “sufficiently close” pixels).• Each edge is weighted by the affinity or

similarity of the two nodes.Source: S. Seitz

66 Segmentation by graph partitioning

– Cut the graph into segments.– Delete links that cross

between segments.– Easiest to break links that

have low affinity

wiji

j

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

have low affinity.• similar pixels should be in the

same segments.• dissimilar pixels should be in

different segments.

A B CSource: S. Seitz

Page 12: Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

12

67 Measuring affinity

• Each pixel is represented by a feature vector, and a distance function is defined.

• We may convert the distance between two feature vectors into an affinity with the help

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

of a generalized Gaussian kernel:

22

1exp dist( , )2ij i jw x xσ

⎛ ⎞= −⎜ ⎟⎝ ⎠

68 Scale affects affinity

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• Small σ: group nearby points.• Large σ: group distant points.

σ=0.1 σ=0.2 σ=1.0

69 Graph cut

• Set of edges whose removal makes a graph di t d

A B

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

disconnected.• Cost of a cut: sum of weights of cut edges.

• A graph cut gives us a segmentation– What is a “good” graph cut and how do we find

one?Source: S. Seitz

,

( , ) iji A j B

cut A B w∈ ∈

= ∑

70 Minimum cut

• We can have a segmentation by finding the minimum cut in a graph– Efficient algorithms exist.

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Minimum cut example

71 Minimum cut (cont.)

• We can have a segmentation by finding the minimum cut in a graph– Efficient algorithms exist.

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Minimum cut example

72 Minimum cut (cont.)

• Drawback: minimum cut tends to cut off very small, isolated components.

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

Ideal Cut

Cuts with lesser weightthan the ideal cut

* Slide from Khurram Hassan-Shafique CAP5415 Computer Vision 2003

Page 13: Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

13

73 Eigenvectors and Segmentation

• Consider the image as a graph G(V,E)– with V being the set of vertices (pixels i=1,…N).– E are the edges.– W is the affinity matrix between pixels.

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• We want to segment it into two segments: – segment A containing “similar pixels” and

segment and B containing the rest of the image.

74Eigenvectors and Segmentation

(cont.)• We allow elements associated with

cluster A to have a continuous weight ai.– Large value for ai means a strong

connection to the cluster.

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• A good cluster is one with elements having:– large weights ai.– large values between them in the affinity

matrix W.

75Eigenvectors and Segmentation

(cont.)• An objective function expressing this assumption is:

[ ]11 12 1 1

21 22 2 21 2

1 1( )

N

N NN T

i ij j Ni i

w w w aw w w a

E a a w a a a a a Wa= =

⎡ ⎤ ⎡ ⎤⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥= = =⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥

∑∑

……

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

1 2N NN Nw w w a⎢ ⎥ ⎢ ⎥⎣ ⎦ ⎣ ⎦…

• E(a) is a sum of products of the form:• ai : association of element i with the cluster.• wij : affinity between elements i and j.• aj : association of element j with the cluster.

76Eigenvectors and Segmentation

(cont.)• We now estimate vector a maximizing:

( ) TE a a Wa=

subject to: 2|| || 1Ta a a= =

because scaling scales the objective function

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

because scaling a scales the objective function.

• The Lagrangian isleading to the solution:

( ; ) (1 )T TJ a a Wa a aλ λ= + −Wa aλ=

which is an eigenvector of W. The one maximizing J corresponds to the largest eigenvalue of W.

77Eigenvectors and Segmentation

(cont.• Vector a is further thresholded

– Elements of a over the threshold belong to the cluster.

– Elements of a below the threshold are not associated with the cluster

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

associated with the cluster.• More (M) segments may be obtained by

– Recursively clustering the pixels associated with small values of vector a, or

– Computing the first M eigenvectors of W and grouping their M -dimensional features (e.g. by K-means).

78Eigenvectors and Segmentation

(cont.• Ideally, we expect that if here are M significant clusters, the

eigenvectors corresponding to the M largest eigenvalues each represent a segment.

– They would be vectors of a block padded with zeros.

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

80 2D points and the first 4 eigenvectors of the affinity matrix.

Page 14: Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

14

79 Average Association

• The presented technique may be reformulated in terms of an association between the elements of two clusters to be maximized:

( , ) ( , ) ( )assoc A A assoc B B assoc A A w+ ∑

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

,, ( , )

| | | | iji A j A

assoc A A wA B ∈ ∈

+ = ∑

yielding the solution of the eigenvector corresponding to the largest eigenvalue of W:

Wa aλ=

80 Average Cut

• A similar approach minimizes the sum of edges to be cut in order to form two segments:

( ) ( )A B A B

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

( , ) ( , )| | | |

cut A B cut A BA B

+

,

( , ) iji A j B

cut A B w∈ ∈

= ∑

81 Average Cut (cont.)

2( ) ( )N N

i j ijE a a a w= −∑∑

• The associated cost function to be minimized, with respect to a, is:

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

1 1i j= =

• If pixels i and j are similar, that is wij is large, then if they do not belong to the same cluster, E(a) is heavily penalized.

• If the pixels are not similar, the energy is not affected as wij approaches zero.

82 Average Cut (cont.)

2

1 1

( ) ( )N N

i j iji j

E a a a w= −∑∑

ii ijj V

d w∈

=∑To facilitate the proof let us define the diagonal matrix D with elements the sum of weights arriving at the i-th pixel:

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

1 1i j= =

2 2

1 1 1 1 1 1

2N N N N N N

i ij j ij i i iji j j i i j

a w a w a a w= = = = = =

= + −∑ ∑ ∑ ∑ ∑∑

2 2

1 1 1 1

2N N N N

i ii j jj i j iji j i j

a d a d a a w= = = =

= + −∑ ∑ ∑∑2 ( )Ta D W a= −

83 Average Cut (cont.)

• Estimating vector a maximizing:

subject to: 2|| || 1Ta a a= =( ) 2 ( )TE a a D W a= −

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

yields the solution of the eigenvector corresponding to the (second) smallest eigenvalueof D-W:

( )D W a aλ− =

84 Normalized cut

• Average association tends to find ‘tight” clusters in the graph.

• Average cut tends to keep a balance but it is not always guaranteed that that the two partitions will have a tight group similarity

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

will have a tight group similarity.• The normalized cut (Ncut) tries to keep a

balance between finding clustering (tight clusters) and segmentation (split clusters).

• It may be shown that both of the previous methods are approximations of Ncut.

J. Shi and J. Malik. Normalized cuts and image segmentation. PAMI 2000

Page 15: Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

15

85 Normalized cut (cont.)

• Ncut is defined as:( , ) ( , )( , )( , ) ( , )

cut A B cut A BNcut A Bassoc A V assoc B V

= +

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• The cost of the cut is a small fraction of the total affinity in each group.

• Minimization is NP-hard. An approximate solution may be found as in the previous cases.

86 Normalized cut (cont.)

1 1 , if( , ) ij

i Aassoc A V w

⎧ = ∈⎪⎪ ∑

• Create vector a having components the weights associating each pixel with a cluster.

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

,

,

( , )

1 1 if( , )

iji A j V

i

iji B j V

ai B

assoc B V w

∈ ∈

∈ ∈

⎪⎪= ⎨⎪− = − ∈⎪⎪⎩

• Each ai is a cluster indicator of the corresponding pixel.

87 Normalized Cut (cont.)

• As before, we may show that:2 21( ) ( ) ( )

2T

i j ij i j iji V j V i A j B

a D W a a a w a a w∈ ∈ ∈ ∈

− = − = −∑∑ ∑∑2

The contribution is 0 for points in the same cluster

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

21 1 ( , )( , ) ( , )i A j B

cut A Bassoc A V assoc B V∈ ∈

⎛ ⎞= +⎜ ⎟

⎝ ⎠∑∑

21 1 ( , )( , ) ( , )

cut A Bassoc A V assoc B V

⎛ ⎞∝ +⎜ ⎟⎝ ⎠

88 Normalized Cut (cont.)

• Also,2 2Ti ii j jj

i A j B

a Da a d a d∈ ∈

= +∑ ∑

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

1 1( , ) ( , )assoc A V assoc B V

= +

2 2

1 1( , ) ( , )( , ) ( , )

assoc A V assoc B Vassoc A V assoc B V

= +

89 Normalized Cut (cont.)

• We now combine1 1( , ) ( , )

Ta Daassoc A V assoc B V

= +

2⎛ ⎞

with

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

in

( )

2

2

1 1( ) ( , )( , ) ( , )

( , )

T

T

a D W a cut A Bassoc A V assoc B V

a Da cut A B

⎛ ⎞− ∝ +⎜ ⎟

⎝ ⎠

=

( , ) ( , )( , )( , ) ( , )

cut A B cut A BNcut A Bassoc A V assoc B V

= +

90 Normalized Cut (cont.)

It turns out that the Ncut objective function is equivalent to minimizing:

( )( , )T

T

a D W aNcut A Ba Da−

=

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

or minimizing:

( ) ( )T TE a a D W a a Daλ= − +

which corresponds to finding the eigenvector correponding to the (second) smallest eigenvalue of

1/2 1/2( )D D W D− −−

Page 16: Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

16

91 Normalized Cut (cont.)

Remember the Average Cut minimization problem is equivalent to minimizing:

1Ta a =( ) ( )TE a a D W a= − subject to

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

The Ncut problem is equivalent to minimizing:

( ) ( )TE a a D W a= − 1Ta Da =subject to

The larger the value of Dii , the more important is the i-th sample.

92 Normalized Cut (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

93 Normalized Cut (cont.)

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

The magnitudes of the eigenvalues provide a hint for the number of clusters.

94 Normalized Cut (cont.)

• Superpixels.• Unsupervised bottom-up process.

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

X. Ren and J. Malik. Learning a classification model for segmentation. ICCV 2003.

95Using texture features for

segmentation• How to segment images that are a

“mosaic of textures”?

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

96Using texture features for

segmentation (cont.)• Convolve image with a bank of filters.

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

J. Malik, S. Belongie, T. Leung and J. Shi. "Contour and Texture Analysis for Image Segmentation". IJCV 43(1),7-27,2001.

Page 17: Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

17

97Using texture features for

segmentation (cont.)• Find textons by clustering vectors of filter

bank outputs.Texton mapImage

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

J. Malik, S. Belongie, T. Leung and J. Shi. "Contour and Texture Analysis for Image Segmentation". IJCV 43(1),7-27,2001.

98Using texture features for

segmentation (cont.)• The final texture feature is a texton histogram

computed over image windows at some “local scale”.

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

J. Malik, S. Belongie, T. Leung and J. Shi. "Contour and Texture Analysis for Image Segmentation". IJCV 43(1),7-27,2001.

99 Pitfall of texture features

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• Possible solution: check for “intervening contours” when computing connection weights.

J. Malik, S. Belongie, T. Leung and J. Shi. "Contour and Texture Analysis for Image Segmentation". IJCV 43(1),7-27,2001.

100 Example Results

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

101Results: Berkeley Segmentation

Engine

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011http://www.cs.berkeley.edu/~fowlkes/BSE/

102

• Pros– Generic framework, can be used with

many different features and affinity formulations.

Normalized cuts: Pros and cons

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• Cons– High storage requirement and time

complexity.– Bias towards partitioning into equal

segments.

Page 18: Lecture 1 Segmentation by Clustering - University of Ioanninacnikou/Courses/Strasbourg/Lecture_1...•Grouping and the Gestalt school. •K-means •Mean shift •Spectral methods

18

103Segments as primitives for

recognition?Multiple segmentations

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• B. Russell et al., “Using Multiple Segmentations to Discover Objects and their Extent in Image Collections,” CVPR 2006.

104 Object detection and segmentation

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• D. Ramanan, “Using segmentation to verify object hypotheses,” CVPR 2007.

∑∑∈

≠+−=Nji

jii

i llclasslPLE,

)())|(log()( δαSegmentation energy:

105 Top-down segmentation

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• E. Borenstein and S. Ullman, “Class-specific, top-down segmentation,”ECCV 2002.

• A. Levin and Y. Weiss, “Learning to Combine Bottom-Up and Top-Down Segmentation,” ECCV 2006.

106 Top-down segmentation (cont.)

Normalized cuts

C. Nikou – École Doctorale, Strasbourg, 6-10 June 2011

• E. Borenstein and S. Ullman, “Class-specific, top-down segmentation,”ECCV 2002

• A. Levin and Y. Weiss, “Learning to Combine Bottom-Up and Top-Down Segmentation,” ECCV 2006.

Top-down segmentation