Commit 567f008c002550d5ef72e37ba9fc032c278e74c3

Authored by Laila Saadatifard
1 parent c8150873

fix the ivote_3d code in matlab for the nissl-rat input data

Showing 1 changed file with 30 additions and 119 deletions   Show diff stats
Matlab_3D/main.m
... ... @@ -5,45 +5,44 @@ total = tic;
5 5  
6 6  
7 7 % ******* Initialize voting parameters **************************************
8   -rmax = 7; %maximum radius of the cell
  8 +rmax = 10; %maximum radius of the cell
9 9 ang_deg = 25.1; %half the angular range of the voting area
10 10 ang = ang_deg * pi / 180;
11   -iter = 5; %number of voting iterations
  11 +iter = 6; %number of voting iterations
12 12 t0 = 1.2; %threshold color
13   -sigma = [1, 1, 1];
  13 +sigma = [4, 4, 2];
14 14 % t = 0.1;
15 15 d_ang= ang / (iter);
16 16  
17 17 % ******** Testing parameters ******************************************
18   -% p = [100, 50, 100];
19   -% ps = [200, 200, 100];
20   -ps = [100, 50, 40];
21   -I = syn_Img(rmax , ps);
22   -% volfile = 'img\nissl-rat.vol';
23   -% fid = fopen(volfile); % open the file that include the image
24   -% S = fread(fid, 3, 'int32');
25   -% X = S(1);
26   -% Y = S(2);
27   -% Z = S(3);
28   -%
29   -% % load the VOL data into a 2D matrix
30   -% I = fread(fid,[X Y*Z], 'uint8');
31   -% fclose(fid);
32   -%
33   -% %change this to a 3D matrix
34   -% I = (reshape(I, [X, Y, Z]));
35   -%
36   -% % invert the intensity
37   -% I = 255 - I;
  18 +p = [100, 50, 100];
  19 +ps = [100, 100, 50];
  20 +% ps = [100, 50, 40];
  21 +% I = syn_Img(rmax , ps);
  22 +volfile = 'nissl-rat.vol';
  23 +fid = fopen(volfile); % open the file that include the image
  24 +S = fread(fid, 3, 'int32');
  25 +X = S(1);
  26 +Y = S(2);
  27 +Z = S(3);
  28 +
  29 +% load the VOL data into a 2D matrix
  30 +I = fread(fid,[X Y*Z], 'uint8');
  31 +fclose(fid);
  32 +
  33 +%change this to a 3D matrix
  34 +I = (reshape(I, [X, Y, Z]));
  35 +
  36 +% invert the intensity
  37 +I = 255 - I;
38 38  
39 39 %perform a gaussian blur
40 40 Iblur = gauss_blur3d(I, sigma);
41 41  
42   -%%crop out a small subregion of I and Iblur
43   -% Iblur = Iblur(p(1):p(1)+ps(1)-1, p(2):p(2)+ps(2)-1, p(3):p(3)+ps(3)-1);
44   -% I = I(p(1):p(1)+ps(1)-1, p(2):p(2)+ps(2)-1, p(3):p(3)+ps(3)-1);
  42 +%crop out a small subregion of I and Iblur
  43 +Iblur = Iblur(p(1):p(1)+ps(1)-1, p(2):p(2)+ps(2)-1, p(3):p(3)+ps(3)-1);
  44 +I = I(p(1):p(1)+ps(1)-1, p(2):p(2)+ps(2)-1, p(3):p(3)+ps(3)-1);
45 45  
46   -%
47 46 % compute the gradient
48 47 [Igrad_y, Igrad_x, Igrad_z] = gradient(Iblur);
49 48  
... ... @@ -90,35 +89,6 @@ validPixels = (zeros(nV,1));
90 89 % indices reference the 3D image
91 90 g_v_prime = (zeros(nV, (rmax^3)));
92 91  
93   -%--------------Display current data-------------------------
94   -% subplot(3, 3, 1),
95   -% imagesc(squeeze(I(:, :, ceil(size(I, 3)/2))));
96   -%
97   -% subplot(3, 3, 2),
98   -% imagesc(squeeze(I(:, ceil(size(I, 2)/2), :)));
99   -%
100   -% subplot(3, 3, 3),
101   -% imagesc(squeeze(I( ceil(size(I, 1)/2), :, :)));
102   -% %
103   -% subplot(3, 3, 4),
104   -% imagesc(squeeze(Iblur(:, :, ceil(size(Iblur, 3)/2))));
105   -%
106   -% subplot(3, 3, 5),
107   -% imagesc(squeeze(Iblur(:, ceil(size(Iblur, 2)/2), :)));
108   -%
109   -% subplot(3, 3, 6),
110   -% imagesc(squeeze(Iblur(ceil(size(Iblur, 1)/2), :, :)));
111   -%
112   -% subplot(3, 3, 7),
113   -% imagesc(squeeze(Imag(:, :, ceil(size(Imag, 3)/2))));
114   -%
115   -% subplot(3, 3, 8),
116   -% imagesc(squeeze(Imag(:, ceil(size(Imag, 2)/2), :)));
117   -%
118   -% subplot(3, 3, 9),
119   -% imagesc(squeeze(Imag(ceil(size(Imag, 1)/2), :, :)));
120   -%
121   -% colormap(gray);
122 92  
123 93 %% vote
124 94 tic;
... ... @@ -235,71 +205,12 @@ for itr = 1 : iter
235 205  
236 206  
237 207 %%
238   -t = 2500;
  208 +t = 250;
