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

% Read an image 
Im = imread('picture 1.jpg');

% Define a region of interest (ROI) over which the intensity will be integrated.
x_start = 650;
x_end   = 850;
y_start = 350;
y_end   = 500;




% XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
%
%                             DO NOT MODIFY THE SCRIPT BEYOND THIS POINT
%
% XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX



%% =====================================================================================================
% Process data

% camera parameters
PixNrx = 1280;
PixNry = 720;

% select a channel (here red)
Red_1 = Im(:,:,1);

% format conversion
Red_1 = double(Red_1);

% define a region of interest ROI
Red_1_ROI = Red_1(y_start:y_end,x_start:x_end);

% integral over region of intensity
Intensity_over_ROI = sum(sum(Red_1_ROI))

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

% plot the whole field to allow to find the position of the intensity peak

figure('color','w','position',[250  250  500  400])

imagesc(Red_1,[0 255]); colormap(gray)
axis square
rectangle('position',[x_start y_start x_end-x_start y_end-y_start],'edgecolor','r','linewidth',2)
title('Image and ROI')
xlabel('Position x (pixel)')
ylabel('Position y (pixel)')


