source: hep2cells/scalecellimage.m @ 123

Last change on this file since 123 was 45, checked in by dtax, 12 years ago

All useful files for processing of cells.

File size: 2.4 KB
Line 
1% scale the intensities of the cells by looking at all cells in one
2% image
3load cells;
4
5% train data:
6I = cell2mat(x(:,3));
7for i=1:length(Itrain)  % over all train images
8   R=[]; G=[]; B=[];
9   J = find(I==Itrain(i));
10   for j=1:length(J)
11      msk = x{J(j),2};
12      % red:
13      im = x{J(j),1}(:,:,1);
14      pixs = im(msk);
15      R = [R; pixs(:)];
16      % green:
17      im = x{J(j),1}(:,:,2);
18      pixs = im(msk);
19      G = [G; pixs(:)];
20      % blue:
21      im = x{J(j),1}(:,:,3);
22      pixs = im(msk);
23      B = [B; pixs(:)];
24   end
25   % now find min and max:
26   % red:
27   mR = quantile(double(R),[0.001 0.999]);
28   mG = quantile(double(G),[0.001 0.999]);
29   mB = quantile(double(B),[0.001 0.999]);
30   for j=1:length(J)
31      im = double(x{J(j),1});
32      msk = double(x{J(j),2});
33      % red:
34      imR = im(:,:,1).*msk-mR(1);
35      if mR(2)>mR(1), imR = imR/(mR(2)-mR(1)); end
36      mR(mR<0) = 0; mR(mR>1) = 1;
37      % green:
38      imG = im(:,:,2).*msk-mG(1);
39      if mG(2)>mG(1), imG = imG/(mG(2)-mG(1)); end
40      mG(mG<0) = 0; mG(mG>1) = 1;
41      % blue:
42      imB = im(:,:,3).*msk-mB(1);
43      if mB(2)>mB(1), imB = imB/(mB(2)-mB(1)); end
44      mB(mB<0) = 0; mB(mB>1) = 1;
45      x{J(j),1} = cat(3,imR,imG,imB);
46   end
47end
48
49% test data:
50I = cell2mat(z(:,3));
51for i=1:length(Itest)  % over all train images
52   R=[]; G=[]; B=[];
53   J = find(I==Itest(i));
54   for j=1:length(J)
55      msk = z{J(j),2};
56      % red:
57      im = z{J(j),1}(:,:,1);
58      pixs = im(msk);
59      R = [R; pixs(:)];
60      % green:
61      im = z{J(j),1}(:,:,2);
62      pixs = im(msk);
63      G = [G; pixs(:)];
64      % blue:
65      im = z{J(j),1}(:,:,3);
66      pixs = im(msk);
67      B = [B; pixs(:)];
68   end
69   % now find min and max:
70   % red:
71   mR = quantile(double(R),[0.001 0.999]);
72   mG = quantile(double(G),[0.001 0.999]);
73   mB = quantile(double(B),[0.001 0.999]);
74   for j=1:length(J)
75      im = double(z{J(j),1});
76      msk = double(z{J(j),2});
77      % red:
78      imR = im(:,:,1).*msk-mR(1);
79      if mR(2)>mR(1), imR = imR/(mR(2)-mR(1)); end
80      mR(mR<0) = 0; mR(mR>1) = 1;
81      % green:
82      imG = im(:,:,2).*msk-mG(1);
83      if mG(2)>mG(1), imG = imG/(mG(2)-mG(1)); end
84      mG(mG<0) = 0; mG(mG>1) = 1;
85      % blue:
86      imB = im(:,:,3).*msk-mB(1);
87      if mB(2)>mB(1), imB = imB/(mB(2)-mB(1)); end
88      mB(mB<0) = 0; mB(mB>1) = 1;
89      z{J(j),1} = cat(3,imR,imG,imB);
90   end
91end
92
93save cellscaled x z Itrain Itest;
94
Note: See TracBrowser for help on using the repository browser.