version 1.1.1
This commit is contained in:
parent
8e6eb7f664
commit
7cc36a8154
|
|
@ -1,20 +0,0 @@
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
||||||
% Image extraction code
|
|
||||||
%
|
|
||||||
% Author:LY Pechvattana, MINH Meng Hour
|
|
||||||
% Date: 19/02/2023
|
|
||||||
%
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
||||||
|
|
||||||
function v = imgex[]
|
|
||||||
video
|
|
||||||
v = VideoReader('code.avi');
|
|
||||||
|
|
||||||
n = 1;
|
|
||||||
while hasFrame(v)
|
|
||||||
img = readFrame(v);
|
|
||||||
imwrite(img,strcat('image',num2str(n),'.png'));
|
|
||||||
n = n+1
|
|
||||||
end
|
|
||||||
n=n-1;
|
|
||||||
|
|
||||||
|
|
@ -1,97 +0,0 @@
|
||||||
%set variable
|
|
||||||
fps = 15;
|
|
||||||
windowDuration = 30;
|
|
||||||
windowShift = 1;
|
|
||||||
roi = [310 126 114 54];
|
|
||||||
imgDirectory = 'images';
|
|
||||||
|
|
||||||
%global
|
|
||||||
redChannel = [];
|
|
||||||
greenChannel = [];
|
|
||||||
blueChannel = [];
|
|
||||||
|
|
||||||
%list the images
|
|
||||||
listImg = dir([imgDirectory '/*.png']);
|
|
||||||
|
|
||||||
for l_img=1:windowDuration*fps
|
|
||||||
% load the current image
|
|
||||||
image_orginal = imread([imgDirectory '/' listImg(l_img).name]);
|
|
||||||
|
|
||||||
image_face = imcrop(image_orginal,roi);
|
|
||||||
|
|
||||||
%spatial average for r, g, b channels
|
|
||||||
[r g b]=imsplit(image_face);
|
|
||||||
|
|
||||||
r_mean = mean2(r);
|
|
||||||
g_mean = mean2(g);
|
|
||||||
b_mean = mean2(b);
|
|
||||||
|
|
||||||
% store the current "average" pixel in global arrays
|
|
||||||
redChannel = [redChannel r_mean];
|
|
||||||
greenChannel = [greenChannel g_mean];
|
|
||||||
blueChannel = [blueChannel b_mean];
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
% estimate temporal average and standard deviation
|
|
||||||
greenChannel_avg = mean(greenChannel);
|
|
||||||
greenChannel_std = std(greenChannel);
|
|
||||||
|
|
||||||
%normalization
|
|
||||||
for i = 1:450
|
|
||||||
greenChannel_normal(i) = (greenChannel(i)-greenChannel_avg);
|
|
||||||
end
|
|
||||||
|
|
||||||
%Fast Fourier transform (fft) of Green Channel
|
|
||||||
greenChannel_fft = fft(greenChannel_normal);
|
|
||||||
|
|
||||||
|
|
||||||
%power spectrum P1
|
|
||||||
L = length(greenChannel_normal);
|
|
||||||
P2 = abs(greenChannel_fft/L);
|
|
||||||
P1 = P2(1:L/2+1);
|
|
||||||
P1(2:end-1)=2*P1(2:end-1);
|
|
||||||
f = 15*(0:(L/2))/L;
|
|
||||||
|
|
||||||
P1 = fftshift(P1);
|
|
||||||
|
|
||||||
plot(f,P1);
|
|
||||||
title("Power Spectrum")
|
|
||||||
xlabel("f (Hz)")
|
|
||||||
ylabel("Power Spectrum (f)")
|
|
||||||
|
|
||||||
%peak - compute the freq vector
|
|
||||||
[m n]=size(P1);
|
|
||||||
x = 1:n;
|
|
||||||
y= 1:m;
|
|
||||||
[X Y]=meshgrid(x, y);
|
|
||||||
X = X - floor(n/2)-1;
|
|
||||||
Y = Y - floor(m/2)-1;
|
|
||||||
f = sqrt(X.^2 + Y.^2);
|
|
||||||
|
|
||||||
%peak - find the peak in range
|
|
||||||
indices = (f>=0.75)&(f<=4);
|
|
||||||
[peaks locations] = findpeaks(P1(indices), 'SortStr','descend');
|
|
||||||
location = locations(1);
|
|
||||||
peak_frequency = f(indices);
|
|
||||||
peak_frequency = peak_frequency(location);
|
|
||||||
heartrate = peak_frequency.*60;
|
|
||||||
|
|
||||||
disp(['Heart rate: ', num2str(heartrate), ' bpm']);
|
|
||||||
|
|
||||||
%plotting RGB
|
|
||||||
figure(2)
|
|
||||||
|
|
||||||
subplot(2,2,1);
|
|
||||||
plot(redChannel);
|
|
||||||
title('Red Channel', "-r");
|
|
||||||
|
|
||||||
subplot(2,2,2);
|
|
||||||
plot(greenChannel);
|
|
||||||
title('Green Channel');
|
|
||||||
|
|
||||||
subplot(2,2,3);
|
|
||||||
plot(blueChannel);
|
|
||||||
title('Blue Channel');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
fps = 15;
|
fps = 15;
|
||||||
windowDuration = 30;
|
windowDuration = 30;
|
||||||
windowShift = 1;
|
windowShift = 1;
|
||||||
roi = [310 126 114 54];
|
roi = [304 126 120 47];
|
||||||
imgDirectory = 'images';
|
imgDirectory = 'images';
|
||||||
|
|
||||||
%global
|
%global
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 209 KiB |
Loading…
Reference in New Issue