Mata kuliah : T0283 - Computer Vision Tahun : 2010 Lecture 07 Segmentation Learning Objectives After carefully listening this lecture, students will be able to do the following : Explain various segmentation techniques and demonstrate their implementation (histogram based segmentation, kmeans) using MATLAB and OpenCV January 20, 2010 T0283 - Computer Vision 3 Motivation : Recognition Using Region Properties Training For all training samples of each model object Segment the image Compute region properties (features) Recognition Given an image of unknown object, Segment the image Compute its feature vector Compare with the training set January 20, 2010 T0283 - Computer Vision 4 Region Segmentation January 20, 2010 T0283 - Computer Vision 5 Segmentation Find set of regions R1, R2, ….,Rn such that n R i i 1 I i j , Ri R j All pixels in region i satisfy some similarity constraint January 20, 2010 T0283 - Computer Vision 6 Similarity Constraints All pixels in any sub-image musts have the same gray levels. All pixels in any sub-image must not differ more than some threshold All pixels in any sub-image may not differ more than some threshold from the mean of the gray of the region The standard deviation of gray levels in any sub-image must be small. January 20, 2010 T0283 - Computer Vision 7 Simple Segmentation 1 B ( x, y ) 0 if I ( x, y ) T Otherwise 1 B( x, y ) 0 if T1 I ( x, y ) T2 Otherwise 1 B( x, y ) 0 January 20, 2010 if I ( x, y ) Z Otherwise T0283 - Computer Vision 8 Image Histogram number of pixels Histogram graphs the number of pixels with a particular gray level as a function of the image of gray levels. gray level January 20, 2010 T0283 - Computer Vision 9 Segmentation Using Histogram Simple Case January 20, 2010 T0283 - Computer Vision 10 Segmentation Using Histogram Simple Case January 20, 2010 1 B1 ( x, y ) 0 if 0 f ( x, y ) T1 Otherwise 1 B2 ( x, y ) 0 if T1 f ( x, y ) T2 Otherwise 1 B3 ( x, y ) 0 if T2 f ( x, y ) T3 Otherwise T0283 - Computer Vision 11 Realistic Histograms Smooth out noise Convolve hist. by averaging or 1D Gaussian filter peak peak valley peak valley valley January 20, 2010 T0283 - Computer Vision 12 Segmentation Using Histogram Real image histograms 1. 2. 3. 4. 5. Compute the histogram of a given image. Smooth the histogram by averaging peaks and valleys in the histogram. Detect good peaks by applying thresholds at the valleys. Segment the image into several binary images using thresholds at the valleys. Apply connected component algorithm to each binary image find connected regions. January 20, 2010 T0283 - Computer Vision 13 Segmentation Using Histograms Select the valleys as thresholds Apply threshold to histogram Label the pixels within the range of a threshold with same label, i.e., a, b, c … or 1, 2, 3 … January 20, 2010 T0283 - Computer Vision 14 Connected Components Disjoint segments with same labels need to be split 0 1 0 0 0 0 1 0 0 1 0 0 0 1 0 1 1 0 1 1 0 1 0 0 0 0 b 0 0 0 0 b 0 0 d 0 0 0 c 0 a a 0 c c 0 a 0 0 0 may be added to segment c January 20, 2010 T0283 - Computer Vision 15 Recursive Connected Component Algorithm 1. 2. 3. 4. Scan the binary image left to right, top to bottom. If there is an unlabeled pixel with a value of “1”, assign a new label to it. Recursively check the neighbors of the pixel in step 2 and assign the same label if they are unlabeled with value “1”. Stop when all the pixels of value “1” have been labeled. January 20, 2010 T0283 - Computer Vision 16 Sequential Connected Component Algorithm 1. 2. 3. 4. Scan the binary image left to right, top to bottom. If an unlabeled pixel with a value of “1”, assign a new label to it according to the following rules : - 0 0 1 0 0 L - L 0 1 0 L L - 0 L 1 L 0 L - L M 1 - L (Set M=L) M L Determine equivalence classes of labels In the second pass, assign the same label to all elements in an equivalence class. January 20, 2010 T0283 - Computer Vision 17 Sequential Connected Component Algorithm 0 1 0 0 0 January 20, 2010 0 1 0 0 1 0 0 0 1 1 1 1 0 1 1 0 1 0 0 0 0 b 0 0 0 0 b 0 0 d T0283 - Computer Vision 0 0 0 c c a a 0 c c 0 a 0 0 0 d=c Equivalence class 18 Example Detecting Finger Tips (marked white) January 20, 2010 T0283 - Computer Vision 19 Recaps : Steps in Seed Segmentation 1. 2. 3. 4. Compute the histogram. Smooth the histogram Detect good peaks Segment image into binary images using thresholds at the valleys. 5. Apply connected component algorithm. January 20, 2010 T0283 - Computer Vision 20 Improving Seed Segmentation Merge small neighboring regions Region growing step Split large regions Region splitting Remove weak boundaries between adjacent regions January 20, 2010 T0283 - Computer Vision 21 Region Growing Seed segmentation (histogram based seg.) Region splitting and merging Phagocyte algorithm Likelihood ratio test January 20, 2010 T0283 - Computer Vision 22 Region Split and Merge Splitting: split non uniform region into 4 adjacent regions Merging: merge similar regions Stop when no splitting merging are possible Uniformity/similarity function: P January 20, 2010 T0283 - Computer Vision 23 Example R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R January 20, 2010 T0283 - Computer Vision 24 Phagocyte Algorithm Boundary melting Remove weak boundaries Similar to region merging Boundary weakness is based on color similarity R2 S (x R1 , x R2 ) I (x R1 ) I (x R2 ) January 20, 2010 T0283 - Computer Vision x R1 x R2 R1 25 Phagocyte Algorithm S (x R1 , x R2 ) I (x R1 ) I (x R2 ) 1 S (x R1 , x R2 ) T W (x R1 , x R2 ) 0 otherwise W ( R1 , R2 ) January 20, 2010 R2 x R1 x R2 R1 W (x R1 , x R2 ) x R1 R1 x R2 R2 T0283 - Computer Vision 26 Phagocyte Merging Heuristics • Merge two regions if W ( Boundary ) T 2, 0 T2 1 min( P1 , P) 2 Phagocyte where P1 and P2 are the perimeters of regions R1 and R2. • Merge regions if W ( Boundary ) T 3, 0 T3 1 Total number of points on the border January 20, 2010 T0283 - Computer Vision Weakness 27 Likelihood Ratio Test Two region hypothesis There is only one region There are indeed two regions Intensity at every pixel is independent Joint probability Gaussian distribution January 20, 2010 T0283 - Computer Vision 28 Likelihood Ratio Test p ( x) 1 e 2 ( x )2 2 2 observing intensity under Gaussian model Likelihood of region A m1 1 21 p( x1 , x2 ,, xm1 ) e 2 m x1, x2, …,xm1A Likelihood of region B m2 1 22 p( xm1 1 , xm1 2 ,, xm1 m2 ) e 2 January 20, 2010 m T0283 - Computer Vision xm1+1, xm1+2, …,xm1+m2B 29 Likelihood Ratio Test There is 1 region hypothesis 1 P( H1 ) p( x1 , x2, , xm1 , xm1 1 , xm1 2 ,, xm1 m2 ) 2 one region There are 2 regions hypothesis m1 m1 m2 e m1 m2 2 m2 1 m21 1 m22 e e P( H 2 ) p( x1 , x2, , xm1 ) p( xm1 1 , xm1 2 ,, xm1 m2 ) 2 A 2 B January 20, 2010 T0283 - Computer Vision 30 Likelihood Ratio Test 1 P( H1 ) 2 one region m1 m2 e m1 m1 m2 2 m2 1 m21 1 m22 e e P( H 2 ) 2 A 2 B ( 0 ) m1 m2 P ( H1 ) LH P( H 2 ) ( A ) m1 ( B ) m2 January 20, 2010 T0283 - Computer Vision Merge regions if LH<T. 31 Region Growing Methods Different algorithms have different number of thresholds How much merging is required Stopping criterion Though simple, seed segmentation succeed by region growing is usually successful January 20, 2010 T0283 - Computer Vision 32 Difference Between Segmentation and Edge Detection Closed boundary Edges are usually open Segmentation provides closed boundaries Local or global Edges are computed in the locality Segmentation is global Increasing feature vector dimensionality Does not drastically improve edge detection Improves segmentation (motion, texture information etc.) Boundary position Localized in edge detection Usually not localized (recent advancements use locality as well) Especially contour based segmentation January 20, 2010 T0283 - Computer Vision 33