Lecture 13: k-means and mean-shift clustering

Similar documents
Lecture: k-means & mean-shift clustering

Lecture: k-means & mean-shift clustering

Computer Vision Lecture 6

Computer Vision Lecture 6

CS 2750: Machine Learning. Clustering. Prof. Adriana Kovashka University of Pittsburgh January 17, 2017

Segmentation and Grouping April 19 th, 2018

Segmentation and Grouping

CMPSCI 670: Computer Vision! Grouping

Segmentation & Grouping Kristen Grauman UT Austin. Announcements

Grouping and Segmentation

Outline. Segmentation & Grouping. Examples of grouping in vision. Grouping in vision. Grouping in vision 2/9/2011. CS 376 Lecture 7 Segmentation 1

Segmentation and Grouping April 21 st, 2015

CS 4495 Computer Vision. Segmentation. Aaron Bobick (slides by Tucker Hermans) School of Interactive Computing. Segmentation

Grouping and Segmentation

CSE 473/573 Computer Vision and Image Processing (CVIP) Ifeoma Nwogu. Lectures 21 & 22 Segmentation and clustering

Lecture 10: Semantic Segmentation and Clustering

Applications. Foreground / background segmentation Finding skin-colored regions. Finding the moving objects. Intelligent scissors

CS 2770: Computer Vision. Edges and Segments. Prof. Adriana Kovashka University of Pittsburgh February 21, 2017

Segmentation & Clustering

The goals of segmentation

Segmentation Computer Vision Spring 2018, Lecture 27

Segmentation and Grouping

Segmentation (continued)

Digital Image Processing

Lecture 16 Segmentation and Scene understanding

Segmentation. Bottom Up Segmentation

Lecture 7: Segmentation. Thursday, Sept 20

Clustering. Subhransu Maji. CMPSCI 689: Machine Learning. 2 April April 2015

Clustering. Discover groups such that samples within a group are more similar to each other than samples across groups.

2%34 #5 +,,% ! # %& ()% #% +,,%. & /%0%)( 1 ! # %& % %()# +(& ,.+/ +&0%//#/ &

CEE598 - Visual Sensing for Civil Infrastructure Eng. & Mgmt.

Image Segmentation. Luc Van Gool, ETH Zurich. Vittorio Ferrari, Un. of Edinburgh. With important contributions by

Image Segmentation. Marc Pollefeys. ETH Zurich. Slide credits: V. Ferrari, K. Grauman, B. Leibe, S. Lazebnik, S. Seitz,Y Boykov, W. Freeman, P.

Clustering. So far in the course. Clustering. Clustering. Subhransu Maji. CMPSCI 689: Machine Learning. dist(x, y) = x y 2 2

Colorado School of Mines. Computer Vision. Professor William Hoff Dept of Electrical Engineering &Computer Science.

Dr. Ulas Bagci

Image Analysis. Segmentation by Clustering

Image Segmentation. Shengnan Wang

Image Segmentation. Computer Vision Jia-Bin Huang, Virginia Tech. Many slides from D. Hoiem

Nonparametric Clustering of High Dimensional Data

Image Segmentation. Selim Aksoy. Bilkent University

Image Segmentation. Selim Aksoy. Bilkent University

Lecture 8: Fitting. Tuesday, Sept 25

Idea. Found boundaries between regions (edges) Didn t return the actual region

Computer Vision II Lecture 4

Announcements. Segmentation & Grouping. Review questions. Outline. Grouping in vision. Examples of grouping in vision 9/21/2015

Image Segmentation. April 24, Stanford University. Philipp Krähenbühl (Stanford University) Segmentation April 24, / 63

Local Features and Bag of Words Models

Case-Based Reasoning. CS 188: Artificial Intelligence Fall Nearest-Neighbor Classification. Parametric / Non-parametric.

CS 188: Artificial Intelligence Fall 2008

2D image segmentation based on spatial coherence

CSE 5243 INTRO. TO DATA MINING

CSSE463: Image Recognition Day 21

CSE 573: Artificial Intelligence Autumn 2010

