why accuracy is same for all the frames?
1 view (last 30 days)
Show older comments
clc
close all
clear all
a=VideoReader('G:\New Folder (2)\test1.mp4'); % Read a video
b = read(a,1); % Read 1st frame
c=rgb2gray(b); % Converting from RGB to GRAY
rows = 8;
columns = 8;
nframe=a.NumberOfFrames; % Number of Frames in video read
tic
for i=100:117
d =read(a,i-1); % Read Previous frame
e1=rgb2gray(d);
e=immultiply(e1,2);
g =read(a,i); % Read Current frame
f1=rgb2gray(g);
f = immultiply(f1,2);
res = f-e;
res_bw = im2bw(res);
% figure
% imshow(res_bw)
% title('reference image');
[HH,WW,~] = size(res_bw); % H=Rows W=Columns
szHH = [repmat(fix(HH/rows),1,rows)]; % Splitting the original size of an image into 8X8 cells in rows
szWW = [repmat(fix(WW/columns),1,columns)]; % Splitting the original size of an image into 8X8 cells in columns
CC = mat2cell(res_bw, szHH, szWW)'; % Segmenting the image e into 8X8 cell
figure
for jj=1:rows*columns
subplot(rows,columns,jj), imshow( CC{jj} )
end
img=getframe(gcf);
imwrite(img.cdata,['E:\frame\reference_image.png'])
[H,W,~] = size(e); % H=Rows W=Columns
szH = [repmat(fix(H/rows),1,rows)]; % Splitting the original size of an image into 8X8 cells in rows
szW = [repmat(fix(W/columns),1,columns)]; % Splitting the original size of an image into 8X8 cells in columns
C = mat2cell(e, szH, szW)'; % Segmenting the image e into 8X8 cells
D =mat2cell(f, szH, szW)'; % Segmenting the image f into 8X8 cells
C1 = C';
D1 = D';
% figure
% for j=1:rows*columns
% subplot(rows,columns,j), imshow( C{j} )
% end
% figure
% for j=1:rows*columns
% subplot(rows,columns,j), imshow( D{j} )
% end
% figure
for k=1:64
E1={C{k}};
E{k}=cell2mat(E1);
subplot(rows,columns,k), imshow( E{k} )
end
% figure
for k=1:64
F1={D{k}};
F{k}=cell2mat(F1);
subplot(rows,columns,k), imshow( F{k} )
end
% figure
for r=1:64
w(r)=abs(std2(double(E{r}))); % computes the standard deviation of the values in E
% figure
% plot(w);
ceil(w);
q(r)=abs(std2(double(F{r}))); % computes the standard deviation of the values in F
% figure
% plot(q);
ceil(q);
diff=w-q;
level(r) = graythresh(E{r}) ; % determine Otsu Threshold value
level1(r) = graythresh(F{r});
if diff(r)>level(r)
T=im2bw(E{r});
subplot(rows,columns,r);
imshow(T)
elseif diff(r)<level(r)
T1 = im2bw(E{r});
T1=0;
subplot(rows,columns,r);
imshow(T1)
elseif diff(r)<level1(r)
P=im2bw(F{r});
imshow(P)
elseif diff(r)>level1(r)
P1 = im2bw(F{r});
P1=0;
subplot(rows,columns,r)
imshow(P1)
end
img=getframe(gcf);
imwrite(img.cdata,['E:\frame\output.png']);
end
TargetImg=imread('E:\frame\reference_image.png');
TestImg=imread('E:\frame\output.png');
TargetMask = zeros(size(TargetImg));
TargetMask= TargetImg>0;
NotTargetMask = logical(1-TargetMask);
TestMask = zeros(size(TestImg));
TestMask= TestImg>0;
FPimg = TestMask.*NotTargetMask;
FPcounts = sum(FPimg);
FP = sum(FPimg(:));
TPimg = TestMask.*TargetMask;
TPcounts = sum(TPimg);
TP = sum(TPimg(:));
FNimg = TargetMask-TPimg;
FNcounts = sum(FNimg);
FN = sum(FNimg(:));
TNimg = 1- FPimg;
TNcounts = sum(TNimg);
TN =sum(TNimg(:));
accuracy(i)=(((TP+TN)/(TP+TN+FN+FP))*100);
Sensitivity(i)= TP/(TP+FN)*100 ;
Specificity(i)= TN/(TN+FP)*100 ;
end
xlabel1=100:1:117;
ylabel1=accuracy(100:117);
figure
plot(xlabel1,ylabel1)
xlabel('frames per second')
ylabel('Accuracy')
title('Accuracy')
how to vary accuracy what changes i should make?
0 Comments
Answers (0)
See Also
Categories
Find more on Basic Display 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!