How to classify images using SVM classifier?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I am new to MATLAB.I have used SVM to classify lion and tiger images.But while testing,if I give lion image I get 1as result.Also,when I give tiger image as testing image,I get result as 1.What is the reason that I get 1during both the cases.How to rectify it.Can anyoneplease help me?
%clear all;
clc;
folder = 'gambar 1';
dirImage = dir( folder );
numData = size(dirImage,2);
M ={} ;
% baca data gambar
for i=1:numData
nama = dirImage(i).name;
if regexp(nama, '(lion|tiger)-[0-9]{1,2}.jpg')
B = cell(1,2);
if regexp(nama, 'lion-[0-9]{1,2}.jpg')
B{1,1} = double(imread([folder, '/', nama]));
B{1,2} = 1;
elseif regexp(nama, 'tiger-[0-9]{1,2}.jpg')
B{1,1} = double(imread([folder, '/', nama]));
B{1,2} = 2;
end
M = cat(1,M,B);
end
end
% konversi gambar untuk keperluan SVM
numDataTrain = size(M,1);
class = zeros(numDataTrain,1);
arrayImage = zeros(numDataTrain, 300 * 300);
for i=1:numDataTrain
im = M{i,1} ;
im = rgb2gray(im);
im = imresize(im, [300 300]);
im = reshape(im', 1, 300*300);
arrayImage(i,:) = im;
class(i) = M{i,2};
end
SVMStruct = fitcsvm(arrayImage, class);
% test untuk lion
lionTest = double(imread('gambar 1/tiger-test.jpg' ));
lionTest = rgb2gray(lionTest);
lionTest = imresize(lionTest, [300 300]);
lionTest = reshape(lionTest',1, 300*300);
result = predict(SVMStruct, lionTest);
disp(result);
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Naive Bayes finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!