Professional Documents
Culture Documents
clear all;
close all;
ITERATIONS = 10;
POPULATION = 50;
red = img(r,c,1);
green = img(r,c,2);
blue = img(r,c,3);
try
if(c == 1 && mod(r,50) == 0)
svm_img = img(r:r+49);
new_pop = [];
for count=1:ITERATIONS
pop = new_pop;
fitness_arr = zeros([1 POPULATION]);
for pop_count=1:POPULATION
idx = ceil(rand*3);
pop(pop_count,1) = idx;
fitness = 0;
%Find the population fitness
if(idx == 1 && cotton == 255)
pop(pop_count,2) = 2;
pop(pop_count,3) = 3;
fitness = fitness + 1;
elseif(idx == 2 && wheat == 255)
pop(pop_count,2) = 1;
pop(pop_count,3) = 3;
fitness = fitness + 1;
elseif(idx == 3 && gram == 255)
pop(pop_count,2) = 1;
pop(pop_count,3) = 2;
fitness = fitness + 1;
end
fitness_arr(pop_count) = fitness;
end
cw = svmclassify(svm_cw,double(pop_best'));
cg = svmclassify(svm_cg,double(pop_best'));
wg = svmclassify(svm_wg,double(pop_best'));
%Now get the max class
total_class = [cw;cg;wg];
length_cotton = length(find(total_class == 1));
length_wheat = length(find(total_class == 2));
length_gram = length(find(total_class == 3));
end
end
img_classified = rgb2gray(out_img);
img_classified = imresize(img_classified,[256 256]);
img_classified = img_classified + (abs(min(min(img_classified))));
img_classified = img_classified / (max(max(img_classified)));
img_classified = round(img_classified*255);
kappa = abs(findKappa(double(img_classified),-1,0.5));
time = toc;
disp('SVM + GA');
kappa
time
fprintf('\n');
subplot(2,1,1);
imshow(img);
title('Original Image');
subplot(2,1,2);
imshow(out_img);
title('Classified Image (R:Cotton,G:Wheat:B:Gram');