Clustering Color/Intensity. Group together pixels of similar color/intensity.

CSE 5243 INTRO. TO DATA MINING

Announcements. Image Segmentation. From images to objects. Extracting objects. Status reports next Thursday ~5min presentations in class

Feature Extractors. CS 188: Artificial Intelligence Fall Nearest-Neighbor Classification. The Perceptron Update Rule.

Kernels and Clustering

CS 343: Artificial Intelligence

What to come. There will be a few more topics we will cover on supervised learning

Segmentation by Clustering Reading: Chapter 14 (skip 14.5)

Segmentation by Clustering. Segmentation by Clustering Reading: Chapter 14 (skip 14.5) General ideas

Lecture 13 Segmentation and Scene Understanding Chris Choy, Ph.D. candidate Stanford Vision and Learning Lab (SVL)

Clustering. CS294 Practical Machine Learning Junming Yin 10/09/06

Classification: Feature Vectors

Image gradients and edges April 11 th, 2017

Image gradients and edges April 10 th, 2018

CS 534: Computer Vision Segmentation and Perceptual Grouping

University of Florida CISE department Gator Engineering. Clustering Part 2

BBS654 Data Mining. Pinar Duygulu. Slides are adapted from Nazli Ikizler

Solution: filter the image, then subsample F 1 F 2. subsample blur subsample. blur

Computer Vision II Lecture 4

Object Recognition. Computer Vision. Slides from Lana Lazebnik, Fei-Fei Li, Rob Fergus, Antonio Torralba, and Jean Ponce

Image Processing and Image Analysis VU

Patch Descriptors. CSE 455 Linda Shapiro

K-Means. Algorithmic Methods of Data Mining M. Sc. Data Science Sapienza University of Rome. Carlos Castillo

COMP 551 Applied Machine Learning Lecture 13: Unsupervised learning

Programming assignment 3 Mean-shift

CS 343H: Honors AI. Lecture 23: Kernels and clustering 4/15/2014. Kristen Grauman UT Austin

In this lecture, we are going to talk about image segmentation, essentially defined as methods for grouping pixels together.

Unsupervised learning in Vision

Bias-Variance Trade-off (cont d) + Image Representations

Feature Matching and Robust Fitting

Fitting: Voting and the Hough Transform April 23 rd, Yong Jae Lee UC Davis

Classification. Vladimir Curic. Centre for Image Analysis Swedish University of Agricultural Sciences Uppsala University

Recap from Monday. Visualizing Networks Caffe overview Slides are now online

Image gradients and edges

Fitting. Lecture 8. Cristian Sminchisescu. Slide credits: K. Grauman, S. Seitz, S. Lazebnik, D. Forsyth, J. Ponce

CS 534: Computer Vision Segmentation and Perceptual Grouping

Unsupervised Learning

Today s lecture. Clustering and unsupervised learning. Hierarchical clustering. K-means, K-medoids, VQ

Cluster Analysis. Prof. Thomas B. Fomby Department of Economics Southern Methodist University Dallas, TX April 2008 April 2010

Announcements. CS 188: Artificial Intelligence Spring Classification: Feature Vectors. Classification: Weights. Learning: Binary Perceptron

CS 558: Computer Vision 4 th Set of Notes

Supervised learning. y = f(x) function

An Introduction to PDF Estimation and Clustering

Graph based Image Segmentation using improved SLIC Superpixel algorithm

Applications of Image Filters

Introduction to object recognition. Slides adapted from Fei-Fei Li, Rob Fergus, Antonio Torralba, and others

Transcription:

Lecture 13: k-means and mean-shift clustering Juan Carlos Niebles Stanford AI Lab Professor Stanford Vision Lab Lecture 13-1

Recap: Image Segmentation Goal: identify groups of pixels that go together Lecture 13-2

