close all; clc
%% =====================================================================================================
% Parameters to be modified

% Read image
I = imread('picture 8.jpg');

% Define a vertical region of interest (ROI) over which the data will be averaged
y_start = 270; 
y_end   = 300;

% 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 = mean(I,3);

% define central line
CL = y_start + floor((y_end-y_start)/2);

% select a line of interest
CenterLine = I_BW(CL,:);

% average over several lines (vertical)
ROI_Line  = I_BW(y_start:y_end,:);

% caculate the mean of the RIO obver several rows
N_Avg_Line = mean(ROI_Line);

%% =====================================================================================================
% Plot data

figure('color','w','Position', [90 200 1350 350])

% plot the image
subplot(1,3,1)
imagesc(I)
hold on
if show_ROI
    rectangle('Position',[1 y_start PixNrx-1 y_end-y_start],'EdgeColor','w','LineWidth',1.2)
end
xlabel('Position x (pixel)')
ylabel('Position y (pixel)')
title('Signal')

% plot a single line
subplot(1,3,2) 
plot(CenterLine,'b','LineWidth',2)
xlabel('Position x (pixel)')
ylabel('Signal (counts)')
title(['Raw B&W signal at y = ' num2str(CL) ' (middle of ROI)'])
xlim([1 PixNrx])

% plot the averaged line
subplot(1,3,3) 
plot(N_Avg_Line,'b','LineWidth',2)
title('Averaged B&W signal')
xlabel('Position x (pixel)')
ylabel('Signal (counts)')
xlim([1 PixNrx])

