Thursday, September 23, 2010

Activity 13 - Color Image Segmentation

In this activity, a region of interest was chosen from the rest of the image though image segmentation. In this case, colored region of interest were segmented. A monochromatic region was cropped out from an image and then the RGB values were determined and transformed into its normalized chromaticity coordinates. Per pixel, let I = R + G + B. The normalized chromaticity coordinates r, g, b is give by

r = R/I; g = G/I; b = B/I
Equation 1

Since r + g + b = 1, we can express b = 1 - r - g showing the dependence of b on the values of r and g. Therefore, the normalized chromaticity coordinates can be represented by two coordinates with r values on the y axis and g values on the x axis, for this case.

In this activity, parametric and nonparametric methods were used to segment a colored region of interest. In the parametric method, the probability that a pixel belongs to a color distribution of interest is determined. The histogram of the subimage of the region of interest is calculated. Assuming independent Gaussian distribution for r and g, the joint probability of the r and g values will produce the segmented region of interest. The following equation defines the probability that a pixel with chromaticity r belongs to the ROI. Similar equation will be used for the g values.

Equation 2

On the other hand, the nonparametric method used the Histogram Projection technique to segment the region of interest. Figure1 to 3 show three different images with different color of region of interest. As observed, the nonparametric method showed more quality in color segmentation of the desired region of interest.



(a)
(b)
(c)
(d)
Figure 1. (a) An image of group of friends surrounded by water.
(b) Segmented using the Parametric Method.
(c) Segmented using the Nonparametric Method.
(d) Cropped Color of interest and location in the chromaticity coordinates.




(a)
(b)
(c)
(d)
Figure 2. (a) An image of mount of ice cream.
(b) Segmented using the Parametric Method.
(c) Segmented using the Nonparametric Method.
(d) Cropped Color of interest and location in the chromaticity coordinates.



(a)
(b)
(c)
(d)
Figure 3. (a) An image of a child holding a red toy.
(b) Segmented using the Parametric Method.
(c) Segmented using the Nonparametric Method.
(d) Cropped Color of interest and location in the chromaticity coordinates.

Self-Evaluation:
Credits:

Appendix: Source Code
stacksize(100000000);

PATH = 'C:\Users\Micent\Documents\Applied Physics\acad 2010-2011 1st sem\App Phy 186 - Instrumentation Physics II\Activity 13\';
ROI = 'melissa';
subimage = 'red';

//region of interest
I1 = imread(strcat([PATH,ROI,'.jpg']));
[r,c] = size(I1);
I1 = double(I1);
R1 = I1(:,:,1);
G1 = I1(:,:,2);
B1 = I1(:,:,3);

Int1 = R1 + G1 + B1;

Int1(find(Int1==0))=100000;

r1 = R1./Int1;
g1 = G1./Int1;

//subregion of ROI
I2 = imread(strcat([PATH,subimage,'.jpg']));
I2 = double(I2);
R2 = I2(:,:,1);
G2 = I2(:,:,2);
B2 = I2(:,:,3);

Int2 = R2 + G2 + B2;

Int2(find(Int2==0))=100000;

r2 = R2./Int2;
g2 = G2./Int2;


//Parametric Segmentation
ur = mean(r2); ug = mean(g2);
sr = stdev(r2); sg = stdev(g2);

pr = (1/(sr*sqrt(2*%pi)))*exp(-(r1-ur).^2/(2*sr^2));
pg = (1/(sg*sqrt(2*%pi)))*exp(-(g1-ug).^2/(2*sg^2));
I3 = pr.*pg; //segmented image

//imwrite(I3,strcat([PATH,ROI,'_',subimage,'_parametric','.jpg']));


//Non-parametric Segmentation
// Histogram Plot
BINS = 256;
rint = round(r2*(BINS-1) + 1);
gint = round(g2*(BINS-1) + 1);

colors = gint(:) + (rint(:)-1)*BINS;

hist = zeros(BINS,BINS);

for row = 1:BINS
for col = 1:(BINS-row+1)
hist(row,col) = length(find(colors==(((col + (row-1)*BINS)))));
end;
end;
scf(1); imshow(hist,[]);
scf(2); mesh(hist);
xs2bmp(1,strcat([PATH,subimage,"_histogram','.bmp']));

//Histogram Backprojection
I4 = zeros(r,c); //segmented image

r1B = r1*(BINS-1); //uniform
g1B = g1*(BINS-1); //uniform
//Pixel-per-Backprojection
for i = 1:r
for j = 1:c
m = round(r1B(i,j)) + 1;
n = round(g1B(i,j)) + 1;
I4(i,j) = hist(m,n);
end
end

imwrite(I4,strcat([PATH,ROI,'_',subimage,'_nonparametric','.jpg']));

No comments:

Post a Comment