239 209 out = Ivote;
240 210 out(out<t) = 0;
241   -% out(out>=t) = 255;
242   -out = imregionalmax(out);
243 211  
244   -out1(:,:,:,1) = mat2gray(Iblur);
245   -out1(:,:,:,2) = mat2gray(out);
246   -out1(:,:,:,3) = mat2gray(Iblur);
247   -% out = out1;
  212 +fid_out = fopen('D:\ivote3_files\out.vol', 'w');
  213 +fwrite(fid_out, out);
  214 +fclose(fid_out);
248 215  
249 216  
250   -figure(4);
251   -
252   -subplot(2, 3, 1),
253   -imagesc(squeeze(Iblur(:, :, ceil(size(Iblur, 3)/2))));
254   -
255   -subplot(2, 3, 2),
256   -imagesc(squeeze(Iblur(:, ceil(size(Iblur, 2)/2), :)));
257   -
258   -subplot(2, 3, 3),
259   -imagesc(squeeze(Iblur( ceil(size(Iblur, 1)/2), :, :)));
260   -
261   -subplot(2, 3, 4),
262   -imagesc( squeeze( out1(:, :, ceil(size(Ivote, 3)/2),:) ) );
263   -
264   -subplot(2, 3, 5),
265   -imagesc(squeeze(out1(:, ceil(size(Ivote, 2)/2), :, :)));
266   -
267   -subplot(2, 3, 6),
268   -imagesc(squeeze(out1( ceil(size(Ivote, 1)/2), :, :, :)));
269   -
270   -colormap(gray);
271   -%%
272   -% figure, imagesc(squeeze(Iblur(:, :, ceil(size(Iblur, 3)/2)))); colormap(gray);
273   -% figure, imagesc(squeeze(Ivote(:, :, ceil(size(Ivote, 3)/2),:))); colormap(gray);
274   -% figure, imagesc(squeeze(Iblur(:, ceil(size(Iblur, 2)/2), :))); colormap(gray);
275   -% figure, imagesc(squeeze(I(:, ceil(size(Ivote, 2)/2), :))); colormap(gray);
276   -% % figure, imagesc(squeeze(Iblur( ceil(size(Iblur, 1)/2), :, :))); colormap(gray);
277   -% figure, imagesc(squeeze(Ivote( ceil(size(Ivote, 1)/2), :, :))); colormap(gray);
278   -%
279   -% fid0 = fopen('D:\ivote3_files\iblur.vol', 'w');
280   -% fwrite(fid0, Iblur);
281   -% fclose(fid0);
282   -%
283   -% fid1 = fopen('D:\ivote3_files\ivote1.vol', 'w');
284   -% fwrite(fid1, Ivote1);
285   -% fclose(fid1);
286   -%
287   -% fid2 = fopen('D:\ivote3_files\ivote2.vol', 'w');
288   -% fwrite(fid2, Ivote2);
289   -% fclose(fid2);
290   -%
291   -% fid3 = fopen('D:\ivote3_files\ivote3.vol', 'w');
292   -% fwrite(fid3, Ivote3);
293   -% fclose(fid3);
294   -%
295   -% fid4 = fopen('D:\ivote3_files\ivote4.vol', 'w');
296   -% fwrite(fid4, Ivote4);
297   -% fclose(fid4);
298   -%
299   -% fid5 = fopen('D:\ivote3_files\ivote5.vol', 'w');
300   -% fwrite(fid5, Ivote5);
301   -% fclose(fid5);
302   -%
303   -% fid10 = fopen('D:\ivote3_files\ivote10.vol', 'w');
304   -% fwrite(fid10, Ivote);
305   -% fclose(fid10);
... ...