The area was obtained by simply binarizing the images and summing the pixels. red-and-green contrast is defined by the following.
We let r be the contrast in the red channel: r = (max(r) - min(r))/(max(r) + min(r))
We let g be the contrast in the green channel: g = (max(g) - min(g))/(max(g) + min(g))
The red-and-green contrast is given by the rg = sqrt(r*r + g*g).
I designated piattos as 1 and pillows as 2.
Piattos features:
---RG---- ----Area----
0.3130230 5428.
0.2596636 6817.
0.2721711 5223.
0.3666842 5742.
Then I input a series of images consisting of four consecutive piattos and four consecutive pillows.
The output of the program below, which made use of minimum distance classification, was
//for piattos
piattos = [];
for i = 1:4
M = imread(strcat('D:\ap186\september17\piatos'+string(i)+'.jpg'));
r = M(:,:,1);
g = M(:,:,2);
contrast_r = (max(r)-min(r))/(max(r)+min(r));
contrast_g = (max(g)-min(g))/(max(g)+min(g));
piattos(1,i) = sqrt(contrast_r*contrast_r + contrast_g*contrast_g);
M_gray = im2gray(M);
M_bw = im2bw(abs(1-M_gray),0.78);
piattos(2,i) = sum(M_bw);
end
//for pillows
pillow = [];
for i = 1:4;
M = imread(strcat('D:\ap186\september17\pillow'+string(i)+'.jpg'));
r = M(:,:,1);
g = M(:,:,2);
contrast_r = (max(r)-min(r))/(max(r)+min(r));
contrast_g = (max(g)-min(g))/(max(g)+min(g));
pillow(1,i) = sqrt(contrast_r*contrast_r + contrast_g*contrast_g);
M_gray = im2gray(M);
M_bw = im2bw(abs(1-M_gray),0.6);
pillow(2,i) = sum(M_bw);
end
m = [];
m(:,1) = sum(piattos,'c')/size(piattos,2);
m(:,2) = sum(pillow,'c')/size(pillow,2);
//for test samples
test = [];
for i = 1:8
M = imread(strcat('D:\ap186\september17\test\'+string(i)+'.jpg'));
r = M(:,:,1);
g = M(:,:,2);
contrast_r = (max(r)-min(r))/(max(r)+min(r));
contrast_g = (max(g)-min(g))/(max(g)+min(g));
test(1,i) = sqrt(contrast_r*contrast_r + contrast_g*contrast_g);
M_gray = im2gray(M);
M_bw = im2bw(abs(1-M_gray),0.63);
test(2,i) = sum(M_bw);
end
//Minimum distance classification
d = [];
for i = 1:8
for j = 1:2
d(j,i) = test(:,i)'*m(:,j) - m(:,j)'*m(:,j);
end
end
d = abs(d);
x =[];
for i = 1:8
x(i) = find(d==min(d(:,i)));
end
for i = 1:length(x);
x(i) = x(i) - 2*(i-1);
end
x
SELF-GRADE: 10/10 because I have 100% accuracy
No comments:
Post a Comment