Index: hep2cells/combinecells.m
===================================================================
--- hep2cells/combinecells.m	(revision 45)
+++ hep2cells/combinecells.m	(revision 45)
@@ -0,0 +1,23 @@
+function [labout,truelab] = combinecells(a,w)
+
+imlab = getident(a,'image');
+ll = unique(imlab);
+n = length(ll);
+lab = zeros(n,1);
+truelab = [];
+for i=1:n
+   I = find(imlab==ll(i));
+   out = a(I,:)*w;
+   %o2 = mean(out);
+   %o2 = median(out);
+   o2 = prod(out);
+   [tmp,lab(i)] = max(o2);
+
+   truelab(i,:) = getlab(a(I(1),:));
+end
+
+classll = getlabels(w);
+
+labout = classll(lab,:);
+truelab = char(truelab);
+
Index: hep2cells/makerotinv.m
===================================================================
--- hep2cells/makerotinv.m	(revision 45)
+++ hep2cells/makerotinv.m	(revision 45)
@@ -0,0 +1,32 @@
+% make rotational invariant features
+%
+% The whole procedure goes like:
+% 1. readcells.m       -> cells.mat
+% 1a. scalecellimage   -> cellscaled.mat
+% 2. gencellgabor.m    -> cells_gabor_sc.mat
+% 3. makerotinv
+% 3a. gencellsimple.m (max)  -> cellssimplemax.mat
+% 3b. gencellsimple.m (mean) -> cellssimplemean.mat
+% 3c. gencellsimple.m (var)  -> cellssimplevar.mat
+
+[a,b]=gencellsimple(x,z,'max');
+xnew = sumgabororientations(a);
+znew = sumgabororientations(b);
+[a,b]=gencellsimple(x,z,'mean');
+xnew = [xnew sumgabororientations(a)];
+znew = [znew sumgabororientations(b)];
+[a,b]=gencellsimple(x,z,'var');
+xnew = [xnew sumgabororientations(a)];
+znew = [znew sumgabororientations(b)];
+
+% fix a wrong labeling in the training set:
+lab = getlabels(xnew);
+I = strmatch('centromeric',lab);
+lab(I,:) = repmat('centromere     ',length(I),1);
+xnew = remclass(setlabels(xnew,lab));
+
+a = xnew; b = znew;
+save cellssimple_rotinv a b;
+
+
+
Index: hep2cells/normalizeperimage.m
===================================================================
--- hep2cells/normalizeperimage.m	(revision 45)
+++ hep2cells/normalizeperimage.m	(revision 45)
@@ -0,0 +1,11 @@
+function b = normalizeperimage(a)
+
+imlab = getident(a,'image');
+ll = unique(imlab);
+b = a;
+for i=1:ll
+   I = find(imlab==i);
+   wsc = scalem(a(I,:),'variance');
+   b(I,:) = a(I,:)*wsc;
+end
+
Index: hep2cells/readcells.m
===================================================================
--- hep2cells/readcells.m	(revision 45)
+++ hep2cells/readcells.m	(revision 45)
@@ -0,0 +1,49 @@
+% read the raw images, their masks and their labels:
+dpath='/Volumes/mm/PRLab/Data/icpr2012_continued/data/Main_Dataset/';
+N = 28;
+
+X = cell(1,1);
+k=0;
+for i=1:N
+   i
+   % first read the label file
+   dinfo = importdata(sprintf('%s/Images/%02d/%02d.csv',dpath,i,i));
+   dat = dinfo.textdata(2:end,:);
+   %cellid = str2num(cell2mat(dat(:,2)));
+   cellid = str2num(strvcat(dat(:,2)));
+   pattlab = dat(:,6);
+   % then read the images 
+   fnames = dir(sprintf('%s/Cells/Cell_Images/%02d/*.png',dpath,i));
+   M = size(fnames,1);
+   for j=1:M
+      k = k+1;
+      nr = str2num(fnames(j).name(1:3));
+      fullfname = sprintf('%s/Cells/Cell_Images/%02d/%s',dpath,i,fnames(j).name);
+      X{k,1} = importdata(fullfname);
+      fullfname = sprintf('%s/Cells/Cell_Masks/%02d/%s',dpath,i,fnames(j).name);
+      bigmask = importdata(fullfname);
+      X{k,2} = (bigmask(dinfo.data(nr,2):dinfo.data(nr,4)-1,...
+                       dinfo.data(nr,1):dinfo.data(nr,3)-1) > 0);
+      X{k,3} = i;
+      X{k,4} = pattlab(nr,:);
+      X{k,5} = nr;
+
+   end
+end
+
+
+Itrain = [ 1 2 3 5 6 7 8 9 11 14 18 20 25 26];
+Itest = [ 4 10 12 13 15 16 17 19 21 22 23 24 27 28];
+I = cell2mat(X(:,3));
+j = [];
+for i=1:length(Itrain)
+   j = [j; find(I==Itrain(i))];
+end
+x = X(j,:); 
+j = [];
+for i=1:length(Itest)
+   j = [j; find(I==Itest(i))];
+end
+z = X(j,:); 
+save cells x z;
+
Index: hep2cells/scalecellimage.m
===================================================================
--- hep2cells/scalecellimage.m	(revision 45)
+++ hep2cells/scalecellimage.m	(revision 45)
@@ -0,0 +1,94 @@
+% scale the intensities of the cells by looking at all cells in one
+% image
+load cells;
+
+% train data:
+I = cell2mat(x(:,3));
+for i=1:length(Itrain)  % over all train images
+   R=[]; G=[]; B=[];
+   J = find(I==Itrain(i));
+   for j=1:length(J)
+      msk = x{J(j),2};
+      % red:
+      im = x{J(j),1}(:,:,1);
+      pixs = im(msk);
+      R = [R; pixs(:)];
+      % green:
+      im = x{J(j),1}(:,:,2);
+      pixs = im(msk);
+      G = [G; pixs(:)];
+      % blue:
+      im = x{J(j),1}(:,:,3);
+      pixs = im(msk);
+      B = [B; pixs(:)];
+   end
+   % now find min and max:
+   % red:
+   mR = quantile(double(R),[0.001 0.999]);
+   mG = quantile(double(G),[0.001 0.999]);
+   mB = quantile(double(B),[0.001 0.999]);
+   for j=1:length(J)
+      im = double(x{J(j),1});
+      msk = double(x{J(j),2});
+      % red:
+      imR = im(:,:,1).*msk-mR(1);
+      if mR(2)>mR(1), imR = imR/(mR(2)-mR(1)); end
+      mR(mR<0) = 0; mR(mR>1) = 1;
+      % green:
+      imG = im(:,:,2).*msk-mG(1);
+      if mG(2)>mG(1), imG = imG/(mG(2)-mG(1)); end
+      mG(mG<0) = 0; mG(mG>1) = 1;
+      % blue:
+      imB = im(:,:,3).*msk-mB(1);
+      if mB(2)>mB(1), imB = imB/(mB(2)-mB(1)); end
+      mB(mB<0) = 0; mB(mB>1) = 1;
+      x{J(j),1} = cat(3,imR,imG,imB);
+   end
+end
+
+% test data:
+I = cell2mat(z(:,3));
+for i=1:length(Itest)  % over all train images
+   R=[]; G=[]; B=[];
+   J = find(I==Itest(i));
+   for j=1:length(J)
+      msk = z{J(j),2};
+      % red:
+      im = z{J(j),1}(:,:,1);
+      pixs = im(msk);
+      R = [R; pixs(:)];
+      % green:
+      im = z{J(j),1}(:,:,2);
+      pixs = im(msk);
+      G = [G; pixs(:)];
+      % blue:
+      im = z{J(j),1}(:,:,3);
+      pixs = im(msk);
+      B = [B; pixs(:)];
+   end
+   % now find min and max:
+   % red:
+   mR = quantile(double(R),[0.001 0.999]);
+   mG = quantile(double(G),[0.001 0.999]);
+   mB = quantile(double(B),[0.001 0.999]);
+   for j=1:length(J)
+      im = double(z{J(j),1});
+      msk = double(z{J(j),2});
+      % red:
+      imR = im(:,:,1).*msk-mR(1);
+      if mR(2)>mR(1), imR = imR/(mR(2)-mR(1)); end
+      mR(mR<0) = 0; mR(mR>1) = 1;
+      % green:
+      imG = im(:,:,2).*msk-mG(1);
+      if mG(2)>mG(1), imG = imG/(mG(2)-mG(1)); end
+      mG(mG<0) = 0; mG(mG>1) = 1;
+      % blue:
+      imB = im(:,:,3).*msk-mB(1);
+      if mB(2)>mB(1), imB = imB/(mB(2)-mB(1)); end
+      mB(mB<0) = 0; mB(mB>1) = 1;
+      z{J(j),1} = cat(3,imR,imG,imB);
+   end
+end
+
+save cellscaled x z Itrain Itest;
+
Index: hep2cells/sumgabororientations.m
===================================================================
--- hep2cells/sumgabororientations.m	(revision 45)
+++ hep2cells/sumgabororientations.m	(revision 45)
@@ -0,0 +1,13 @@
+function b = sumgabororientations(a)
+% sum the gabor outputs for the different orientations...
+% (because the features should be rotationally invariant)
+
+n = size(a,2)-1;
+n = n/4;
+
+b = a(:,1); % keep the first feature (original image)
+for i=0:(n-1)
+   I = 2+((i*4):(i*4+3));
+   b = [b mean(a(:,I),2)];
+end
+
