TP5 Image Segmentation
TP5 Image Segmentation
Matlab commands
allows calculating, using Otsu's method,
thresh = multithresh(I,N); the N segmentation thresholds of the image I.
thres: would be a vector of size × ( )
Manipulation
1. Read the image 'medtest.png', assign it to the variable I, then display it.
2. Display its histogram. Distinguish the separable areas on the histogram.
3. calculate a segmentation threshold(N = 1)
1
4. segment the image I, to obtain the matrix Is.
open the Is matrix, and check that its content is made up of 0 and 1
Display the segmentation result
5. Calculate two segmentation thresholds(N = 2)
6. segment the image I, to obtain the label matrixIs,
open the matrix Is, and check that its content is made up of 0, 1, and 2
convert it to a color image
Display the segmentation result
commenter
7. Rephrase question 6. for = 3, then4
Matlab Commands:
Allows to apply the algorithm of
growth of a single region:
in image I,
around the germ (initial pixel) of
coordonnées [x,y],
J = regiongrowing(I,x,y,sigma_R); the standard deviation of the region sigma_R
J is the same size as I, it is a
matrix of labels and
where the values are:
. 1 (true): segmented point
. 0 (false): non-segmented point
Allows to extract the coordinates of the
[x, y] = getpts; point of the figure pointed with the
mouse
Manipulation
1. Read the image'medtest.png', assign it to the variable I, and convert it to double precision.
Choose as the germ the point[x y] = [198 359
2
3. Apply the region growth algorithm to segment a region with a standard deviation of 0.2.
around this germ. You will obtain an image (matrix) of labels , which we will call
segmented image.
4. Display the segmented image on the original image
figure, imshow(I+J);
Matlab Commands:
Allows for the classification of the points of vector X into k classes
classification result, label vector
vector)
oIdx is the same size as X.
[idx,C] = kmeans(X,k); the label (classification) of each point X at index i,
is contained in Idx at the same index i.
The possible values of Idx are the values of the labels
(classes) : 1, 2, 3, ..., k.
C: a vector of size ( × ), it contains the k-centers of
classes.
Manipulation:
1. Read and display the image in grayscale'medtest.png', assign it to the variableI
2. Rearrange the pixels of I into a single column II
3. Apply the k-means algorithm to classify the points of II into 2 regions. You will obtain the
vector of labels (idx) and the centers of classes (C)
What are the centers of the regions.
4. Rearrange the label vector idx into a matrix Is, then display it.
Observe the 2 regions
5. Change the number of classes (regions) to 3 and then to 4.
commenter.
It is a method that aims first to divide the image into homogeneous regions according to a certain
criterion (predicate)
Then operate to merge the obtained regions that are similar according to this same predicate, in
one single region
Matlab commands:
Allows for the segmentation of image I by the division/merging method.
a: is the minimum size of image blocks during the operation of
J = splitmerge(I, a, division. It is a number 2 to the power of: 1, 2, 4, 8, 16, ...
@predicate);
@predicate : is a function that contains the criteria of
division/fusion
the obtained matrix J is a label matrix.
Matlab Functions:
functionflag = predicate(region) Go to the 'predicate' function and change the
sd = std2(region); parameters following by the desired values:
m = mean2(region); ecart_typestandard deviation of the region to
ecart_type = 20; %%%
val_min = 0; %%%
segmenter
val_max = 200; %%% val_minminimum value of the gray level
flag = (sd > ecart_type) ... in the region to be segmented
& (m > val_min) & (m < val_max); val_max:maximum value of the gray level
in the region to be segmented
4
Manipulation:
1.Read and display the image in grayscale.'medtest.png', assign it to the variableI
2. Apply the divide/conquer algorithm,
by dividing the image into blocks of minimal size2
according to the predicates :
standard deviation = 20
5
histogram thresholding
I = imread('medtest.png');
show image(I); figure, show histogram(I);
thres = multithresh(I, 4);
Is = imquantize(I, thres);
Irgb = label2rgb(Is);
figure;
show image(Irgb)
k-means
I = imread('medtest.png');
II=im2col(I,size(I));
[idx,C] = kmeans(II,4);
Is=col2im(idx,[1, 1],size(I));
Is=label2rgb(Is);
growing_region
% case1
I = im2double(imread('medtest.png'));
x=198; y=359;
J = regiongrowing(I,x,y,0.2);
figure, imshow(I+J);
% cas2
[x, y] = getpts; x=uint8(x); y=uint8(y);
J1 = regiongrowing(I,x,y,0.2);
figure, imshow(I+J+J1);
% case 3
figure(3), imshow(I);
Js=zeros(size(I)); %initial segmented image set to 0
for i=1:4
figure(3)
[x, y] = getpts; x=uint8(x); y=uint8(y);
sig=0.4; %écart type = 0.2; 0.3; 0.4, ... ;
J = regiongrowing(I, x, y, sig);
Js=Js+J*i; %label the segmented region J with i
label2rgb(Js);
figure(4), imshow(Js_rgb));
pause,
end
Division/fusion
I = (imread('medtest.png'));
J = splitmerge(I, 4, @predicate);
Jrgb=label2rgb(J);
figure, imshow(Jrgb);
functionflag = predicate(region)
sd = std2(region);
m = mean2(region);
ecart_type = 20;
val_min = 0;
val_max = 200;
(sd > ecart_type) & (m > val_min) & (m < val_max);
6