Matlab R2016b

clc;
clear;
close all;
warning off all;
image_folder = 'pengolahan\data latih';
filenames = diri(fullfile(image_folder,'*.jpg'));
total_images = numel(filenames);
area = zeros(1,total_images);
perimeter = zeros(1,total_images);
metric = zeros(1,total_images);
eccentricity = zeros(1,total_images);
for n = 1 : total_images
full_name = fullfile(image_folder, filenames(n).name);
our_images = logical(imread(full_name));
our_images = bwconfull(our_images,'objects');
stats = regionprops(our_images,'Area','Perimeter','Eccentricity');
area(n) = stats.Area;
perimeter(n) = stats.Perimeter;
metric(n) = 4*pi*area(n)/(perimeter(n)^2);
eccentricity(n) = stats.Eccentricity;
trainset = [metric;eccentricity]';
end
%prepare class label for first run of SVM
class = cell(75,1);
class(1:35,1) = {'Sub Tropis'};
class(36:75,1)= {'Tropis'};
%perform run of svm
figure
SVMModel = fitcsvm(trainset,class);
sv = SVMModel.SupportVectors;
gscatter(trainset(:,1), trainset(:,2),class)
grid on
hold on
plot(sv(:,1),sv(:,2),'ko','MarkerSize',10)
legend('Sub Tropis','Tropis','Support Vector')
hold off
xlabel ('Metric')
ylabel ('Eccentricity')
save SVMModel.mat SVMModel
[SL: formatted code as code and added line breaks for readability. Also fixed one missing ' in the line where filenames is first defined.]

2 comentarios

Joe Anton
Joe Anton el 27 de Mayo de 2020
Undefined function or variable 'trainset'. Eror in svm (line 33) SVMModel = fitcsvm(trainset,class)
Image Analyst
Image Analyst el 27 de Mayo de 2020
And why do you think that it somehow knows what trainset is if you never defined it? It can't just make stuff up for you. You need to define it. Where did you do that?

Iniciar sesión para comentar.

Respuestas (1)

Steven Lord
Steven Lord el 27 de Mayo de 2020

1 voto

My suspicion is that your images folder contains no JPG files. If it doesn't, your for loop does not execute its loop body and the variable trainset is never created.

Productos

Versión

R2016b

Preguntada:

el 27 de Mayo de 2020

Respondida:

el 27 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by