Borrar filtros
Borrar filtros

Error in matlab code

1 visualización (últimos 30 días)
Maryam Almannaee
Maryam Almannaee el 28 de Nov. de 2021
Editada: Image Analyst el 28 de Nov. de 2021
I have the following MATLAB code, but there is an issue. It's not running. Can someone help me with that?
clc;
clear all;
close all;
DatasetPath='C:\Users\4u\OneDrive\Desktop\Jaffedbase'
imds=imageDatastore(DatasetPath,'IncludeSubfolders',true,'LabelSource','foldernames')
tic;
train_data = dir('C:\Users\4u\OneDrive\Desktop\Jaffedbase*.tiff');
trainl=length(train_data);
trainf=[];
v1=[];
%Traing images loop
for trainloop = 1:trainl
file_train=strcat('C:\Users\4u\OneDrive\Desktop\Jaffedbase',train_data(trainloop).name);
im_train= (imread(file_train));
facecet = vision.CascadeObjectDetector(); % face detection in a given image
bbox=step(facedet,im_train);
face=imcrop(im_train,bbox);
Mouthdet= vision.CascadeObjectDetector('Mouth'); % mouth detection in a given face image
BB==step(Mouthdet,face);
for i= 1:size(BB,1)
a=BB(i,:);
z=a(2);
if z > 97
b=face(a(2):a(2)+a(4),a(1):a(1)+a(3));
figure(1);
subplot (5,4,trainloop);
imshow(file_train);
figure(2);
subplot (5,4,trainloop);
imshow(b);
[featureVector1,hogVisualization1] = extractHOGFeatures(b); %Extracting featues using HOG
figure(3);
subplot (5,4,trainloop);
plot(hogVisualization1);
Train_coeff1=featureVector1';
v1=[v1,Train_coeff1(1:120,1:1)];
trainfv1';
end
end
end
Happy = [trainf(1,:);trainf(3,:);trainf(5,:);trainf(6,:);trainf(15,:);trainf(16,:)];
Surprise = [trainf(2,:);trainf(4,:);trainf(7,:);trainf(8,:);trainf(17,:);trainf(18,:)];
Sad = [trainf(9,:);trainf(10,:);trainf(11,:);trainf(12,:);trainf(19,:)];
Anger = [trainf(13,:);trainf(14,:);trainf(20,:)];
aT1=mean(Happy);
aT2=mean(Surprise);
aT3=mean(Sad);
aT4=mean(Anger);
train_group=[1;2;1;2;1;1;2;2;3;3;3;3;4;4;1;1;2;2;3;4];
Model=fitcknn(trainf,train_group','Distance','euclidean'); % Training the KNN Classifier
test_data = dir('C:\Users\4u\OneDrive\Desktop\Jaffedbase\test1\*.tiff');
testl=length(test_data);
testf=[];
test_group=[1;2;3;2;3;1;4;4;1;2;3;2;4;4;4;1;3;3;2;1];
k=1;
for testloop = 1:testl
file_test = strcat('C:\Users\4u\OneDrive\Desktop\Jaffedbase\test1\',test_data(testloop).name);
im_test= imread(file_test);
facedet1= vision.CascadeObjectDetector(); % face detection in a given image
bbox=step(facedet1,im_test);
face1=imcrop(im_test,bbox1);
Mouthdet1= vision.CascadeObjectDetector('Mouth'); % mouth detection in a given face image
BB1=step(Mouthdet1,face1);
y1=size(BB1,1);
for j = 1:y1
a1=BB1(j,:);
z1=a1(2);
if z1 > 100
b1=face1(a1(2):a1(2)+a1(4),a1(1):a1(1)+a1(3));
figure(4);
subplot(5,4,testloop);
imshow(file_test);
figure(5);
subplot (5,4,testloop);
imshow(b1);
[ffeatureVector2,hogVisualization2] = extractHOGFeatures(b1); %Extracting featues using HOG
figure(6);
subplot(5,4,testloop);
plot(hogVisualization2);
Train_coeff2=featureVector2';
tc=Train_coeff2(1:120,1:1);
tc=tc';
[llabel,score,cost] = predict(Model,tc);
TestPredict(k)=round(label);
if test_group(testloop) == 1
ref_tc=aT1;
elseif test_group(testloop) == 2
ref_tc=aT2;
elseif test_group(testloop) == 3
ref_tc=aT3;
elseif test_group(testloop) == 4
ref_tc=aT4;
end
PSNR_cal(k)=psnr(tc,ref_tc);
mse_cal(k)=immse(tc,ref_tc);
entropy_cal(k)=entropy(b1);
k=k+1;
end
end
end
% Accuracy, mean time of executions, PSNR, MSE and Entropy Calculations
cMatf = confusionmat(test_group,TestPredict) %compare test data with new features
acc = 100*(sum(diag(cMatf))/length(TestPredict));
fprintf('Accuracy: ');
fprintf('%d\n', acc);
execution_time=toc
X=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20];
figure(7);
plot(X,PSNR_cal,'--bs');
xlabel ('Image Numbers');
ylabel ('Signal to Noise Ratio');
title('PSNR (Peak Signal to Noise Ratio)');
figure(8);
plot(X,mse_cal,'--ro');
xlabel ('Image Numbers');
ylabel ('Mean square error');
title('MSE (Mean Square Error)');
figure(9);
plot(X,entropy_cal,'--ms');
xlabel ('Image Numbers');
ylabel ('Entropy');
title('Entropy');
  1 comentario
Jan
Jan el 28 de Nov. de 2021
Editada: Image Analyst el 28 de Nov. de 2021
We cannot run your code due to th missing inputs. Then information "there is an issue" is too vague to bve answered. Please mention, what issue you have. It is much easier to solve a problem than to guess, what the problem is.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by