% generate a mil dataset from cells
clear all;load cells_gabor;

delta = 5; % how fine to sample the image

N = size(x,1);
bags = cell(N,1);
lab = [];
imlab = [];
for i=1:N
   i
   % store in:
   thisbag = [];
   % get gabor features
   gdat = x{i,1};
   msk = x{i,2};
   sz = size(gdat);
   for i1=1:delta:sz(1)
      for i2=1:delta:sz(2)
         if (msk(i1,i2)>0)
            thisbag = [thisbag; squeeze(gdat(i1,i2,:))'];
         end
      end
   end
   bags{i} = thisbag;
   %lab{i} = x{i,4};  % label of bag
   lab = [lab; x{i,4}];
   imlab = [imlab; repmat(x{i,3},size(thisbag,1),1)];  % original image label
end
a = genmil(bags,strvcat(lab));
a = setident(a,imlab,'image');

M = size(z,1);
bags = cell(M,1);
lab = [];
imlab = [];
for i=1:M
   i
   % store in:
   thisbag = [];
   % get gabor features
   gdat = z{i,1};
   msk = z{i,2};
   sz = size(gdat);
   for i1=1:delta:sz(1)
      for i2=1:delta:sz(2)
         if (msk(i1,i2)>0)
            thisbag = [thisbag; squeeze(gdat(i1,i2,:))'];
         end
      end
   end
   bags{i} = thisbag;
   %lab{i} = z{i,4};  % label of bag
   lab = [lab; z{i,4}];
   imlab = [imlab; repmat(z{i,3},size(thisbag,1),1)];  % original image label
end
b = genmil(bags,strvcat(lab));
b = setident(b,imlab,'image');

save cellsmil_delta5 a b;