Recap: Gestalt Theory Gestalt: whole or group (German: "shape, form") Whole is other than sum of its parts Relationships among parts can yield new properties/features Psychologists identified series of factors that predispose set of elements to be grouped (by human visual system) I stand at the window and see a house, trees, sky. Theoretically I might say there were 327 brightnesses and nuances of colour. Do I have "327"? No. I have sky, house, and trees. Max Wertheimer (1880-1943) Untersuchungen zur Lehre von der Gestalt, Psychologische Forschung, Vol. 4, pp. 301-350, 1923 Lecture 13-3

Recap: Gestalt Factors These factors make intuitive sense, but are very difficult to translate into algorithms. Lecture 13-4

Recap: Multistability https://en.wikipedia.org/wiki/spinning_dancer Lecture 13-5

Recap: Agglomerative clustering Simple algorithm Initialization: Every point is its own cluster Repeat: Find most similar pair of clusters Merge into a parent cluster Until: The desired number of clusters has been reached There is only one cluster Lecture 13-6

What will we learn today? K-means clustering Mean-shift clustering Reading material: Forsyth & Ponce: Chapter 9.3 Comaniciu and Meer, Mean Shift: A Robust Approach toward Feature Space Analysis, PAMI 2002. gifs: https://www.projectrhea.org Lecture 13-7

Image Segmentation: Toy Examplewhite 1 2 3 pixels black pixels gray pixels input image These intensities define the three groups. intensity We could label every pixel in the image according to which of these primary intensities it is. i.e., segment the image based on the intensity feature. What if the image isn t quite so simple? Slide credit: Kristen Grauman Lecture 13-8

Pixel count Input image Pixel count Intensity Input image Slide credit: Kristen Grauman Intensity Lecture 13-9

Pixel count Input image Intensity Now how to determine the three main intensities that define our groups? We need to cluster. Slide credit: Kristen Grauman Lecture 13-10

0 190 Intensity 255 3 2 Goal: choose three centers as the representative intensities, and label every pixel according to which of these centers it is nearest to. Best cluster centers are those that minimize Sum of Square Distance (SSD) between all points and their nearest cluster center ci: Lecture 13-11 Slide credit: Kristen Grauman 1

Objective function Goal: minimize the distortion in data given clusters - Preserve information Cluster center Data Slide: Derek Hoiem Lecture 13-12

Clustering With this objective, it is a chicken and egg problem: If we knew the group memberships, we could get the centers by computing the mean per group. Lecture 13-13 Slide credit: Kristen Grauman If we knew the cluster centers, we could allocate points to groups by assigning each to its closest center.

K-means Clustering Initialization: choose k cluster centers Repeat: assignment step: For every point find its closest center update step: Update every center as the mean of its points Until: The maximum number of iterations is reached, or No changes during the assignment step, or The average distortion per point drops very little [Lloyd, 1957] Lecture 13-14

K-means Clustering l ica n h c te note slide credit: P. Rai Lecture 13-15

K-means Clustering l ica n h c te note [1] [1] L. Bottou and Y. Bengio. Convergence properties of the kmeans algorithm. NIPS, 1995. Lecture 13-16 slide credit: P. Rai

K-means: Initialization k-means is extremely sensitive to initialization Bad initialization can lead to: poor convergence speed bad overall clustering How to initialize? randomly from data try to find K spread-out points (k-means++) Safeguarding measure: try multiple initializations and choose the best Lecture 13-17

K-means: Initialization k-means is extremely sensitive to initialization Bad initialization can lead to: poor convergence speed bad overall clustering Lecture 13-18

K-means++ Can we prevent arbitrarily bad local minima? 1. Randomly choose first center. 2. Pick new center with prob. proportional to (x - ci)2 (Contribution of x to total error) 3. Repeat until K centers. Expected error O(logK) (optimal) K-means++ animation Arthur & Vassilvitskii 2007 Lecture 13-19

K-means: choosing K slide credit: P. Rai Lecture 13-20

K-means: choosing K Validation set Try different numbers of clusters and look at performance When building dictionaries (discussed later), more clusters typically work better Slide: Derek Hoiem Lecture 13-21

Distance Measure & Termination Choice of distance measure: Euclidean (most commonly used) Cosine non-linear! (Kernel k-means) Picture courtesy: Christof Monz (Queen Mary, Univ. of London) Termination: The maximum number of iterations is reached No changes during the assignment step (convergence) The average distortion per point drops very little Lecture 13-22

