%This file executes function Gapson which creates BW figures
%Gapson connects ends of objects and gives nice fiber
%Save of file done with imwrite - much faster than other commands
clc;clear all;
nr_of_exp='exp_074';%<<<-------------
letter='X';
%Create directories
mkdir([letter,':\phejduk\fibers\',nr_of_exp,'\result_gap'])
mkdir([letter,':\phejduk\fibers\',nr_of_exp,'\result_gap2'])
mkdir([letter,':\phejduk\fibers\',nr_of_exp,'\result_out'])
mkdir([letter,':\phejduk\fibers\',nr_of_exp,'\result_gap\skeleton'])
mkdir([letter,':\phejduk\fibers\',nr_of_exp,'\result_gap2\skeleton'])
% Directories
directory=[letter,':\phejduk\fibers\',nr_of_exp,'\img_raw'];
directory2=[letter,':\phejduk\fibers\',nr_of_exp,'\result_gap'];
directory3=[letter,':\phejduk\fibers\',nr_of_exp,'\result_gap2'];
directory4=[letter,':\phejduk\fibers\',nr_of_exp,'\result_gap\skeleton'];
directory5=[letter,':\phejduk\fibers\',nr_of_exp,'\result_gap2\skeleton'];
% Look for images in directory
%Extension of images in direcory raw images
ending = '\*.tif';
%Extension of images in result_gap (normally bmp)
ending2 = '\*.bmp';
%From which image start
from=1;
%Last image, if 0 - you do it only for test
last_number=1;
%One threshold to cover surrounding of specific fiber to create BW mask
threshold_2=22;
%After mask was create it is normal 
threshold=30;
%Do not take into account distances larger than
limit1=20;
limit2=20;
crop=[200 200 500 550];%<<<------IMPORTANT
%Folder with functions
funkcje = [letter,':\pnakiel\__MATLAB_SCRIPTS_AND_PROGRAMS\FIBER_Brownian_motion_MSD_angle\MATLAB_SCRIPTS\PN'];
cd(funkcje)
Gapson(limit1,directory,directory2,directory4,ending,from,threshold,threshold_2,crop,last_number)
%If images looks OK you do not have to use it
Gapson2(limit2,directory2,directory3,directory5,ending2,from,last_number)
