This is my code and I trained two types of classes in there(a building as class 1 and a mountain as class 2). When I upload and try to identified the class always it only output "this belongs to class 1". What will be the wrong of my code?

1 view (last 30 days)
Module training
%% Taking an Image
[fname,path]=uigetfile('.jpg','Open a image as Input for Training');
c=strcat(path,fname);
im=imread(fname);
imshow(im);
title('Input Image');
c=input('Enter the Class (Number from 1-10)');
%% Feature Extraction
F=FeatureStatistical(im);
try
S = load('db.mat');
F=[F c];
db=[db; F, c];
catch ME
disp(ME.message);
% F = reshape(F,[3,2]); % Omit the duplicate reshaping - it has no effect
% F = reshape(F, [1,6]);
db = [F c];
end
save('db.mat', 'db');
feature statistical
function[F]=FeatureStatistical(im)
im=double(im);
m=mean(im(:));
s=std(im(:));
F=[m s];
end
Image Classifier
%% Test Image
[fname,path]=uigetfile('.jpg','Provide a Image for Testing');
c=strcat(path,fname);
im=imread(fname);
imshow(im);
title('Test Image');
%% Fond out which Class it Belongs to
Ftest=FeatureStatistical(im);
%% Compare with Database
load db.mat
Ftrain=db(:,1,1);
ctrain=db(:,3);
for(i=1:size(Ftrain,1))
dist(1,:)=sum(abs(Ftrain(1,:)-Ftest));
end
m=find(dist==min(dist),1);
det_class=ctrain(m);
msgbox(strcat('detected class',num2str(det_class)));

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!