-
Notifications
You must be signed in to change notification settings - Fork 3
/
DMD_foregroundaperture.m
78 lines (61 loc) · 1.95 KB
/
DMD_foregroundaperture.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
%F:\dmd_pendrive\DMD_Output\Foregroundaperture
clc;clear all;close all;
Frames = zeros(540, 960, 40);
c = 0;
%for t=470:519
for t=1:100
c = c + 1;
% name=sprintf('lightswicth/%d.bmp', t);
% name = strcat('foregroundaperture/b00',num2str(t),'.bmp');
name = strcat('vid/Image',num2str(t),'.jpg');
display(name)
img=imread(name);
imggray=rgb2gray(img);
Frames(:, :, c)=imggray;
end
sizeOfFrames = size(Frames);
assert(length(sizeOfFrames) == 3, 'Input must be a three dimensional matrix')
heightFrame = sizeOfFrames(1);
widthFrame = sizeOfFrames(2);
numberFrames = sizeOfFrames(3);
FramesVectorized = zeros(heightFrame * widthFrame, numberFrames);
for i=1:numberFrames
temp = Frames(:,:,i);
FramesVectorized(:, i)= temp(:);
end
%display(['Total number of frames are ', num2str(numberFrames)]);
%numberFrames = input('How many frames to use? ');
X1 = FramesVectorized(:,1:numberFrames-1);
X2 = FramesVectorized(:,2:numberFrames);
[U, E, V] = svd(X1, 'econ');
Stild = U' * X2 * V * pinv(E);
[EigVec, EigVal] = eig(Stild);
omega = log(EigVal);
Omega = exp(omega);
Psi = U * EigVec;
b = pinv(Psi)*X1(:, 1);
%XDMDt = Psi * Omega * b;
omegaD = abs(diag(omega));
LowRank = exp(min(omegaD));
XDMD = zeros(heightFrame * widthFrame, numberFrames - 1);
for t = 1:numberFrames - 1
XDMD(:, t) = Psi * Omega.^t * b;
end
XLow = zeros(heightFrame * widthFrame, numberFrames - 1);
for t = 1 :numberFrames - 1
XLow(:, t) = Psi * LowRank.^t * b;
end
XLow = abs(XLow);
XSparse = abs(XDMD - XLow);
Foreground = uint8(reshape(XSparse, [heightFrame, widthFrame, numberFrames-1]));
Background = uint8(reshape(XLow, [heightFrame, widthFrame, numberFrames-1]));
figure;
%for i = 1:49
for i = 1:90
%imshow(Background(:,:,i))
%imshow(Foreground(:,:,i))
subplot(1,2,1), subimage(Background(:,:,i)); title('Low-Rank');
subplot(1,2,2), subimage(Foreground(:,:,i)); title('Sparse');
pause(1)
i
end