close all; clc
%% =====================================================================================================
% Parameters to be modified

% Read image 1
I_1 = imread('Picture 1.jpg');
% Read image 2
I_2 = imread('Picture 2.jpg');
% Read image 3
I_3 = imread('Picture 3.jpg');
% Read image 4
I_4 = imread('Picture 4.jpg');
% Read image 5
I_5 = imread('Picture 5.jpg');

% Define a vertical region of interest (ROI) over which the data will be averaged
y_start = 375; 
y_end   = 390;

% Show ROI (1 = show ROI, 0 = hide ROI)
show_ROI = 1;





% XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
%
%                             DO NOT MODIFY THE SCRIPT BEYOND THIS POINT
%
% XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX







%% =====================================================================================================
% Process data

%parameters
PixNrx      =       1280;
PixNry      =       720;

% convert to B&W
I_BW_500 = mean(I_1,3);
I_BW_550 = mean(I_2,3);
I_BW_600 = mean(I_3,3);
I_BW_650 = mean(I_4,3);
I_BW_700 = mean(I_5,3);

% average over several lines (vertical)
ROI_Line_500  = I_BW_500(y_start:y_end,:);
N_Avg_Line_500 = mean(ROI_Line_500);

ROI_Line_550  = I_BW_550(y_start:y_end,:);
N_Avg_Line_550 = mean(ROI_Line_550);

ROI_Line_600  = I_BW_600(y_start:y_end,:);
N_Avg_Line_600 = mean(ROI_Line_600);

ROI_Line_650  = I_BW_650(y_start:y_end,:);
N_Avg_Line_650 = mean(ROI_Line_650);

ROI_Line_700  = I_BW_700(y_start:y_end,:);
N_Avg_Line_700 = mean(ROI_Line_700);

%% =====================================================================================================
% Plot data

figure('color','w','Position', [250 250 1228 527])

% plot image 1
subplot(1,2,1) 
imagesc(I_1)
hold on
if show_ROI
    rectangle('Position',[1 y_start PixNrx-1 y_end-y_start],'EdgeColor','w','LineWidth',1.2)
end
title('Image 1')
xlabel('Position x (pixel)')
ylabel('Position y (pixel)')

% plot the averaged lines all at once 
subplot(1,2,2)
hold on
plot(N_Avg_Line_500,'b','LineWidth',2);
plot(N_Avg_Line_550,'c','LineWidth',2);
plot(N_Avg_Line_600,'g','LineWidth',2);
plot(N_Avg_Line_650,'y','LineWidth',2);
plot(N_Avg_Line_700,'r','LineWidth',2);
xlabel('Position x (pixel)')
ylabel('Signal (counts)')
title('Averaged signals')
legend('Im1','Im2','Im3','Im4','Im5')
xlim([1 PixNrx])










