%%%% with polymer
clear
clc
% cd   'G:\.shortcut-targets-by-id\13Eh4a7Dcx7E1N60KZXAf4HvcY7EV7u7L\Babak Vajdi Hokmabad\Data and Notes\KH in polymer Sol\Results\Analysis'
cd 'G:\.shortcut-targets-by-id\13Eh4a7Dcx7E1N60KZXAf4HvcY7EV7u7L\Babak Vajdi Hokmabad\Data and Notes\KH in polymer Sol\Results\Experiments\10052023__kymo2ch\4e10_BMB_Kymo2ch__frames\TRITC'
path='G:\.shortcut-targets-by-id\13Eh4a7Dcx7E1N60KZXAf4HvcY7EV7u7L\Babak Vajdi Hokmabad\Data and Notes\KH in polymer Sol\Results\Experiments\10052023__kymo2ch\4e10_BMB_Kymo2ch__frames\TRITC\';
m =6.19;  % magnification, spatial resolution in um/pix

core_traj = [1 456
    5  456
    10 456
    20 446 
    30 442
    40 438
    50 434
    60 431
    70 428
    80 424
    90 420
    100 418
    110 415
    120 412
    130 410
    140 408
    150 406
    160 404
    170 401
    180 399
    200 398
    250 390
    300 378
    350 364
    400 350
    450 336
    500 324
    550 308
    600 284
    650 284
    707 284
    707 284];

file=dir(path);
NF = length(file);
% I_avg =zeros(206,30);

% r=(0:214).*m;
num=0;

 for k=2:1:length(core_traj)
    disp (k);
    num=num+1
    file2=fullfile(path, file(core_traj(k,1)).name)
    fid=fopen(file2,'rt');
    img(:,:,:)=4095-imread(file2); 

    I = [imgaussfilt(img,'FilterSize',3)];  
    I_c = I(260:280,core_traj(k,2):490);
    I_avg = mean(I_c,1);
    I_avg = I_avg - 2795;
    I_avg_p(:,num) = mean(I_c,"all")- 2795;   %2795 is the equivalent of c_o2=0;
    
    r = core_traj(k,2):490;
    Content(num) = sum(I_avg.*r);
    clear I_c I_avg
    
   
 end


figure(1)
plot(core_traj(1:end-1,1),I_avg_p)


Content_inital = sum((284:490).*3665);
figure(2)
semilogy((10+core_traj(1:end-1,1))./(0.13*60),Content./Content_inital)   %3665 is the equivalent of c_o2=maximum; 206=R
ylim([0.025 1])
xlabel('time \rm(min)')    
ylabel('O_2 content / O_2 content_{sat}','Interpreter','tex')
ax = gca;
ax.LineWidth = 0.5;
ax.FontSize = 12;
ax.FontName = 'Arial';
pbaspect([2 1 1])





