How Can I compute True/ Table, Recall Precision, F1 ?

3 views (last 30 days)
Hello,
I want to create a program that read 5 different video files, extract 2 frames form each video, perform threshold, and Histogram Intersection.
Now I want to create a Table that contains True/ False vales, Recall, Precision and F1.
How can I calculate True Positive, False Positive & False Negative for each Intersection?
How can I store the result on the table?
Compute Precision for each intersection
Presision = True Positive/True Positive+False Positive
Compute Recall for each intersection
Recall= True Positive//True Positive/+False Negative
Compute F1 for each intersection
F1= 2*[(P*R)/P+R]
Below is the code that I wrote
Can someone please help me??
thanks in advance!
function [output]= calculate_TruthTable(filename, fimename01,fimename02, fimename03, fimename04)
% the First Video
filename='C:\Users\User\Videos\videos\TestSet\01_DevilsAdvocate_01.mp4';
% From the first video we extract frame 40
% Convert the frame to greyscale
% Perform threshold
% Compute histogrma
% Normalize histogram
vObj= VideoReader(filename);
vFrame01 = read(vObj, 40);
vFrame01grey = rgb2gray(vFrame01);
binaryImage = vFrame01grey < 40;
hist01=imhist(binaryImage);
hist01=hist01 ./max(abs(hist01));
% From the same video extract frame 135
% Convert the frame to grayscale
% Perform threshold
% Compute Histogram
% Normalize histogram
vFrame02 = read(vObj, 135);
vFrame02grey = rgb2gray(vFrame02);
binaryImage02 = vFrame02grey < 40;
hist02=imhist(binaryImage02);
hist02=hist02 ./max(abs(hist02));
% Find Histogram Intersection for the forst video
histIntersect= sum(max(hist01-hist02));
Intersect = find(histIntersect);
%--------------------------------------------------------------------------------------------------------------------------%
% the Second Video
fimename01= 'C:\Users\User\Videos\videos\TestSet\01_PulpFiction_01.mp4';
% From the second videoextract frame 40
% Convert the frame to greyscale
% Perform threshold
% Compute histogrma
% Normalize histogram
vObj= VideoReader(filename);
vFrame03 = read(vObj, 40);
vFrame03grey = rgb2gray(vFrame03);
binaryImage03 = vFrame03grey < 40;
hist03=imhist(binaryImage03);
hist03=hist03 ./max(abs(hist03));
% From the same video extract frame 135
% Convert the frame to grayscale
% Perform threshold
% Compute Histogram
% Normalize histogram
vFrame04 = read(vObj, 135);
vFrame04grey = rgb2gray(vFrame04);
binaryImage04 = vFrame04grey < 40;
hist04=imhist(binaryImage04);
hist04=hist04 ./max(abs(hist04));
% Compute histogram intersection
mysec_histIntersect= sum(max(hist03-hist04));
myInter02 = sort(mysec_histIntersect);
%---------------------------------------------------------------------------------------------------------------------------%
% the Third Video
fimename02= 'C:\Users\User\Videos\videos\TestSet\02_HowSheMove_01.mp4';
% From the third video extract frame 40
% Convert the frame to greyscale
% Perform threshold
% Compute histogrma
% Normalize histogram
vObj= VideoReader(filename);
vFrame05 = read(vObj, 40);
vFrame05grey = rgb2gray(vFrame05);
binaryImage05 = vFrame05grey < 40;
hist05=imhist(binaryImage05);
hist05=hist05 ./max(abs(hist05));
% From the same video extract frame 135
% Convert the frame to grayscale
% Perform threshold
% Compute Histogram
% Normalize histogram
vFrame06 = read(vObj, 60);
vFrame06grey = rgb2gray(vFrame06);
binaryImage06 = vFrame06grey < 40;
hist06=imhist(binaryImage06);
hist06=hist06 ./max(abs(hist06));
% Compute histogram intersection
mythird_histIntersect= sum(max(hist05-hist06));
%------------------------------------------------------------------------------------------------------------------------%
% The forth video
filename03='C:\Users\User\Videos\videos\TestSet\02_LastDance_01.mp4';
% From the forth video extract frame 40
% Convert the frame to greyscale
% Perform threshold
% Compute histogrma
% Normalize histogram
vObj= VideoReader(filename);
vFrame07 = read(vObj, 40);
vFrame07grey = rgb2gray(vFrame07);
binaryImage07 = vFrame07grey < 40;
hist07=imhist(binaryImage07);
hist07=hist07 ./max(abs(hist07));
% From the same video extract frame 135
% Convert the frame to grayscale
% Perform threshold
% Compute Histogram
% Normalize histogram
vFrame08 = read(vObj, 135);
vFrame08grey = rgb2gray(vFrame08);
binaryImage08 = vFrame08grey < 40;
hist08=imhist(binaryImage08);
hist08=hist08 ./max(abs(hist08));
% Compute histogram intersection
myfourth_histIntersect= sum(max(hist07-hist08));
%---------------------------------------------------------------------------------------------------------------------------%
% The fifth video
filename04='C:\Users\User\Videos\videos\TestSet\03_ArcticTale_01.mp4';
% From the fifth video extract frame 40
% Convert the frame to greyscale
% Perform threshold
% Compute histogrma
% Normalize histogram
vObj= VideoReader(filename);
vFrame09 = read(vObj, 40);
vFrame09grey = rgb2gray(vFrame09);
binaryImage09 = vFrame09grey < 40;
hist09=imhist(binaryImage09);
hist09=hist09 ./max(abs(hist09));
% From the same video extract frame 135
% Convert the frame to grayscale
% Perform threshold
% Compute Histogram
% Normalize histogram
vFrame10 = read(vObj, 135);
vFrame10grey = rgb2gray(vFrame10);
binaryImage10 = vFrame10grey < 40;
hist10=imhist(binaryImage10);
hist10=hist10 ./max(abs(hist10));
% Compute histogram intersection
myfifth_histIntersect= sum(min(hist09-hist10));
%---------------------------------------------------------------------------------------------------------------------------%
% Compute Recall for each intersection
% How can I calculate TP, FP & FN for each Intersection?????
% How can I store the result on the table(T)??????
% Compute Precision for each intersection
% P = TP/TP+FP
% Compute Recall for each intersection
% R= TP/TP+FN
% Compute F1 for each intersection
% F1= 2*[(P*R)/P+R]
MovieName = {'DevilsAdvocate';'PulpFiction';'HowSheMov';'LastDance';'ArcticTale'};
MovieGenre= {'Thriller';'Thriller';'Dance';'Dance';'Documentary'};
True= {''; '';'';'';'' };
False= {''; '';'';'';'' };
Recall= {''; '';'';'';'' };
Precision={'';'';'';'';''};
F1={'';'';'';'';''};
TruthTable = table(MovieName,MovieGenre,True,False,Recall,Precision,F1);
output= sortrows(TruthTable);
end

Answers (0)

Categories

Find more on Creating and Concatenating Matrices 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!