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 DARK NOISE
I_D = imread('Picture 3.jpg');






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




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

% select a channel (here red)
Red_1 = I_1(:,:,1);
Red_2 = I_2(:,:,1);
Dark_Noise = I_D(:,:,1);

% format conversion
Red_1 = double(Red_1);
Red_2 = double(Red_2);
Dark_Noise = double(Dark_Noise);

% integral over intensity
Intensity_1_no_correction = sum(sum(Red_1))
Intensity_2_no_correction = sum(sum(Red_2))

% subtraction of dark noise - background correction
Red_1 = abs(Red_1 - Dark_Noise);
Red_2 = abs(Red_2 - Dark_Noise);

% integral over intensity
Intensity_1_with_correction = sum(sum(Red_1))
Intensity_2_with_correction = sum(sum(Red_2))

% ratio of injected power
Ratio_injected_power = Intensity_1_with_correction/Intensity_2_with_correction

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

figure('color','w','Position', [250 250 1222 475]')

subplot(1,2,1)
imagesc(Red_1,[0 255])
title('Image 1 corrected')
xlabel('Position x (pixel)')
ylabel('Position y (pixel)')
colormap gray

subplot(1,2,2)
imagesc(Red_2,[0 255])
title('Image 2 corrected')
xlabel('Position x (pixel)')
ylabel('Position y (pixel)')
colormap gray





