% load the data:
%load cells;
load cellscaled;

% settings:
g_s = [1 2 3 5]; % scale
g_f = [0.1 0.3]; %freq
g_d = [0 0.25 0.5 0.75]*pi; % direction

% other 
ns = length(g_s);
nd = length(g_d);
nf = length(g_f);

% compute feature for train and test:
dim = ns*nd*nf;
N = size(x,1);
for i=1:N
   i
   % get image data from green channel:
   %im = x{i,1}(:,:,2);
   im = sum(x{i,1}(:,:,2),3);
   %if (min(im(:))<0) error('pixel values < 0'); end
%   im = im/max(im(:));
   im = double(hist_equalize(im));
   %newx:
   newx = zeros(size(im,1),size(im,2),dim+1);
   newx(:,:,1) = im;
   % get gabor features 
   j=1;
   for i1=1:ns
      for i2=1:nf
         for i3=1:nd
            j=j+1;
            newx(:,:,j) = abs(gabor(im,g_s(i1),g_f(i2),g_d(i3)));
         end
      end
   end
   x{i,1} = newx;
end
M = size(z,1);
for i=1:M
   i
   % get image data from green channel:
   %im = z{i,1}(:,:,2);
   im = sum(z{i,1}(:,:,2),3);
   %if (min(im(:))<0) error('pixel values < 0'); end
%   im = im/max(im(:));
   im = double(hist_equalize(im));
   %newz:
   newz = zeros(size(im,1),size(im,2),dim+1);
   newz(:,:,1) = im;
   % get gabor features 
   j=1;
   for i1=1:ns
      for i2=1:nf
         for i3=1:nd
            j=j+1;
            newz(:,:,j) = abs(gabor(im,g_s(i1),g_f(i2),g_d(i3)));
         end
      end
   end
   z{i,1} = newz;
end

save cells_gabor_sc x z;
