tic;
clear all;
clc;
my_folder='\image_samples\';

path=strcat(pwd,my_folder);
images=load_images(path);

matrix = []; % Initialize to null.
stats22= [];
add_mat=[];
tdf=[];
dim=0;
pas=0
PT_nou=[];
for t = 1:length(images)
fullpath=strcat(path,images);
A = rgb2gray(imread(fullpath{t,1}));
[L1,N1] = superpixels(A,100);
BW1 = boundarymask(L1);
stars1=[];
[m n]=size(A)
T1=zeros(n,n);
k=1;
while k<N1
for i=1:m
    for j=1:n
        %mat_labels{i,1}= images{t,1}
    if (L1(i,j)==k && A(i,j)~=0)
        T1(i,j)=L1(i,j);
%         P(k)=BoxCountfracDim(T1)
         
    end
    end
   
end
    nr=k;
    k=k+1;
end


 stats1{t,1} = regionprops(T1,'Perimeter','Area','Eccentricity','Orientation','ConvexArea','MajorAxisLength')
 
 
 T{t,1}=[stats1{t,1}.Perimeter; stats1{t,1}.Area; stats1{t,1}.Eccentricity; stats1{t,1}.Orientation; stats1{t,1}.ConvexArea; stats1{t,1}.MajorAxisLength]';
 T{t,2}=images{t,1};
 
 
 
 add_mat={images{t,1}, 'img', 'img', 'img', 'img', 'img'};
 add_mat_nou=[add_mat(:,1); T{t,1}]
 matrix=[matrix; add_mat_nou]
 
end

 PT_nou_img=[];
  for st=1:length(matrix)
      if rem(st,2)==0
        Pt=matrix(st,1);
        PT_nou=[PT_nou; Pt]
      else
        Pt_img=matrix(st,1);
        PT_nou_img=[PT_nou_img; Pt_img]
      end
  end
  
  PTT=[];
  PTT_nou=[]
  PTT_img_fin=[]
  for iterate=1:length(PT_nou)
      
      PTT=PT_nou{iterate,1};
      for iteratie2=1:length(PTT)
          PTT_img(iteratie2,1)=PT_nou_img(iterate,1);
          PTT_img_fin=[PTT_img_fin; PTT_img(iteratie2,1)]
      end
      PTT_nou=[PTT_nou; PTT]  
  end
  
  perim=PTT_nou(:,1);
  aria=PTT_nou(:,2);
  exentr=PTT_nou(:,3);
  orien=PTT_nou(:,4);
  convex=PTT_nou(:,5);
  diam=PTT_nou(:,6);
  circ=4*pi.*aria./perim.^2;
  w=size(perim)
  for i=1:w
      if (perim(i)==0 || aria(i)==0)
                  circ(i)=0
      end
  end
    
col_header={'perim', 'aria', 'exentr', 'orien', 'convex', 'diam', 'circ'};
AAAx=[perim aria exentr orien convex diam circ]
filename='file1.xlsx';
xlswrite(filename,col_header,1,'A1');
xlswrite(filename,AAAx,1,'A2');

col_header2={'label'};

filename='file2.xlsx';
xlswrite(filename,col_header2,1,'A1');
xlswrite(filename,PTT_img_fin,1,'A2');
toc;
  