K-means: Example K-Means Clustering Example Lecture 13-23

How to evaluate clusters? Generative How well are points reconstructed from the clusters? Distortion Discriminative How well do the clusters correspond to labels? Purity Note: unsupervised clustering does not aim to be discriminative Slide: Derek Hoiem Lecture 13-24

Segmentation as Clustering Let s just use the pixel intensities! k=2 k=3 Slide credit: Kristen Grauman Lecture 13-25

Feature Space Depending on what we choose as the feature space, we can group pixels in different ways. Grouping pixels based on intensity similarity Feature space: intensity value (1D) Slide credit: Kristen Grauman Lecture 13-26

Feature Space Depending on what we choose as the feature space, we can group pixels in different ways. R=255 G=200 B=250 Grouping pixels based on color similarity R=245 G=220 B=248 B G R R=15 G=189 B=2 Feature space: color value (3D) R=3 G=12 B=2 Slide credit: Kristen Grauman Lecture 13-27

Feature Space Depending on what we choose as the feature space, we can group pixels in different ways. Grouping pixels based on texture similarity F1 F2 Filter bank of 24 filters F24 Feature space: filter bank responses (e.g., 24D) Slide credit: Kristen Grauman Lecture 13-28

K-Means Clustering Results K-means clustering based on intensity or color is essentially vector quantization of the image attributes Clusters don t have to be spatially coherent Intensity-based clusters Color-based clusters Image source: Forsyth & Ponce Image Lecture 13-29

Smoothing Out Cluster Assignments Assigning a cluster label per pixel may yield outliers: Original Labeled by cluster center s intensity? How can we ensure they are spatially smooth? 3 1 2 Slide credit: Kristen Grauman Lecture 13-30

Segmentation as Clustering Depending on what we choose as the feature space, we can group pixels in different ways. Grouping pixels based on intensity+position similarity Intensity Y X Way to encode both similarity and proximity. Slide credit: Kristen Grauman Lecture 13-31

K-means clustering for superpixels SLIC Superpixels: Feature space intensity + position L.a.b. color space limited region (window 2*S) Distance metric: Initialization: Spatial grid (grid step = S) Iterate over centers and not points Achanta et al., SLIC Superpixels Compared to State-of-the-art Superpixel Methods, PAMI 2012. Lecture 13-32

K-means clustering for superpixels Achanta et al., SLIC Superpixels Compared to State-of-the-art Superpixel Methods, PAMI 2012. Lecture 13-33

K-means clustering for superpixels Achanta et al., SLIC Superpixels Compared to State-of-the-art Superpixel Methods, PAMI 2012. Lecture 13-34

K-means clustering for superpixels Achanta et al., SLIC Superpixels Compared to State-of-the-art Superpixel Methods, PAMI 2012. Lecture 13-35

K-means Clustering: Limitations [1] [1] Dhillon et al. Kernel k-means, Spectral Clustering and Normalized Cuts. KDD, 2004. Lecture 13-36 slide credit: P. Rai

K-Means pros and cons Pros Finds cluster centers that minimize conditional variance (good representation of data) Simple and fast, Easy to implement Cons Need to choose K Sensitive to outliers Prone to local minima All clusters have the same parameters (e.g., distance measure is non-adaptive) *Can be slow: each iteration is O(KNd) for N d-dimensional points Usage Unsupervised clustering Rarely used for pixel segmentation Lecture 13-37

Scaling-up K-means clustering Assignment step is the bottleneck Approximate assignments [AK-means, CVPR 2007], [AGM, ECCV 2012] Mini-batch version [mbk-means, WWW 2010] Search from every center [Ranked retrieval, WSDM 2014] Binarize data and centroids [BK-means, CVPR 2015] Quantize data [DRVQ, ICCV 2013], [IQ-means, ICCV 2015] Lecture 13-38

What will we learn today? K-means clustering Mean-shift clustering Lecture 13-39

