Image Segmentation Qualification Exam Deparment of Electrical Engineering - DEE Pedro M. Achanccaray Diaz Advisor: Raul Queiroz Feitosa Sumário 1. Introduction 2. Spatially blind approaches 3. Spatially guided approaches 2 Sumário 1. Introduction 2. Spatially blind approaches 3. Spatially guided approaches 3 1. Introduction Digital Image Processing (DIP): Digital Image Real scene Acquisition Enhancement / Pre-Processing Segmentation Postprocessing Feature Extraction Recognition Classification 4 1. Introduction Digital Image Processing (DIP): Digitalization errors Acquisition Image without noise Enhancement / Pre-Processing Segmentation Postprocessing Feature Extraction Recognition Classification 5 1. Introduction Digital Image Processing (DIP): Image without noise Acquisition Enhancement / Pre-Processing Segmentation Outcome Segmentation Postprocessing Feature Extraction Recognition Classification 6 1. Introduction Digital Image Processing (DIP): Segmentation Outcome Acquisition Enhancement / Pre-Processing Segmentation Improved Segmentation Postprocessing Feature Extraction Recognition Classification 7 1. Introduction Digital Image Processing (DIP): Improved Segmentation Features ๐ฅ1 = ๐ฅ11 , ๐ฅ12 , … , ๐ฅ1๐ ๐ฅ2 = ๐ฅ21 , ๐ฅ22 , … , ๐ฅ2๐ ๐ฅ3 = ๐ฅ31 , ๐ฅ32 , … , ๐ฅ3๐ ... ... Area, Color, Spatial position, Texture,... Acquisition Enhancement / Pre-Processing Segmentation Postprocessing Feature Extraction Recognition Classification 8 1. Introduction Digital Image Processing (DIP): Scene Understanding Classes Features ๐ฅ1 = ๐ฅ11 , ๐ฅ12 , … , ๐ฅ1๐ ๐ฅ2 = ๐ฅ21 , ๐ฅ22 , … , ๐ฅ2๐ ๐ฅ3 = ๐ฅ31 , ๐ฅ32 , … , ๐ฅ3๐ Acquisition Enhancement / Pre-Processing Segmentation Postprocessing Feature Extraction ... ... ... Area, Color, Spatial position, Texture,... Tree Sky Road Labels Recognition Classification 9 1. Introduction Image Segmentation: “Segmentation subdivides an image into its constituent regions or objects. The level of detail to which the subdivision is carried depends on the problem being solved” – Gonzales & Woods, 2008. Image without noise Acquisition Enhancement / Pre-Processing Segmentation Outcome Segmentation Postprocessing Feature Extraction Recognition Classification 10 1. Introduction Image Segmentation: But...why an image should be segmented? • Provides a more meaningful representation easier to analyze. • Reduces complexity of feature extraction and classification steps. Image Segmentation usually leads to two typical results: Over segmentation Under segmentation 11 1. Introduction Image Segmentation: Image Segmentation partitions the region ๐ in ๐ subregions ๐ 1 , ๐ 2 , … , ๐ ๐ where: ๐ ๐ ๐ = ๐ : each pixel must be in a region. a) ๐=1 b) ๐ ๐ is a connected set ∀๐ = 1,2, … , ๐ c) ๐ ๐ ∩ ๐ ๐ = ∅ ∀๐, ๐; ๐ ≠ ๐ regions must be disjoint. d) ๐ ๐ ๐ =TRUE each pixel has to fulfill certain condition to belong to a segment. e) ๐ ๐ ๐ ∪ ๐ ๐ =FALSE according to the same condition, two regions have to be different. 12 1. Introduction The following presentation: classification was considered for this – High-level taxonomy. – Low-level taxonomy. Taxonomy: Classification 13 1. Introduction High-level taxonomy Image Type • Monochromatic • Color Human Interaction Image Representation • Supervised • Unsupervised • Single scale • Multiscale Image Features • One feature • Multiple features (color, gradient, texture, position, etc.) Principle of Operation • Spatially blind (color) • Spatially guided (spatial position) 14 1. Introduction Low-level taxonomy Spatially guided Spatially blind Clustering • K-means • Mean Shift Histogram thresholding • Otsu segmentation Region based • Region Growing Energy based • Graph-based Based on Regions and Contours • Watersheds 15 Sumário 1. Introduction 2. Spatially blind approaches 3. Spatially guided approaches 16 2. Spatially blind approaches Clustering : Definitions – Cluster: Set formed by similar elements in a certain way. – Clustering: Group data in clusters according to certain similarity criterion. – Feature: Characteristic representative of a data set. For our case, can be considered as features: color, area, perimeter, etc. – Feature Space: ๐-dimensional space formed by the extracted features. Test Image 202 × 302 × 3 17 2. Spatially blind approaches Clustering : K-Means Segmentation Group pixels according to the Euclidian distance between each pixel and the cluster’s centroids. Then, the main goal is to minimze the following target function: ๐ ๐ ๐ฝ๐พ−๐๐๐๐๐ ๐ = ๐ฅ๐ − ๐ฃ๐ 2 ๐=1 ๐=1 ๐ = ๐๐๐๐๐๐{๐ฝ๐พ−๐๐๐๐๐ ๐ } ๐ Where: ๐ฅ๐ : ๐-dimensional feature vector corresponding to the pixel ๐. ๐ฅ๐ = ๐ฅ๐๐ , ๐ฅ๐๐บ , ๐ฅ๐๐ต in the case of RGB images. ๐ฃ๐ : centroid of cluster ๐. ๐: number of clusters. ๐: number of pixels (๐ค๐๐๐กโ × โ๐๐๐โ๐ก) 18 2. Spatially blind approaches Clustering : K-Means Segmentation – Results ๐=3 ๐ =5 Including spatial information: ๐ฅ๐ = Spatial position of the pixel in ๐ฅ๐๐ , ๐ฅ๐๐บ , ๐ฅ๐๐ต , ๐ฅ๐๐ , ๐ฅ๐๐ the image. The clustering will be spatially guided. ๐ =10 ๐ =20 19 2. Spatially blind approaches Clustering : Fuzzy C-Means Segmentation Group pixels according to the Euclidian distance between each pixel and the cluster’s centroids. Then, the main goal is to minimze the following target function: ๐ ๐ ๐ฝ๐ถ−๐๐๐๐๐ = ๐๐๐ ๐ ๐ฅ๐ − ๐ฃ๐ ๐=1 ๐=1 Where: ๐ฅ๐ : ๐-dimensional feature vector corresponding to the pixel ๐. ๐ฃ๐ : centroid of cluster ๐. ๐: number of clusters. ๐: number of pixels (๐ค๐๐๐กโ × โ๐๐๐โ๐ก) ๐๐๐ : degree of membership of pixel ๐ in the cluster ๐. ๐: fuzziness index. 2 Updating centroids: ๐๐ฝ ๐๐๐ , ๐ฃ๐ = 0 → ๐ฃ๐ = ๐๐๐๐ ๐ ๐ ๐=1 ๐๐๐ . ๐ฅ๐ ๐ ๐ ๐=1 ๐๐๐ Updating degrees of membership: ๐๐ฝ ๐๐๐ , ๐ฃ๐ = 0 → ๐๐๐ = ๐๐ฃ๐ 1 ๐ฅ๐ − ๐ฃ๐ ๐ ๐ =1 ๐ ๐−1 1 ๐ฅ๐ − ๐ฃ๐ ๐ ๐−1 20 2. Spatially blind approaches Clustering : Fuzzy C-Means Segmentation – Results ๐=3 ๐ =5 ๐ =10 ๐ =20 21 2. Spatially blind approaches Clustering : Mean-Shift Segmentation Find the local extrema in the density distribution of a data set. 1. Extract features from the image (spatial position and spectral values or color). 2. Choose a search window (shape and probability density function – pdf). 3. Put a search window for each pixel in the image. 4. Compute the window’s center of mass. 5. Move the center of the window to the center of mass. 6. Repeat steps 4 and 5 until the search window stops moving or na sotpping criterion is reached. Centro de Massa Vetor Mean shift Centro de Massa nuevo ... Extração de Atributos Espaço de Atributos (exemplo 2D) 22 2. Spatially blind approaches Clustering : Mean-Shift Segmentation The kernel considering the two features is: ๐พ ๐; ๐๐ 2 , ๐๐2 = 2๐ −๐๐ /2 1 ๐๐ 2 exp − 2 ๐๐ 2 ๐๐ 2 ๐๐ 2๐ −๐๐/2 1 ๐๐ 2 exp − 2 ๐๐2 ๐๐2 ๐๐ Spatial position Color Where: ๐๐ , ๐๐ : Feature vector of dimensionalities ๐๐ , ๐๐ related to the spatial position and color respectively. ๐๐ , ๐๐ : Standard deviation for each kind of feature. It is an exception due to the inclusion of spatial features 23 2. Spatially blind approaches Clustering : Mean-Shift Segmentation – Results ๐๐ 2 = 10, ๐๐2 = 10 ๐๐ 2 = 10, ๐๐2 = 30 ๐๐ 2 ๐๐ 2 = 20, ๐๐2 = 20 ๐๐ 2 =240, ๐๐2 = 20 = 40, ๐๐ = 20 ๐๐ 2 = 10, ๐๐2 = 90 ๐๐ 2 = 90, ๐๐2 = 20 24 2. Spatially blind approaches Histogram Thresholding : Definitions Grayscale Sky 25 2. Spatially blind approaches Histogram Thresholding : Otsu Segmentation Select a threshold that minimizes the intra-group variance. 1. Select an initial threshold ๐ = 1. 2. Threshold the image. 3. Two groups of pixels are created: ๏ง ๐บ1 with pixels < ๐. ๏ง ๐บ2 with pixels ≥ ๐. 4. Compute the proportions that represents each group ๐1 , ๐2 and the variance of each group ๐12 , ๐22 . 5. Compute the intra-group variance: 2 ๐๐ ๐ = ๐1 ๐ ๐12 ๐ + ๐2 ๐ ๐22 ๐ 6. Increase ๐ = ๐ + 1 and repeat steps from 2 to 5 until it is not possible to obtain two groups. 7. The optimal threshold corresponds to the minimum intra-group variance. T ๐ฎ๐ ๐ฎ๐ 26 2. Spatially blind approaches Histogram Thresholding : Otsu Segmentation – Results ๐ = 169 27 Sumário 1. Introduction 2. Spatially blind approaches 3. Spatially guided approaches 28 3. Spatially guided approaches Region based: Definitions – Region Growing: seeds – Region Splitting: – Region Merging: 29 3. Spatially guided approaches Region based: Baatz & Schäpe Segmentation Segmentation based on region growing and merging. 1. Initially, each pixel is considerd as one segment. 2. Later, in each step, a pair of segments is merged into one larger segment. 3. Each merge has na associated cost, a merging cost (๐). 4. A merging occurs when it has a merging cost inferior to an scale parameter. This merge will promote the lowest increase in the global heterogeneity. 5. The segmentation procedure ends when no further merging can be performed. There are two variants based on the heuristic taken to find the best segment for merging: Local Best Mutual Fitting Best (BF)Fitting (LMBF) Lowestmerging merging Lowest cost(๐) (๐) cost Lowest merging cost (๐) 30 3. Spatially guided approaches Region based: Baatz & Schäpe Segmentation The merging cost is calculated as follows: ๐ = ๐๐๐๐๐๐ × โ๐๐๐๐๐ + 1 − ๐๐๐๐๐๐ × โ๐ โ๐๐๐ Color where: ๐๐๐๐๐๐ : color weight. ๐๐๐๐๐๐ ∈ 0,1 Shape ๐ถ ∪๐ถ ๐ถ ๐ถ 1 2 ๐๐๐ฟ๐ฟ ๐ด ๐๐ถ๐๐๐๐ ×โ ๐๐ฟ๐๐๐๐ +− 1๐ด− ×๐๐๐๐ ๐๐ฟ 1 +×๐ดโ๐ถ๐ ๐ข๐๐ฃ × ๐๐ฟ 2 ๐ถ1 ๐ 1 ∪๐ถ2 2 โ๐๐๐๐๐ = ๐ โ๐๐๐ = ๐ฟ๐ฟ Onde: ๐ ๐ถ1 ๐ ๐ถ1: Segments to be merged. ๐ถ , ๐ถ 1 2 ๐๐ข๐๐ฃ๐ถ1 = ๐ถ1 ๐ถ๐๐๐๐ถ1 = ๐ถ1 ∪๐ด๐ถ๐ถ21: Resulting segment merging. ๐after ๐๐ ๐ด๐ถ1 : Area of segment ๐ถ1 . ๐ : Standard deviation of pixels in segment ๐ถ . โ๐๐๐๐ = ๐ด๐ถ๐ถ11 ∪๐ถ2 × ๐ถ๐๐๐๐ถ1 ∪๐ถ2 − ๐ด๐ถ1 × ๐ถ๐๐๐๐ถ1 + ๐ด๐ถ21 × ๐ถ๐๐๐๐ถ1 ๐๐ฟ : Weight corresponding to band ๐ฟ. โ๐ ๐ข๐๐ฃ = ๐ด๐ถ1 ∪๐ถ2 × ๐๐ข๐๐ฃ๐ถ1∪๐ถ2 − ๐ด๐ถ1 × ๐๐ข๐๐ฃ๐ถ1 + ๐ด๐ถ2 × ๐๐ข๐๐ฃ๐ถ2 ๐ถWhere: 1 (blue) , ๐ถ2 : Segments to be merged. ๐ถ๐ถ 2 1(red) : Resulting segment after merging. ๐ถ๐ถ 1 1∪∪๐ถ๐ถ 2 2(green) ๐ด๐ถ1 : Area of segment ๐ถ1 . ๐ ๐ถ1 : Length of the edge of segment ๐ถ1 . ๐ถ ๐๐๐1 : Length of the edge of the bounding box of the segment ๐ถ1 . 31 3. Spatially guided approaches Region based: Baatz & Schäpe Segmentation – Results ๐ = 20, ๐๐๐๐๐๐ = 0.9, ๐๐๐๐๐ = 0.5 ๐ = 50, ๐๐๐๐๐๐ = 0.9, ๐๐๐๐๐ = 0.5 ๐ = 90, ๐๐๐๐๐๐ = 0.9, ๐๐๐๐๐ = 0.5 ๐ = 50, ๐๐๐๐๐๐ = 0.1, ๐๐๐๐๐ = 0.9 ๐ = 50, ๐๐๐๐๐๐ = 0.5, ๐๐๐๐๐ = 0.9 ๐ = 50, ๐๐๐๐๐๐ = 0.9, ๐๐๐๐๐ = 0.9 32 3. Spatially guided approaches Energy based: Graph-based Segmentation An image is modeled as an undirected graph: ๐บ = ๐, ๐ธ , where: ๐: Vertices ๐ธ: Edges Connectivity Matrix Each pixel is a vertex ๐ฃ๐ ∈ ๐. Each edge ๐๐๐ has an associated weight ๐๐๐ . 1 ๐ = ๐๐๐ ; ๐, ๐ ∈ ๐ 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 ๐๐๐ : Similarity measure ↑ ๐๐๐ → pixels are more similar 9 33 3. Spatially guided approaches Energy based: Graph-based Segmentation A cut is: ๐จ ๐๐ข๐ก ๐ด, ๐ต = ๐ ๐ข, ๐ฃ ๐ข∈๐ด,๐ฃ∈๐ต ๐ฉ Minimum Cut; however, it is not the best one. Then, the image can be segmented by looking for minimum cuts. A normalization based on the size of the segments is robust to penalization of big segments. ๐๐ข๐ก ๐ด, ๐ต ๐๐ข๐ก ๐ด, ๐ต ๐๐๐ข๐ก ๐ด, ๐ต = + ๐๐ ๐ ๐๐ ๐ด, ๐ ๐๐ ๐ ๐๐ ๐ต, ๐ where: ๐๐ ๐ ๐๐ ๐ด, ๐ = ๐ ๐ข, ๐ก ๐ข∈๐ด,๐ก∈๐ 34 3. Spatially guided approaches Energy based: Graph-based Segmentation In a matricial way, a minimum cut after simplification is: ๐๐ ๐ซ − ๐พ ๐ min ๐๐๐ข๐ก ๐ = min ๐ ๐ ๐๐ ๐ซ๐ Where: ๐ท ๐, ๐ = ๐๐ ๐, ๐ ; ๐ท ๐, ๐ = 0 (sum of weights of vertex ๐). The solution is given by a problem of generalized eigenvalues: ๐ซ − ๐พ ๐ = ๐๐ซ๐ Solved by conversion to a standard eigenvalue problem: 1 ๐ซ −2 1 −2 1 2 ๐ซ − ๐พ ๐ซ ๐ = ๐๐ where: ๐ = ๐ซ ๐ The solution corresponds to the second smallest eigenvector (the first one is zero). 35 3. Spatially guided approaches Energy based: Graph-based Segmentation – Results ๐๐ ๐๐๐๐๐๐ก๐ = 5 ๐๐ ๐๐๐๐๐๐ก๐ = 10 ๐๐ ๐๐๐๐๐๐ก๐ = 50 ๐๐ ๐๐๐๐๐๐ก๐ = 15 ๐๐ ๐๐๐๐๐๐ก๐ = 20 36 3. Spatially guided approaches Energy based: Segmentation based on Conditional Random Fields Related to a different problem: Semantic Segmentation. Acquisition Enhancement / Pre-Processing Segmentation Postprocessing Feature Extraction Recognition Classification 37 3. Spatially guided approaches Energy based: Segmentation based on Conditional Random Fields The image is modeled as an undirected graph: ๐บ = ๐, ๐ธ , where: ๐: Vertices ๐ธ: Edges The goal is to maximize the following energy function: ๐ธ ๐ = ๐๐ ๐ฅ๐ + ๐∈๐ ๐๐๐ ๐ฅ๐ , ๐ฅ๐ ๐∈๐,๐∈๐๐ where: ๐: random variable over the pixels to be labeled. ๐ฅ๐ : feature vector of pixel ๐. ๐๐ : neighbor pixels of pixel ๐. ๐๐ : Unary term for the pixel ๐. ๐๐๐ : Pairwise term for the edge ๐๐. 38 3. Spatially guided approaches Energy based: Segmentation based on Conditional Random Fields Let’s analyze the energy function: Unary term ๐ธ ๐ = ๐๐ ๐ฅ๐ + ๐∈๐ฑ Position ๐๐๐ ๐ฅ๐ , ๐ฅ๐ ๐∈๐ฑ,๐∈๐๐ Unary term Color Pairwise term Norm of Difference of intensity values Pairwise term Fourier basis Histogram of Gradients (HoG) ๐ค1 ๐๐๐๐ ๐ฅ๐ + ๐ค2 ๐๐๐๐ ๐ฅ๐ + ๐ค3 ๐๐๐๐ข๐๐๐๐ ๐ฅ๐ + ๐ค4 ๐โ๐๐ ๐ฅ๐ 39 3. Spatially guided approaches Energy based: Segmentation based on Conditional Random Fields – Results Result Input Image Reference (Ground Truth) 40 3. Spatially guided approaches Based on Regions and Contours: Watershed Segmentation Use region and contour information to segment an image. The image is visualized as a topographic relief in 3D. Intensity or Gradient 41 3. Spatially guided approaches Based on Regions and Contours: Watershed Segmentation 1. Calculate the gradient module of the image (per band). 2. Consider for each pixel, the maximum value of the gradient per band. 3. A hole is punched in each regional minimum and the entire topography is flooded from below, leaving water rise through the holes at a uniform rate. 4. A threshold ๐ can be set to uniformize the regional minimum. 42 3. Spatially guided approaches Based on Regions and Contours: Watershed Segmentation ๐ = 0.1 ๐ = 0.3 ๐ = 0.5 ๐ = 0.9 43 44 Image Segmentation Qualification Exam Deparment of Electrical Engineering - DEE Pedro M. Achanccaray Diaz Advisor: Raul Queiroz Feitosa