Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into...

33
Image Segmentation Image Segmentation Longin Jan Latecki Longin Jan Latecki CIS 601 CIS 601

Transcript of Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into...

Page 1: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Image SegmentationImage Segmentation

Longin Jan LateckiLongin Jan Latecki

CIS 601CIS 601

Page 2: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Image SegmentationImage Segmentation

Segmentation divides an image into its Segmentation divides an image into its constituent regions or objects.constituent regions or objects.

Segmentation of non trivial images is one of Segmentation of non trivial images is one of the difficult task in image processing. Still the difficult task in image processing. Still under research.under research.

Segmentation accuracy determines the Segmentation accuracy determines the eventual success or failure of computerized eventual success or failure of computerized analysis procedure.analysis procedure.

Page 3: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Segmentation AlgorithmsSegmentation Algorithms

Segmentation algorithms are based on one of Segmentation algorithms are based on one of two basic properties of intensity values two basic properties of intensity values discontinuity and similarity.discontinuity and similarity.

First category is to partition an image based on First category is to partition an image based on abrupt changes in intensity, such as edges in an abrupt changes in intensity, such as edges in an image.image.

Second category are based on partitioning an Second category are based on partitioning an image into regions that are similar according to a image into regions that are similar according to a predefined criteria. Histogram thresholding predefined criteria. Histogram thresholding approach falls under this category.approach falls under this category.

Page 4: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Domain spaces

spatial domain (row-column (rc) space)

histogram spaces

color space

other complex feature space

Page 5: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

HistogramsHistograms

Histogram are constructed by splitting the range Histogram are constructed by splitting the range of the data into equal-sized bins (called classes). of the data into equal-sized bins (called classes). Then for each bin, the number of points from the Then for each bin, the number of points from the data set that fall into each bin are counted. data set that fall into each bin are counted. Vertical axis: Frequency (i.e., pixel counts for Vertical axis: Frequency (i.e., pixel counts for each bin) each bin) Horizontal axis: Response variableHorizontal axis: Response variableIn image histograms the pixels form the In image histograms the pixels form the horizontal axis horizontal axis

Page 6: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Thresholding - FoundationThresholding - Foundation

Suppose that the gray-level histogram Suppose that the gray-level histogram corresponds to an image f(x,y) composed of corresponds to an image f(x,y) composed of dark objects on the light background, in such a dark objects on the light background, in such a way that object and background pixels have gray way that object and background pixels have gray levels grouped into two dominant modes. One levels grouped into two dominant modes. One obvious way to extract the objects from the obvious way to extract the objects from the background is to select a threshold ‘T’ that background is to select a threshold ‘T’ that separates these modes. separates these modes. Then any point (x,y) for which f(x,y) < T is called Then any point (x,y) for which f(x,y) < T is called an object point, otherwise, the point is called a an object point, otherwise, the point is called a background point.background point.

Page 7: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Example Example

Page 8: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Gray Scale Image - bimodalGray Scale Image - bimodal

Image of a Finger Print with light background

Page 9: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Segmented ImageSegmented Image

Image after Segmentation

Page 10: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

In Matlab histograms for images can be In Matlab histograms for images can be constructed using the imhist command.constructed using the imhist command.

I = imread('pout.tif');

figure, imhist(I) %look at the hist to get a threshold, e.g., 110

BW=roicolor(I, 110, 255); % makes a binary image

figure, imshow(BW) % all pixels in (110, 255) will be 1 and white

% the rest is 0 which is black

roicolor returns a region of interest selected as those pixels in I that match the values in the gray level interval.

BW is a binary image with 1's where the values of I match the values of the interval.

Page 11: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Bimodal HistogramBimodal Histogram

If two dominant modes characterize the If two dominant modes characterize the image histogram, it is called a bimodal image histogram, it is called a bimodal histogram. Only one threshold is enough histogram. Only one threshold is enough for partitioning the image.for partitioning the image.

If for example an image is composed of If for example an image is composed of two types of dark objects on a light two types of dark objects on a light background, three or more dominant background, three or more dominant modes characterize the image histogram.modes characterize the image histogram.

Page 12: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Multimodal HistogramMultimodal Histogram

In such a case the histogram has to be In such a case the histogram has to be partitioned by multiple thresholds.partitioned by multiple thresholds.

Multilevel thresholding classifies a point (x,y) as Multilevel thresholding classifies a point (x,y) as belonging to one object class belonging to one object class

if T1 < (x,y) <= T2, if T1 < (x,y) <= T2,

to the other object class to the other object class

if f(x,y) > T2 if f(x,y) > T2

and to the background and to the background

if f(x,y) <= T1.if f(x,y) <= T1.

Page 13: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Thresholding Bimodal HistogramThresholding Bimodal Histogram

Basic Global Thresholding: Basic Global Thresholding: 1)Select an initial estimate for T1)Select an initial estimate for T 2)Segment the image using T. This will produce two groups of pixels. 2)Segment the image using T. This will produce two groups of pixels.

G1 consisting of all pixels with gray level values >T and G2 G1 consisting of all pixels with gray level values >T and G2 consisting of pixels with values <=T.consisting of pixels with values <=T.

3)Compute the average gray level values mean1 and mean2 for the 3)Compute the average gray level values mean1 and mean2 for the pixels in regions G1 and G2.pixels in regions G1 and G2.

4)Compute a new threshold value 4)Compute a new threshold value T=(1/2)(mean1 +mean2)T=(1/2)(mean1 +mean2) 5)Repeat steps 2 through 4 until difference in T in successive 5)Repeat steps 2 through 4 until difference in T in successive

iterations is smaller than a predefined parameter T0.iterations is smaller than a predefined parameter T0.

