function [Sum_of_particles, Mean_brightness, SNR, Avg_partcl_diameter_in_mikrons_temp] = Img_analysis_v5_3(i, File_name)

% Read image
File_name = imread(File_name);

% Get average image calculated by START_Particle_counter
AVG_img_2 = getappdata(0,'AVG_img_2');

% Subtract image from average image to reduce noise
Filtered_img = imsubtract(File_name,AVG_img_2);

% Convert image to Grayscale
%Gray_img = rgb2gray(Source_img);
    
%% Draw image contours
filter_index0 = 15;     % Input parameters for the image contour (least value)
filter_index1 = 15;     % dtto (max value)
[C,h] = imcontour(Filtered_img, [filter_index0 filter_index1],'ok');

% Count the sum of particles
Sum_of_particles = (sum(C(:) == filter_index0))

%% SNR calculation
Filtered_img_noise_SNR = double(Filtered_img(:));           % Preparing data (Image data to DOUBLE format)
Filtered_img_noise_std = std(Filtered_img_noise_SNR(:));    % Standard deviation of brightness values of the Filtered image

% Area calculation
v1 = getappdata(0,'v1');
v2 = getappdata(0,'v2'); 
v3 = getappdata(0,'v3'); 
v4 = getappdata(0,'v4'); 
v5 = getappdata(0,'v5'); 
v6 = getappdata(0,'v6'); 
v7 = getappdata(0,'v7'); 
v8 = getappdata(0,'v8'); 
v9 = getappdata(0,'v9');
v10 = getappdata(0,'v10');
v11 = getappdata(0,'v11');
v12 = getappdata(0,'v12');
v13 = getappdata(0,'v13');
v14 = getappdata(0,'v14');
v15 = getappdata(0,'v15');
v16 = getappdata(0,'v16');
Sum_of_particles_in_group1 = getappdata(0,'Sum_of_particles_in_group1');
Sum_of_particles_in_group2 = getappdata(0,'Sum_of_particles_in_group2');
Sum_of_particles_in_group3 = getappdata(0,'Sum_of_particles_in_group3');
Sum_of_particles_in_group4 = getappdata(0,'Sum_of_particles_in_group4');
Sum_of_particles_in_group5 = getappdata(0,'Sum_of_particles_in_group5');
Sum_of_particles_in_group6 = getappdata(0,'Sum_of_particles_in_group6');
Sum_of_particles_in_group7 = getappdata(0,'Sum_of_particles_in_group7');
Sum_of_particles_in_group8 = getappdata(0,'Sum_of_particles_in_group8');
Sum_of_particles_in_group9 = getappdata(0,'Sum_of_particles_in_group9');
Sum_of_particles_in_group10 = getappdata(0,'Sum_of_particles_in_group10');
Sum_of_particles_in_group11 = getappdata(0,'Sum_of_particles_in_group11');
Sum_of_particles_in_group12 = getappdata(0,'Sum_of_particles_in_group12');
Sum_of_particles_in_group13 = getappdata(0,'Sum_of_particles_in_group13');
Sum_of_particles_in_group14 = getappdata(0,'Sum_of_particles_in_group14');
Sum_of_particles_in_group15 = getappdata(0,'Sum_of_particles_in_group15');
Sum_of_particles_in_group16 = getappdata(0,'Sum_of_particles_in_group16');

% First moment of area
v1_1 = v1;
v2_1 = v2-v1;
v3_1 = v3-v2;
v4_1 = v4-v3;
v5_1 = v5-v4;
v6_1 = v6-v5;
v7_1 = v7-v6;
v8_1 = v8-v7;
v9_1 = v9-v8;
v10_1 = v10-v9;
v11_1 = v11-v10;
v12_1 = v12-v11;
v13_1 = v13-v12;
v14_1 = v14-v13;
v15_1 = v15-v14;
v16_1 = v16-v15;

