Matlab R2016b

5 visualizzazioni (ultimi 30 giorni)
Joe Anton
Joe Anton il 27 Mag 2020
Risposto: Steven Lord il 27 Mag 2020
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 Commenti
Joe Anton
Joe Anton il 27 Mag 2020
Undefined function or variable 'trainset'. Eror in svm (line 33) SVMModel = fitcsvm(trainset,class)
Image Analyst
Image Analyst il 27 Mag 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?

Accedi per commentare.

Risposte (1)

Steven Lord
Steven Lord il 27 Mag 2020
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.

Prodotti


Release

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by