does not able to recognize correct class of the image.
1 view (last 30 days)
Show older comments
%% 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');
function[F]=FeatureStatistical(im)
im=double(im);
m=mean(im(:));
s=std(im(:));
F=[m s];
end
Here I trained 2 calsses using 10 images for each. class -1 is a buildind and class -2 is a mountain.
%% 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,2]);
ctrain=db(:,3);
for(i=1:size(Ftrain,1))
dist(1,:)=sum(abs(Ftrain(1,:)-Ftest));
end
Min=min(dist);
if(Min<50)
m=find(dist==Min,1);
det_class=ctrain(m);
msgbox(strcat('detected class',num2str(det_class)));
else
msgbox('Not Exist');
end
When testing the images using this code it says "Not exist" for even exactly the same image uploaded for test.
4 Comments
Walter Roberson
on 11 Dec 2018
Suppose that after the line
F=FeatureStatistical(im);
that F is a row vector of length 2, such as [93 5.83]. And suppose that db is the empty matrix [].
c=input('Enter the Class (Number from 1-10)');
so c is expected to be a scalar integer. Suppose the user entered 10.
You have the code
F=[F c];
db=[db; F, c];
So before the F=[F c] line, F is [93 5.83] and after that line, F = [93 5.83 10] because you put c on the end of F. Then you have the assignment to db; with empty db that would be
db=[[]; [93 5.83 10], 10]
which would store db = [93 5.83 10 10]
Now my question for you is why you are storing two copies of c in db? The last two elements stored are going to be the same. What benefit does that provide ? Why not just store
db=[db; F];
which would get db=[93 5.83 10] ?
Answers (0)
See Also
Categories
Find more on Numeric Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!