A region of interest (ROI) from a colored image is segmented in this activity using two types of segmentation - Parametric and Non-parametric.
The following image is searched from the internet.
Source: http://www.justfurfun.org/doghtml/yorikpage.htm
The blue ball which the dog holds is the ROI used for segmentation. A monochromatic patch is then cropped from the ROI and this is shown below.
This monochromatic patch is the basis of extracting the ROI from the whole image. Its normalized primary color channels red (R), green (G), and blue (B) separately with the whole image's are obtained next. This is done by dividing each color channel element-by-element to the sum of the RGB arrays resulting to the normalized chromaticity coordinates for red (r), green (g), and blue (b). The normalized chromaticity space is as follows.
Here, the 3 dimensional color space is reduced to only 2 having red as the horizontal axis and green as the vertical axis. Of course, blue has its region in the normalized chromaticity space since the relation between the normalized chromaticity coordinates is r + g + b = 1. Normalizing the color channels of the whole image and the patch of the ROI is very important because the shade or brightness of the colors of the whole image and the ROI is separated from their pure colors or chromaticities and so the image is segmented correctly.
Parametric segmentation is the first type implemented to the image. In this process, the probability of each pixel from the whole image belonging to the chromaticity of the ROI is determined through a Gaussian distribution having the form as shown below.
From the expressions above, sigma is the standard deviation of the normalized chromaticities of the patch of the ROI while mu is the mean. Then, r and g come from the normalized chromaticities of each pixel of the whole image. The segmented image is then generated from the multiplied or joint probabilities in the red and blue normalized channels. This is illustrated as follows.
Apparently, the white region represents the ROI that is the blue ball. Comparing from the original image with the blue ball, the image is well segmented since various shades of the ROI are indeed ignored and thus the whole blue ball is almost separated from the image.
Non-parametric segmentation operates in the probability distribution of the normalized chromaticity of the ROI alone without depending to a function such as the Gaussian distribution employed in the parametric segmentation. A 2 dimensional histogram is acquired here as shown below which is then verified from the normalized chromaticity space.
Both histograms above are comparable to the normalized chromaticity space, their bins are just varied for the sake of visualization (left histogram with 32 bins) and application of the histogram backprojection process (right histogram with 256 bins). The histogram agrees with the normalized chromaticity space since the peaks are located within the blue region knowing that the ROI has chromaticity within this area.
The histogram backprojection is where each pixel in the image is assigned to a value corresponding to the histogram value in the normalized chromaticity space. Hence, it is essential to increase the bins of the histogram to 256 in order to accommodate the 256 rounded integer values in the normalized chromaticity space. Finally, the result of the non-parametric segmentation is the following.
It can be observed that the image is not that well segmented compared to the parametric approach since majority of the blue ball particularly at the bottom part where its brightness is minimal is not extracted. The good thing about non-parametric segmentation is that no function is needed, instead, just the histogram of a monochromatic patch from the ROI is required. Therefore, for this case, a Gaussian function works great as basis of probability distribution for image segmentation.
Since I have successfully done and understand parametric and non-parametric segmentation of a colored image, I give myself 10/10 in this activity.
Throughout the activity, I have worked independently in its completion. However, I shared useful ideas that have helped my classmates.
Appendix
Below is the whole Scilab code utilized in this Activity.
stacksize(4e7);
image = imread('big_blue_ball.jpg');
I = imread('ROI.jpg');
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
RGB = R + G + B;
r = R./RGB;
b = B./RGB;
g = G./RGB;
Ri = image(:,:,1);
Gi = image(:,:,2);
Bi = image(:,:,3);
RGBi = Ri + Gi + Bi;
ri = Ri./RGBi;
bi = Bi./RGBi;
gi = Gi./RGBi;
// Parametric Segmentation
rmean = mean(r);
gmean = mean(g);
rsigma = stdev(r);
gsigma = stdev(g);
rp = (1/(rsigma*sqrt(2*%pi)))*exp(-((ri - rmean).^2)/(2*rsigma^2));
gp = (1/(gsigma*sqrt(2*%pi)))*exp(-((gi - gmean).^2)/(2*gsigma^2));
rgp = round(rp.*gp);
//scf(0);
//imshow(rgp);
//imwrite(rgp, 'parametric segment.bmp');
// Non-parametric Segmentation
// 2D Histogram Plot
BINS = 256;
rint = round(r*(BINS - 1) + 1);
gint = round(g*(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
histo = hist/max(hist);
//scf(1);
//mesh(histo);
// Backprojection
rib = ri*255;
gib = gi*255;
[a, b] = size(image);
segment = zeros(a, b);
for i = 1:a
for j = 1:b
c = round(rib(i, j)) + 1;
d = round(gib(i, j)) + 1;
segment(i, j) = hist(c, d);
end
end
//scf(2);
//imshow(segment);
//imwrite(segment, 'nonparametric segment.bmp');
The following image is searched from the internet.
Source: http://www.justfurfun.org/doghtml/yorikpage.htm
The blue ball which the dog holds is the ROI used for segmentation. A monochromatic patch is then cropped from the ROI and this is shown below.
This monochromatic patch is the basis of extracting the ROI from the whole image. Its normalized primary color channels red (R), green (G), and blue (B) separately with the whole image's are obtained next. This is done by dividing each color channel element-by-element to the sum of the RGB arrays resulting to the normalized chromaticity coordinates for red (r), green (g), and blue (b). The normalized chromaticity space is as follows.
Here, the 3 dimensional color space is reduced to only 2 having red as the horizontal axis and green as the vertical axis. Of course, blue has its region in the normalized chromaticity space since the relation between the normalized chromaticity coordinates is r + g + b = 1. Normalizing the color channels of the whole image and the patch of the ROI is very important because the shade or brightness of the colors of the whole image and the ROI is separated from their pure colors or chromaticities and so the image is segmented correctly.
Parametric segmentation is the first type implemented to the image. In this process, the probability of each pixel from the whole image belonging to the chromaticity of the ROI is determined through a Gaussian distribution having the form as shown below.
From the expressions above, sigma is the standard deviation of the normalized chromaticities of the patch of the ROI while mu is the mean. Then, r and g come from the normalized chromaticities of each pixel of the whole image. The segmented image is then generated from the multiplied or joint probabilities in the red and blue normalized channels. This is illustrated as follows.
Apparently, the white region represents the ROI that is the blue ball. Comparing from the original image with the blue ball, the image is well segmented since various shades of the ROI are indeed ignored and thus the whole blue ball is almost separated from the image.
Non-parametric segmentation operates in the probability distribution of the normalized chromaticity of the ROI alone without depending to a function such as the Gaussian distribution employed in the parametric segmentation. A 2 dimensional histogram is acquired here as shown below which is then verified from the normalized chromaticity space.
Both histograms above are comparable to the normalized chromaticity space, their bins are just varied for the sake of visualization (left histogram with 32 bins) and application of the histogram backprojection process (right histogram with 256 bins). The histogram agrees with the normalized chromaticity space since the peaks are located within the blue region knowing that the ROI has chromaticity within this area.
The histogram backprojection is where each pixel in the image is assigned to a value corresponding to the histogram value in the normalized chromaticity space. Hence, it is essential to increase the bins of the histogram to 256 in order to accommodate the 256 rounded integer values in the normalized chromaticity space. Finally, the result of the non-parametric segmentation is the following.
It can be observed that the image is not that well segmented compared to the parametric approach since majority of the blue ball particularly at the bottom part where its brightness is minimal is not extracted. The good thing about non-parametric segmentation is that no function is needed, instead, just the histogram of a monochromatic patch from the ROI is required. Therefore, for this case, a Gaussian function works great as basis of probability distribution for image segmentation.
Since I have successfully done and understand parametric and non-parametric segmentation of a colored image, I give myself 10/10 in this activity.
Throughout the activity, I have worked independently in its completion. However, I shared useful ideas that have helped my classmates.
Appendix
Below is the whole Scilab code utilized in this Activity.
stacksize(4e7);
image = imread('big_blue_ball.jpg');
I = imread('ROI.jpg');
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
RGB = R + G + B;
r = R./RGB;
b = B./RGB;
g = G./RGB;
Ri = image(:,:,1);
Gi = image(:,:,2);
Bi = image(:,:,3);
RGBi = Ri + Gi + Bi;
ri = Ri./RGBi;
bi = Bi./RGBi;
gi = Gi./RGBi;
// Parametric Segmentation
rmean = mean(r);
gmean = mean(g);
rsigma = stdev(r);
gsigma = stdev(g);
rp = (1/(rsigma*sqrt(2*%pi)))*exp(-((ri - rmean).^2)/(2*rsigma^2));
gp = (1/(gsigma*sqrt(2*%pi)))*exp(-((gi - gmean).^2)/(2*gsigma^2));
rgp = round(rp.*gp);
//scf(0);
//imshow(rgp);
//imwrite(rgp, 'parametric segment.bmp');
// Non-parametric Segmentation
// 2D Histogram Plot
BINS = 256;
rint = round(r*(BINS - 1) + 1);
gint = round(g*(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
histo = hist/max(hist);
//scf(1);
//mesh(histo);
// Backprojection
rib = ri*255;
gib = gi*255;
[a, b] = size(image);
segment = zeros(a, b);
for i = 1:a
for j = 1:b
c = round(rib(i, j)) + 1;
d = round(gib(i, j)) + 1;
segment(i, j) = hist(c, d);
end
end
//scf(2);
//imshow(segment);
//imwrite(segment, 'nonparametric segment.bmp');
For independent work and exceptional clarity you deserve an 11.
ReplyDelete