Dilation and Erosion
Total Page:16
File Type:pdf, Size:1020Kb
CS 4495 Computer Vision – A. Bobick Morphology CS 4495 Computer Vision Binary images and Morphology Aaron Bobick School of Interactive Computing CS 4495 Computer Vision – A. Bobick Morphology Administrivia • PS6 – should be working on it! Due Sunday Nov 24th. • Some issues with reading frames. Resolved? • Exam: Tues November 26th . • Short answer and multiple choice (mostly short answer) • Study guide is posted in calendar. • Bring a pen. • PS7 – we still hope to have out by 11/26. Will be straight forward implementation of Motion History Images CS 4495 Computer Vision – A. Bobick Morphology Binary Image Analysis Binary image analysis • consists of a set of image analysis operations that are used to produce or process binary images, usually images of 0’s and 1’s. 0 represents the background 1 represents the foreground 00010010001000 00011110001000 00010010001000 Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Binary Image Analysis • Is used in a number of practical applications • Part inspection • Manufacturing • Document processing Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology What kinds of operations? • Separate objects from background and from one another • Aggregate pixels for each object • Compute features for each object Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Example: red blood cell image • Many blood cells are separate objects • Many touch – bad! • Salt and pepper noise from thresholding • How useable is this data? Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Results of analysis • 63 separate objects detected • Single cells have area about 50 • Noise spots • Gobs of cells Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Useful Operations • Thresholding a gray-scale image • Determining good thresholds • Connected components analysis • Binary mathematical morphology • All sorts of feature extractors • (area, centroid, circularity, …) Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Thresholding • Background is black • Healthy cherry is bright • Bruise is medium dark • Histogram shows two cherry regions (black background has been removed) pixel counts 0 gray-scale values 255 Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Histogram-Directed Thresholding How can we use a histogram to separate an image into 2 (or several) different regions? Is there a single clear threshold? 2? 3? Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Automatic Thresholding: Otsu’s Method Grp 1 Grp 2 Assumption: the histogram is bimodal t Method: find the threshold t that minimizes the weighted sum of within-group variances for the two groups that result from separating the gray tones at value t. In practice, this operator works very well for true bimodal distributions and not too badly for others. Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Thresholding Example Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Connected Components Labeling Once you have a binary image, you can identify and then analyze each connected set of pixels. The connected components operation takes in a binary image and produces a labeled image in which each pixel has the integer label of either the background (0) or a component. Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Methods for CC Analysis 1. Recursive Tracking (almost never used) 2. Parallel Growing (needs parallel hardware) 3. Row-by-Row (most common) • Classical Algorithm • Efficient Run-Length Algorithm (developed for speed in real industrial applications) Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Equivalent Labels Original Binary Image 0 0 0 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 0 0 0 1 1 1 1 0 0 0 1 1 1 1 0 0 0 1 1 0 0 0 1 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 0 0 0 1 1 1 1 1 1 0 1 1 1 1 0 0 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Equivalent Labels CC =0 Scan across rows: If 1 and connected, 0 0 0 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 Propgate lowest label behind or above (4 0 0 0 1 1 1 1 0 0 0 1 1 1 1 0 0 0 1 1 or 8 connected). 0 0 0 1 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 Remember conflicts 0 0 0 1 1 1 1 1 1 0 1 1 1 1 0 0 1 1 1 If 1 and not connected 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 CC++ and label CC 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 If 0, label 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Relabel based on 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 table 0 0 0 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Equivalent Labels CC =0 Scan across rows: If 1 and connected, 0 0 0 1 1 1 0 0 0 0 2 2 2 2 0 0 0 0 3 Propgate lowest label behind or above (4 or 8 connected). 0 0 0 1 1 1 1 0 0 0 2 2 2 2 0 0 0 3 3 Remember conflicts 0 0 0 1 1 1 1 1 0 0 2 2 2 2 0 0 3 3 3 If 1 and not connected 0 0 0 1 1 1 1 1 1 0 2 2 2 2 0 0 3 3 3 CC++ and label CC 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 3 3 3 If 0, label 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 3 3 3 Relabel based on 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 table 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 ≡ 2 1 ≡ 3 Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Equivalent Labels The Labeling Process 0 0 0 1 1 1 0 0 0 0 2 2 2 2 0 0 0 0 3 1 ≡ 2 0 0 0 1 1 1 1 0 0 0 2 2 2 2 0 0 0 3 3 1 ≡ 3 0 0 0 1 1 1 1 1 0 0 2 2 2 2 0 0 3 3 3 0 0 0 1 1 1 1 1 1 0 2 2 2 2 0 0 3 3 3 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 3 3 3 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 3 3 3 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Labeling shown as Pseudo-Color connected components of 1’s from thresholded image connected components of cluster labels Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Mathematical Morphology Binary mathematical morphology consists of two basic operations dilation and erosion and several composite relations closing and opening hit-or-miss transformation . Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Dilation Dilation expands the connected sets of 1s of a binary image. It can be used for 1. growing features 2. filling holes and gaps Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Erosion Erosion shrinks the connected sets of 1s of a binary image. It can be used for 1. shrinking features 2. Removing bridges, branches and small protrusions Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Structuring Elements A structuring element is a shape mask used in the basic morphological operations. They can be any shape and size that is digitally representable, and each has an origin. box disk hexagon something box(length,width) disk(diameter) Slide by Linda Shapiro CS 4495 Computer Vision – A. Bobick Morphology Dilation with Structuring Elements The arguments to dilation and erosion are 1.