Mean-Shift Segmentation D. Comaniciu and P. Meer, Mean Shift: A Robust Approach toward Feature Space Analysis, PAMI 2002. Lecture 13-40 Slide credit: Svetlana Lazebnik An advanced and versatile technique for clustering-based segmentation

Iterative Mode Search 1. 2. 3. 4. Initialize random seed, and window W Calculate center of gravity (the mean ) of W = Shift the search window to the mean Repeat Step 2 until convergence [Fukunaga & Hostetler, 1975] Lecture 13-41 Slide credit: Steve Seitz Mean-Shift Algorithm

Mean-Shift Region of interest Center of mass Mean Shift vector Slide by Y. Ukrainitz & B. Sarel Lecture 13-42

Mean-Shift Region of interest Center of mass Mean Shift vector Slide by Y. Ukrainitz & B. Sarel Lecture 13-43

Mean-Shift Region of interest Center of mass Mean Shift vector Slide by Y. Ukrainitz & B. Sarel Lecture 13-44

Mean-Shift Region of interest Center of mass Mean Shift vector Slide by Y. Ukrainitz & B. Sarel Lecture 13-45

Mean-Shift Region of interest Center of mass Mean Shift vector Slide by Y. Ukrainitz & B. Sarel Lecture 13-46

Mean-Shift Region of interest Center of mass Mean Shift vector Slide by Y. Ukrainitz & B. Sarel Lecture 13-47

Mean-Shift Region of interest Center of mass Slide by Y. Ukrainitz & B. Sarel Lecture 13-48

Tessellate the space with windows Run the procedure in parallel Lecture 13-49 Slide by Y. Ukrainitz & B. Sarel Real Modality Analysis

The blue data points were traversed by the windows towards the mode. Lecture 13-50 Slide by Y. Ukrainitz & B. Sarel Real Modality Analysis

Mean-Shift Clustering Cluster: all data points in the attraction basin of a mode Attraction basin: the region for which all trajectories lead to the same mode Slide by Y. Ukrainitz & B. Sarel Lecture 13-51

Mean-Shift Clustering/Segmentation Find features (color, gradients, texture, etc) Initialize windows at individual pixel locations Perform mean shift for each window until convergence Merge windows that end up near the same peak or mode Slide credit: Svetlana Lazebnik Lecture 13-52

Slide credit: Svetlana Lazebnik Mean-Shift Segmentation Results Lecture 13-53

Slide credit: Svetlana Lazebnik More Results Lecture 13-54

More Results Lecture 13-55

Slide credit: Bastian Leibe Problem: Computational Complexity Need to shift many windows Many computations will be redundant. Lecture 13-56

Speedups: Basin of Attraction 1. Slide credit: Bastian Leibe r Assign all points within radius r of end point to the mode. Lecture 13-57

Slide credit: Bastian Leibe Speedups Assign all points within radius r/c of the search path to the mode Lecture 13-58

al c i n tech e not Mean-shift Algorithm Comaniciu & Meer, 2002 Lecture 13-59

al c i n tech e not Mean-shift Algorithm Comaniciu & Meer, 2002 Lecture 13-60

Summary Mean-Shift Pros General, application-independent tool Model-free, does not assume any prior shape (spherical, elliptical, etc.) on data clusters Just a single parameter (window size h) h has a physical meaning (unlike k-means) Finds variable number of modes Robust to outliers Slide credit: Svetlana Lazebnik Cons Output depends on window size Window size (bandwidth) selection is not trivial Computationally (relatively) expensive (~2s/image) Does not scale well with dimension of feature space Lecture 13-61

Medoid-Shift & Quick-Shift Quick-Shift: - does not need the gradient or quadratic lower bound - only one step has to be computed for each point: simply moves each point to the nearest neighbor for which there is an increment of the density - there is no need for a stopping/merging heuristic - the data space X may be non-euclidean [Vedaldi and Soatto, 2008] Lecture 13-62

What have we learned today K-means clustering Mean-shift clustering IPython Notebook for SLIC and Quickshift Lecture 13-63