Basic Adaptive Thresholding: Images having uneven illumination Basic Adaptive Thresholding: Images having uneven illumination makes it difficult to segment using histogram, this approach is to makes it difficult to segment using histogram, this approach is to divide the original image into sub images and use the above said divide the original image into sub images and use the above said thresholding process to each of the sub images. thresholding process to each of the sub images.

Page 14: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Thresholding multimodal histogramsThresholding multimodal histograms

A method based on A method based on

Discrete Curve EvolutionDiscrete Curve Evolution

to find thresholds in the histogram.to find thresholds in the histogram.

The histogram is treated as a polylineThe histogram is treated as a polylineand is simplified until a few vertices and is simplified until a few vertices remain. remain.

Thresholds are determined by vertices that Thresholds are determined by vertices that are local minima.are local minima.

Page 15: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Discrete Curve Evolution (DCE)Discrete Curve Evolution (DCE)

u

v

w u

v

w

It yields a sequence: P=P0, ..., Pm

Pi+1 is obtained from Pi by deleting the vertices of Pi that have minimal relevance measure

K(v, Pi) = |d(u,v)+d(v,w)-d(u,w)|

>

Page 16: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Example Example

Page 17: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Thresholding – Colour ImagesThresholding – Colour Images

In colour images each pixel is In colour images each pixel is characterized by three RGB values.characterized by three RGB values.

Here we construct a 3D histogram, and Here we construct a 3D histogram, and the basic procedure is analogous to the the basic procedure is analogous to the method used for one variable.method used for one variable.

Histograms plotted for each of the colour Histograms plotted for each of the colour values and threshold points are found.values and threshold points are found.

Page 18: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Displaying objects in the Displaying objects in the Segmented ImageSegmented Image

The objects can be distinguished by The objects can be distinguished by assigning a arbitrary pixel value or assigning a arbitrary pixel value or average pixel value to the regions average pixel value to the regions separated by thresholds.separated by thresholds.

Page 19: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Experiments by Venugual RajagupalExperiments by Venugual Rajagupal

Type of images used:Type of images used:

1) Two Gray scale image having bimodal 1) Two Gray scale image having bimodal histogram structure.histogram structure.

2) Gray scale image having multi-modal 2) Gray scale image having multi-modal histogram structure.histogram structure.

3) Colour image having bimodal histogram 3) Colour image having bimodal histogram structure.structure.

Page 20: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Gray Scale Image - bimodalGray Scale Image - bimodal

Image of rice with black background

Page 21: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Segmented ImageSegmented Image

Image after segmentationImage histogram of rice

Page 22: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Gray Scale Image - MultimodalGray Scale Image - Multimodal

Original Image of lena

Page 23: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Multimodal HistogramMultimodal Histogram

Histogram of lena

Page 24: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Segmented ImageSegmented Image

Image after segmentation – we get a outline of her face, hat, shadow etc

Page 25: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Colour Image - bimodalColour Image - bimodal

Colour Image having a bimodal histogram

Page 26: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

HistogramHistogram

Histograms for the three colour spaces

Page 27: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Segmented ImageSegmented Image

Segmented image – giving us the outline of her face, hand etc

Page 28: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Clustering in Color SpaceClustering in Color Space

Each image point is mapped to a point in a color space, e.g.:

Color(i, j) = (R (i, j), G(i, j), B(i, j))

The points in the color space are grouped to clusters.The clusters are then mapped back to regions in the image.

Page 29: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Resluts 1Resluts 1

Mnp: 30, percent 0.05, cluster number 4

Mnp : 20, percent 0.05, cluster number 7

Original pictures segmented pictures

Page 30: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

k-means Clusteringk-means Clustering

An algorithm for partitioning (or clustering) An algorithm for partitioning (or clustering) NN data points into data points into KK disjoint subsets disjoint subsets SSjj containing containing NNjj data points so as to minimize data points so as to minimize the sum-of-squares criterion the sum-of-squares criterion

2

1

|| j

K

j Snn

j

xJ

where xn is a vector representing the nth data point and j is

the geometric centroid of the data points in SSjj    

Page 31: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

The algorithm consists of a simple re-estimation procedure:

•First, K centroid points are selected j, e.g., at random.

•Second, each data points is assigned to

the cluster SSjj of the closest centroid j.

•Third, the centroid j is recomputed for each cluster set.

The steps two and three are alternated until a stopping criterion is met, i.e., when there is no further change in the assignment of the data points.

In general, the algorithm does not achieve a global minimum of J over the assignments. In fact, since the algorithm uses discrete assignment rather than a set of continuous parameters, the "minimum" it reaches cannot even be properly called a local minimum. Despite these limitations, the algorithm is used frequently as a result of its ease of implementation.

Homework:

Implement in Matlab and test on some example images the clustering in the color space. You can use k-means or some other clustering algorithm.

Page 32: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

Matlab exampleMatlab example

Matlab programs are in www.cis.temple.edu/~latecki/CIS601-03/Lectures/Matlab/Clustering/

data=load('irises1.dat'); % loads a classic data set of Irises

[distance,cluster,tse] = kmeans1(data,3); %starts k-means clustering

showcluster(cluster,'irises1.dat'); % shows clusters in 3D projection obtained by PCA

[output_matrix] = test_tableform('ireses_gt.txt',cluster,3);%if the ground truth is know, this function compares the clustering result to it

Page 33: Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.

ConclusionConclusion

After segmenting the image, the contours of After segmenting the image, the contours of objects can be extracted using edge objects can be extracted using edge detection and/or border following techniques. detection and/or border following techniques.

Image segmentation techniques are Image segmentation techniques are extensively used in Similarity Searches, e.g.: extensively used in Similarity Searches, e.g.:

http://elib.cs.berkeley.edu/photos/blobworld/http://elib.cs.berkeley.edu/photos/blobworld/