From 65f25bb19d2d144dd26f1c329de182a79179e8d4 Mon Sep 17 00:00:00 2001 From: Julian Date: Wed, 6 Apr 2022 16:45:38 +0200 Subject: [PATCH] ROI analysis --- Camerafeed/picToROI.m | 13 ++++++------ Camerafeed/plotAverage.m | 43 +++++++++++++++++++++++++++++++++++++++ Camerafeed/plotFFT.m | 38 ++++++++++++++++++++++++++++++++++ Camerafeed/testfunction.m | 11 +++++++++- 4 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 Camerafeed/plotAverage.m create mode 100644 Camerafeed/plotFFT.m diff --git a/Camerafeed/picToROI.m b/Camerafeed/picToROI.m index a1bb26d..08f6c1c 100644 --- a/Camerafeed/picToROI.m +++ b/Camerafeed/picToROI.m @@ -11,12 +11,11 @@ % 06/04/2021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -function [frame] = picToROI(imgWidth,imgHeight,nbIm,d) +function [gROI] = picToROI(imgWidth,imgHeight,nbIm,d) + display("piToRoi Start") files = dir('*.jpg'); ROI = zeros (3*d/2,3*d+1,nbIm,3); - display("ok1"); for n=1:1:nbIm - display("ok2"); files(n).name frame = imread (files(n).name); @@ -24,12 +23,12 @@ function [frame] = picToROI(imgWidth,imgHeight,nbIm,d) for i=1:1:3*d/2 %imgHeight*0.5-d*5/2:1:3*d/2 for j=1:1:3*d %imgWidth*0.5-3*d/2:1:3*d - ROI(i,j,n,1) = Image(i+imgHeight*0.5-d*5/2,j+imgWidth*0.5-3*d/2,1); - ROI(i,j,n,2) = Image(i+imgHeight*0.5-d*5/2,j+imgWidth*0.5-3*d/2,1); - ROI(i,j,n,3) = Image(i+imgHeight*0.5-d*5/2,j+imgWidth*0.5-3*d/2,1); + rROI(i,j,n) = Image(i+imgHeight*0.5-d*5/2,j+imgWidth*0.5-3*d/2,1)*255; + gROI(i,j,n) = Image(i+imgHeight*0.5-d*5/2,j+imgWidth*0.5-3*d/2,2)*255; + bROI(i,j,n) = Image(i+imgHeight*0.5-d*5/2,j+imgWidth*0.5-3*d/2,3)*255; endfor endfor endfor - + display("piToRoi End") endfunction diff --git a/Camerafeed/plotAverage.m b/Camerafeed/plotAverage.m new file mode 100644 index 0000000..ccfff37 --- /dev/null +++ b/Camerafeed/plotAverage.m @@ -0,0 +1,43 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%function []= plotAverage(ROI,nbIm, fps) +% +% Task: plotting the average color of the ROI over time +% +% Inputs: +% - ROI: 3D matrix, Region of interest, made out of 'nbIm' different images +% - nbIm: integer, number of images stored from the video +% - fps: frames per seconds of the video +% +% Outputs: +% - plot of the average color of the ROI as a function of time +% +% Antoine Rodary - Julian Leclerc - Gwenn Durpoix-Espinasson - Luc Pichot +% 06/04/2021 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +function [averageArray]= plotAverage(ROI,nbIm, fps) + display("PlotAv Start") + % passing through each image of the video + averageArray = zeros(1,nbIm); + [n,m,Nimg]=size(ROI); + for k = 1:nbIm + % calculating the average value of the ROI + sum = 0; + for i = 1:n + for j = 1:m + sum = sum + ROI(i,j,k); + end + end + average = sum/(i*j); + %storing + averageArray(k)= average; + end + xAxis = [0:(1/fps):(nbIm/fps)-(1/fps)]; + figure(1); + plot(xAxis, averageArray); + title('Average color of the ROI over time') + xlabel('t (s)') + ylabel('Average color of the ROI') + display("PlotAv End") +endfunction \ No newline at end of file diff --git a/Camerafeed/plotFFT.m b/Camerafeed/plotFFT.m new file mode 100644 index 0000000..0a50031 --- /dev/null +++ b/Camerafeed/plotFFT.m @@ -0,0 +1,38 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%function []= plotFFT(averageArray, nbIm, fps) +% +% Task: plotting the fast fourier transform of the average color of the ROI +% +% Inputs: +% - averageArray : function of the average color of the ROI over time +% - nbIm : integer, number of images stored from the video +% - fps : frames per seconds of the video +% +% Outputs: +% - plot of the fast fourier transform of the average color of the ROI +% +% Antoine Rodary - Julian Leclerc - Gwenn Durpoix-Espinasson - Luc Pichot +% 06/04/2021 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +function []= plotFFT(averageArray, nbIm,fps) + + display("Plot FFT Start") + Fs = fps; % Sampling frequency + T = 1/Fs; % Sampling period + L = nbIm; % Length of signal + t = (0:L-1)*T; % Time vector + Y = fft(averageArray); + + P2 = abs(Y/L); + P1 = P2(1:L/2+1); + P1(2:end-1) = 2*P1(2:end-1); + f = Fs*(0:(L/2))/L; + figure(2); + plot(f,P1) + title('Fast Fourier Transform of the signal of the average color of the ROI') + xlabel('f (Hz)') + ylabel('|P1(f)|') + display("Plot FFT End") + hold on; +endfunction diff --git a/Camerafeed/testfunction.m b/Camerafeed/testfunction.m index 71bb9eb..4f4cf47 100644 --- a/Camerafeed/testfunction.m +++ b/Camerafeed/testfunction.m @@ -1 +1,10 @@ -M = picToROI(750,480,5,26); \ No newline at end of file +fps = 30; +nbIm = 300; + +%rROI = picToROI(750,480,nbIm,26,1); +gROI = picToROI(750,480,nbIm,26,1); +%bROI = picToROI(750,480,nbIm,26,1); + +hold +averageArray = plotAverage(gROI,nbIm, fps); +plotFFT(averageArray, nbIm,fps); \ No newline at end of file