close all
%% using 20x
% 50:0.07
% 45:0.09
% 40:0.08
% 35:0.10
% 30:0.14
% 25:0.34
% 20:0.50
% 15:0.67
% 10:0.78
%% using 10x, thres depends on grid_size(below based on 383)
% 50:0.179 thres ~ 
% 45:0.370       ~
% 40:0.367
% 35:0.449       ~ 
% 30:0.593       ~ 
% 25:0.626       ~ 
% 20:0.633
% 15:0.652 thres ~ 
% 10:0.576

%% get or set theoretical threshold value from exp data
%thres=slice_height(uint8(grid_size/2),uint8(0.67*channel_height));
%thres=0.03525
ratio=234/256;
% get threshold using
% integrated_val_at_max=sum(max(slice_height))
% integrated_val_at_min=sum(slice_height(50,:))


% threshold using ratio
%thres=slice_height(uint8(cropped_width/2),uint8(channel_height*ratio))
thres=0.015;
%% cut out final image depending on thres
slice_height_thres=slice_height;
figure;%subplot(1,2,1);
imagesc(abs(slice_height));colormap(pink);
axis image;
for as=1:size(slice_height_thres,1)
    for df=1:size(slice_height_thres,2)
        if slice_height(as,df)>thres
            slice_height_thres(as,df)=1;
        else
            slice_height_thres(as,df)=0;
        end
    end
end
figure;%subplot(1,2,2);
imagesc(abs(slice_height_thres));

colormap(gray); axis image;
title(['Thres=',num2str(thres)]);