%% Trans
fold='C:\Users\Alex\Desktop\Retroversa for Nancy\';
Pic=dir([fold '*jpg']);
clear trans

close all
for i=1:length(Pic)
    filename=fold;

    A=imread([filename Pic(i).name]);
    
    B=im2bw(A, 200/255); % binarizes
thresholdarea=10000; %minimum size of object = threshold area
diskradius=1; % low numbers work better
 bw = bwareaopen(1-B,thresholdarea);
    se = strel('disk',diskradius);
    bw = imclose(bw,se);    %identifying closed areas
    bw = imfill(bw,'holes'); %filling closed areas
    
    C=rgb2gray(A);
    imshow(C.*uint8(bw))
    [ox,oy]=(ginput(1));
    outx=[ox];
    outy=[oy];
    butt=1;
    while butt==1
        [oxx,oyy,butt]=(ginput(1));
        outx=[outx;oxx];
        outy=[outy;oyy];
        clear oxx oyy;
    end;
    
    exclude=roipoly(bw, outx, outy);
    

     bw=bw-exclude;
   bw(bw==-1)=0;
     
         [ox,oy]=(ginput(1));
    outx=[ox];
    outy=[oy];
    butt=1;
    while butt==1
        [oxx,oyy,butt]=(ginput(1));
        outx=[outx;oxx];
        outy=[outy;oyy];
        clear oxx oyy;
    end;
    
  include=roipoly(bw, outx, outy);
 bw=min(1, bw+include);

    
   object=C.*uint8(bw);
        stats=regionprops(bw, 'Area');
     area=stats(1).Area;
   average=mean(mean(object(object~=0)));
imshow(object)
figure
imshow(bw)   
 


trans(i)=average/255
end

%% Opacity
%     filename='C:\Users\Alex\Desktop\Tioga shells\TI787 bleached pictures\day 1\';
%     Pic=['o' nu '.tif'];
%     A=imread([filename Pic]);
%     
%     B=im2bw(A, 0.5/255); % binarizes 25
% thresholdarea=1000; %minimum size of object = threshold area
% diskradius=1; % low numbers work better
%  bw = bwareaopen(B,thresholdarea);
%     se = strel('disk',diskradius);
%     bw = imclose(bw,se);    %identifying closed areas
%     bw = imfill(bw,'holes'); %filling closed areas
%     
%     C=rgb2gray(A);
%     imshow(C.*uint8(bw))
%     [ox,oy]=(ginput(1));
%     outx=[ox];
%     outy=[oy];
%     butt=1;
%     while butt==1
%         [oxx,oyy,butt]=(ginput(1));
%         outx=[outx;oxx];
%         outy=[outy;oyy];
%         clear oxx oyy;
%     end;
%     
% %     include=roipoly(bw, outx, outy);
% %     bw=min(1, bw+include);
% 
%      exclude=roipoly(bw, outx, outy);
%     
% 
%      bw=bw-exclude;
%    bw(bw==-1)=0;
%    
%      figure
%    imshow(bw)
%      
%          [ox,oy]=(ginput(1));
%     outx=[ox];
%     outy=[oy];
%     butt=1;
%     while butt==1
%         [oxx,oyy,butt]=(ginput(1));
%         outx=[outx;oxx];
%         outy=[outy;oyy];
%         clear oxx oyy;
%     end;
%     
%   include=roipoly(bw, outx, outy);
%  bw=min(1, bw+include);
% 
% 
% object=C.*uint8(bw);
% average=mean(mean(object(object~=0)));
% % object(object>1.8*average)=0;
% % average=mean(mean(object(object~=0)));
% 
% imshow(object)
% figure
% imshow(bw)
% opacity=average/255