 function [Sum_of_particles_hist_15, Sum_of_particles_hist_31, Sum_of_particles_hist_47, Sum_of_particles_hist_63, Sum_of_particles_hist_79, Sum_of_particles_hist_95, Sum_of_particles_hist_111, Sum_of_particles_hist_127,Sum_of_particles_hist_143, Sum_of_particles_hist_159, Sum_of_particles_hist_175, Sum_of_particles_hist_191, Sum_of_particles_hist_207, Sum_of_particles_hist_223, Sum_of_particles_hist_239, Sum_of_particles_hist_250] = Img_histogram_v5_3(v, 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 background noise
Filtered_img = imsubtract(File_name,AVG_img_2);

% Draw image contours for following tresholds:
% 15,31,47,63,79,95,111,127,143,159,175,195,215,235,250
v1 = 15;
        filter_index0 = v1;     % Input parameters for the image contour (least value)
        filter_index1 = v1;     % dtto (max value)
        [C] = imcontour(Filtered_img, [filter_index0 filter_index1],'ok');
        % Count the sum of particles
        Sum_of_particles_hist_15 = (sum(C(:) == filter_index0));
        
v2 = 31;
        filter_index0 = v2;     % Input parameters for the image contour (least value)
        filter_index1 = v2;     % dtto (max value)
        [C] = imcontour(Filtered_img, [filter_index0 filter_index1],'ok');
        % Count the sum of particles
        Sum_of_particles_hist_31 = (sum(C(:) == filter_index0));

v3 = 47;
        filter_index0 = v3;     % Input parameters for the image contour (least value)
        filter_index1 = v3;     % dtto (max value)
        [C] = imcontour(Filtered_img, [filter_index0 filter_index1],'ok');
        % Count the sum of particles
        Sum_of_particles_hist_47 = (sum(C(:) == filter_index0));

v4 = 63;
        filter_index0 = v4;     % Input parameters for the image contour (least value)
        filter_index1 = v4;     % dtto (max value)
        [C] = imcontour(Filtered_img, [filter_index0 filter_index1],'ok');
        % Count the sum of particles
        Sum_of_particles_hist_63 = (sum(C(:) == filter_index0));

v5 = 79;
        filter_index0 = v5;     % Input parameters for the image contour (least value)
        filter_index1 = v5;     % dtto (max value)
        [C] = imcontour(Filtered_img, [filter_index0 filter_index1],'ok');
        % Count the sum of particles
        Sum_of_particles_hist_79 = (sum(C(:) == filter_index0));

v6 = 95;
        filter_index0 = v6;     % Input parameters for the image contour (least value)
        filter_index1 = v6;     % dtto (max value)
        [C] = imcontour(Filtered_img, [filter_index0 filter_index1],'ok');
        % Count the sum of particles
        Sum_of_particles_hist_95 = (sum(C(:) == filter_index0));

v7 = 111;
        filter_index0 = v7;     % Input parameters for the image contour (least value)
        filter_index1 = v7;     % dtto (max value)
        [C] = imcontour(Filtered_img, [filter_index0 filter_index1],'ok');
        % Count the sum of particles
        Sum_of_particles_hist_111 = (sum(C(:) == filter_index0));

v8 = 127;
        filter_index0 = v8;     % Input parameters for the image contour (least value)
        filter_index1 = v8;     % dtto (max value)
        [C] = imcontour(Filtered_img, [filter_index0 filter_index1],'ok');
        % Count the sum of particles
        Sum_of_particles_hist_127 = (sum(C(:) == filter_index0));

v9 = 143;
        filter_index0 = v9;     % Input parameters for the image contour (least value)
        filter_index1 = v9;     % dtto (max value)
        [C] = imcontour(Filtered_img, [filter_index0 filter_index1],'ok');
        % Count the sum of particles
        Sum_of_particles_hist_143 = (sum(C(:) == filter_index0));
v10 = 159;
        filter_index0 = v10;     % Input parameters for the image contour (least value)
        filter_index1 = v10;     % dtto (max value)
        [C] = imcontour(Filtered_img, [filter_index0 filter_index1],'ok');
        % Count the sum of particles
        Sum_of_particles_hist_159 = (sum(C(:) == filter_index0));
v11 = 175;
        filter_index0 = v11;     % Input parameters for the image contour (least value)
        filter_index1 = v11;     % dtto (max value)
        [C] = imcontour(Filtered_img, [filter_index0 filter_index1],'ok');
        % Count the sum of particles
        Sum_of_particles_hist_175 = (sum(C(:) == filter_index0));
v12 = 191;
        filter_index0 = v12;     % Input parameters for the image contour (least value)
        filter_index1 = v12;     % dtto (max value)
        [C] = imcontour(Filtered_img, [filter_index0 filter_index1],'ok');
        % Count the sum of particles
        Sum_of_particles_hist_191 = (sum(C(:) == filter_index0));
v13 = 207;
        filter_index0 = v13;     % Input parameters for the image contour (least value)
        filter_index1 = v13;     % dtto (max value)
        [C] = imcontour(Filtered_img, [filter_index0 filter_index1],'ok');
        % Count the sum of particles
        Sum_of_particles_hist_207 = (sum(C(:) == filter_index0));
v14 = 223;
        filter_index0 = v14;     % Input parameters for the image contour (least value)
        filter_index1 = v14;     % dtto (max value)
        [C] = imcontour(Filtered_img, [filter_index0 filter_index1],'ok');
        % Count the sum of particles
        Sum_of_particles_hist_223 = (sum(C(:) == filter_index0));
v15 = 239;
        filter_index0 = v15;     % Input parameters for the image contour (least value)
        filter_index1 = v15;     % dtto (max value)
        [C] = imcontour(Filtered_img, [filter_index0 filter_index1],'ok');
        % Count the sum of particles
        Sum_of_particles_hist_239 = (sum(C(:) == filter_index0));
v16 = 250;
        filter_index0 = v16;     % Input parameters for the image contour (least value)
        filter_index1 = v16;     % dtto (max value)
        [C] = imcontour(Filtered_img, [filter_index0 filter_index1],'ok');
        % Count the sum of particles
        Sum_of_particles_hist_250 = (sum(C(:) == filter_index0));

        
% Export v1-v8 so it can be used in Img_analysis program
setappdata(0,'v1',v1);
setappdata(0,'v2',v2);
setappdata(0,'v3',v3);
setappdata(0,'v4',v4);
setappdata(0,'v5',v5);
setappdata(0,'v6',v6);
setappdata(0,'v7',v7);
setappdata(0,'v8',v8);
setappdata(0,'v9',v9);
setappdata(0,'v10',v10);
setappdata(0,'v11',v11);
setappdata(0,'v12',v12);
setappdata(0,'v13',v13);
setappdata(0,'v14',v14);
setappdata(0,'v15',v15);
setappdata(0,'v16',v16);
end