diff --git a/RGB_traces.m b/RGB_traces.m new file mode 100644 index 0000000..6f7ff06 --- /dev/null +++ b/RGB_traces.m @@ -0,0 +1,27 @@ +%%%%%%%%%%%%%%%%%%%%% +% function RGB_avg = RGB_traces (input1) +% ex. RGB_avgs = 2DRotationMatrix('frame0.jpg') +% +% Task: Extracting the average RGB values of a frame +% +% Inputs: +% - input1: frame adress on pc +% +% Output: +% -RGB_avg: a 1x3 matrix with the RGB average values, format -> [R, G, B] +% +% author: Loic Delattre (loic.delattre@ecam.fr) +% date: 06/02/2023 +%%%%%%%%%%%%%%%%%%%%% + +function RGB_avg = RGB_traces (image) + I = imread (image); + RGB_avg = []; + i = 3; + j = 1; + while i >= 1 + RGB_avg(j) = matrix_avg (I(:,:,i)); + j = j + 1; + i = i - 1; + endwhile +endfunction diff --git a/frames_RGBs.m b/frames_RGBs.m new file mode 100644 index 0000000..101d242 --- /dev/null +++ b/frames_RGBs.m @@ -0,0 +1,36 @@ +%%%%%%%%%%%%%%%%%%%%% +% function RGB_avg = RGB_traces (input1) +% ex. RGB_avgs = 2DRotationMatrix('frame0.jpg') +% +% Task: Extracting the average RGB values of a frame +% +% Inputs: +% - input1: frame adress on pc +% +% Output: +% -RGB_avg: a 1x3 matrix with the RGB average values, format -> [R, G, B] +% +% author: Loic Delattre (loic.delattre@ecam.fr) +% date: 06/02/2023 +%%%%%%%%%%%%%%%%%%%%% + +function RGB_data = frames_RBGs () + %frames_num = 918; + j = 0; + RGB_data = [0, 0, 0]; + while j <= 10000 + try + image = strcat('frames/frame', int2str(j), '.jpg'); + j = j + 1; + i = 3; + while i >= 1 + RGB_data(i, j) = RGB_traces (image)(i); + i = i - 1; + endwhile + catch + disp('scanned all frames') + j = 10001 + end_try_catch + endwhile + +endfunction diff --git a/get_frames.py b/get_frames.py index 152f622..252c5d9 100644 --- a/get_frames.py +++ b/get_frames.py @@ -64,5 +64,5 @@ def get_frames(vid): cap.release() cv2.destroyAllWindows() - return -get_frames(video) \ No newline at end of file + return i +print('number of frames extracted ' + get_frames(video)) \ No newline at end of file diff --git a/matrix_avg.m b/matrix_avg.m new file mode 100644 index 0000000..a4f8b32 --- /dev/null +++ b/matrix_avg.m @@ -0,0 +1,22 @@ +%%%%%%%%%%%%%%%%%%%%% +% function RGB_avg = RGB_traces (input1) +% ex. RGB_avgs = 2DRotationMatrix('frame0.jpg') +% +% Task: Extracting the average RGB values of a frame +% +% Inputs: +% - input1: frame adress on pc +% +% Output: +% -RGB_avg: a 1x3 matrix with the RGB average values +% +% author: Loic Delattre (loic.delattre@ecam.fr) +% date: 06/02/2023 +%%%%%%%%%%%%%%%%%%%%% + +function Mavg = matrix_avg (M) + col = size(M,2); + row = size(M,1); + num_items = col*row; + Mavg = sum(sum(M))/num_items; +endfunction diff --git a/test_file.m b/test_file.m new file mode 100644 index 0000000..b120e6d --- /dev/null +++ b/test_file.m @@ -0,0 +1,17 @@ +clear all +close all +clc + +threshold = 1e-6; + +RGB_data = frames_RGBs (); + +%TEST 1 +%Average of all the items inside of a matrix +A = [1, 2; 3, 4]; +avg = 2.5; +if matrix_avg (A) - avg < threshold + disp('Test 1 passed gg') +else + disp('Test 1 failed, f') +endif \ No newline at end of file