% Area of histogram
S = (Sum_of_particles_in_group1*v1_1)+(Sum_of_particles_in_group2*v2_1)+(Sum_of_particles_in_group3*v3_1)+(Sum_of_particles_in_group4*v4_1)+(Sum_of_particles_in_group5*v5_1)+(Sum_of_particles_in_group6*v6_1)+(Sum_of_particles_in_group7*v7_1)+(Sum_of_particles_in_group8*v8_1)+(Sum_of_particles_in_group9*v9_1)+(Sum_of_particles_in_group10*v10_1)+(Sum_of_particles_in_group11*v11_1)+(Sum_of_particles_in_group12 * v12_1)+(Sum_of_particles_in_group13 * v13_1)+(Sum_of_particles_in_group14 * v14_1)+(Sum_of_particles_in_group15 * v15_1)+(Sum_of_particles_in_group16 * v16_1);

Sx1  = (Sum_of_particles_in_group1 *  v1_1)  * (v1_1/2);
Sx2  = (Sum_of_particles_in_group2 *  v2_1)  * (v1 + v2_1/2);
Sx3  = (Sum_of_particles_in_group3 *  v3_1)  * (v2 + v3_1/2);
Sx4  = (Sum_of_particles_in_group4 *  v4_1)  * (v3 + v4_1/2);
Sx5  = (Sum_of_particles_in_group5 *  v5_1)  * (v4 + v5_1/2);
Sx6  = (Sum_of_particles_in_group6 *  v6_1)  * (v5 + v6_1/2);
Sx7  = (Sum_of_particles_in_group7 *  v7_1)  * (v6 + v7_1/2);
Sx8  = (Sum_of_particles_in_group8 *  v8_1)  * (v7 + v8_1/2);
Sx9  = (Sum_of_particles_in_group9 *  v9_1)  * (v8 + v9_1/2);
Sx10 = (Sum_of_particles_in_group10 * v10_1) * (v9 + v10_1/2);
Sx11 = (Sum_of_particles_in_group11 * v11_1) * (v10 + v11_1/2);
Sx12 = (Sum_of_particles_in_group12 * v12_1) * (v11 + v12_1/2);
Sx13 = (Sum_of_particles_in_group13 * v13_1) * (v12 + v13_1/2);
Sx14 = (Sum_of_particles_in_group14 * v14_1) * (v13 + v14_1/2);
Sx15 = (Sum_of_particles_in_group15 * v15_1) * (v14 + v15_1/2);
Sx16 = (Sum_of_particles_in_group16 * v16_1) * (v15 + v16_1/2);

% Mean brightness of particles from Histogram (calculated as a centroid of the histogram)
Mean_particle_brightness_from_histogram = (Sx1+Sx2+Sx3+Sx4+Sx5+Sx6+Sx7+Sx8+Sx9+Sx10+Sx11+Sx12+Sx13+Sx14+Sx15+Sx16)/S; 

% SNR
SNR = 10*log10(Mean_particle_brightness_from_histogram/Filtered_img_noise_std); 

%% Mean brightness of a particle in image
Mean_brightness = Mean_particle_brightness_from_histogram;

%% Calculate area of each particle (particle border is defined as the area
% used for countours function (filter_index0)).
% Img to BW
level_area = filter_index0/255;                                 %to get number btw [0 1] needed for im2bw
Filtered_img_BW = im2bw(Filtered_img, level_area);              %note: Threshold can be also asumed by using Otsu`s method: level = graythresh(Gray_img_noise_2);
% Calculate area of each particle
Area = regionprops(Filtered_img_BW,'Area');
%No_of_areas = bwlabel(Gray_img_noise_2_BW);
%Sum_of_particles2 = max(No_of_areas) %Count no. of particles using Regionprops
Area_as_cell = struct2cell(Area);
Area_as_matrix = cell2mat(Area_as_cell);
Avg_partcl_size_in_pxls = mean(Area_as_matrix);
Avg_partcl_size_in_pxls_as_circle = sqrt((4*Avg_partcl_size_in_pxls)/pi);
Avg_partcl_diameter_in_mikrons_temp = Avg_partcl_size_in_pxls_as_circle*29.69;       % 29.69 mikrons = lenght and height of a pixel at the distance of a laser sheet

end