From 567f008c002550d5ef72e37ba9fc032c278e74c3 Mon Sep 17 00:00:00 2001 From: Laila Saadatifard Date: Fri, 9 Oct 2015 16:42:05 -0500 Subject: [PATCH] fix the ivote_3d code in matlab for the nissl-rat input data --- Matlab_3D/main.m | 149 ++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------- 1 file changed, 30 insertions(+), 119 deletions(-) diff --git a/Matlab_3D/main.m b/Matlab_3D/main.m index bc431fd..22b44cb 100644 --- a/Matlab_3D/main.m +++ b/Matlab_3D/main.m @@ -5,45 +5,44 @@ total = tic; % ******* Initialize voting parameters ************************************** -rmax = 7; %maximum radius of the cell +rmax = 10; %maximum radius of the cell ang_deg = 25.1; %half the angular range of the voting area ang = ang_deg * pi / 180; -iter = 5; %number of voting iterations +iter = 6; %number of voting iterations t0 = 1.2; %threshold color -sigma = [1, 1, 1]; +sigma = [4, 4, 2]; % t = 0.1; d_ang= ang / (iter); % ******** Testing parameters ****************************************** -% p = [100, 50, 100]; -% ps = [200, 200, 100]; -ps = [100, 50, 40]; -I = syn_Img(rmax , ps); -% volfile = 'img\nissl-rat.vol'; -% fid = fopen(volfile); % open the file that include the image -% S = fread(fid, 3, 'int32'); -% X = S(1); -% Y = S(2); -% Z = S(3); -% -% % load the VOL data into a 2D matrix -% I = fread(fid,[X Y*Z], 'uint8'); -% fclose(fid); -% -% %change this to a 3D matrix -% I = (reshape(I, [X, Y, Z])); -% -% % invert the intensity -% I = 255 - I; +p = [100, 50, 100]; +ps = [100, 100, 50]; +% ps = [100, 50, 40]; +% I = syn_Img(rmax , ps); +volfile = 'nissl-rat.vol'; +fid = fopen(volfile); % open the file that include the image +S = fread(fid, 3, 'int32'); +X = S(1); +Y = S(2); +Z = S(3); + +% load the VOL data into a 2D matrix +I = fread(fid,[X Y*Z], 'uint8'); +fclose(fid); + +%change this to a 3D matrix +I = (reshape(I, [X, Y, Z])); + +% invert the intensity +I = 255 - I; %perform a gaussian blur Iblur = gauss_blur3d(I, sigma); -%%crop out a small subregion of I and Iblur -% Iblur = Iblur(p(1):p(1)+ps(1)-1, p(2):p(2)+ps(2)-1, p(3):p(3)+ps(3)-1); -% I = I(p(1):p(1)+ps(1)-1, p(2):p(2)+ps(2)-1, p(3):p(3)+ps(3)-1); +%crop out a small subregion of I and Iblur +Iblur = Iblur(p(1):p(1)+ps(1)-1, p(2):p(2)+ps(2)-1, p(3):p(3)+ps(3)-1); +I = I(p(1):p(1)+ps(1)-1, p(2):p(2)+ps(2)-1, p(3):p(3)+ps(3)-1); -% % compute the gradient [Igrad_y, Igrad_x, Igrad_z] = gradient(Iblur); @@ -90,35 +89,6 @@ validPixels = (zeros(nV,1)); % indices reference the 3D image g_v_prime = (zeros(nV, (rmax^3))); -%--------------Display current data------------------------- -% subplot(3, 3, 1), -% imagesc(squeeze(I(:, :, ceil(size(I, 3)/2)))); -% -% subplot(3, 3, 2), -% imagesc(squeeze(I(:, ceil(size(I, 2)/2), :))); -% -% subplot(3, 3, 3), -% imagesc(squeeze(I( ceil(size(I, 1)/2), :, :))); -% % -% subplot(3, 3, 4), -% imagesc(squeeze(Iblur(:, :, ceil(size(Iblur, 3)/2)))); -% -% subplot(3, 3, 5), -% imagesc(squeeze(Iblur(:, ceil(size(Iblur, 2)/2), :))); -% -% subplot(3, 3, 6), -% imagesc(squeeze(Iblur(ceil(size(Iblur, 1)/2), :, :))); -% -% subplot(3, 3, 7), -% imagesc(squeeze(Imag(:, :, ceil(size(Imag, 3)/2)))); -% -% subplot(3, 3, 8), -% imagesc(squeeze(Imag(:, ceil(size(Imag, 2)/2), :))); -% -% subplot(3, 3, 9), -% imagesc(squeeze(Imag(ceil(size(Imag, 1)/2), :, :))); -% -% colormap(gray); %% vote tic; @@ -235,71 +205,12 @@ for itr = 1 : iter %% -t = 2500; +t = 250; out = Ivote; out(out=t) = 255; -out = imregionalmax(out); -out1(:,:,:,1) = mat2gray(Iblur); -out1(:,:,:,2) = mat2gray(out); -out1(:,:,:,3) = mat2gray(Iblur); -% out = out1; +fid_out = fopen('D:\ivote3_files\out.vol', 'w'); +fwrite(fid_out, out); +fclose(fid_out); -figure(4); - -subplot(2, 3, 1), -imagesc(squeeze(Iblur(:, :, ceil(size(Iblur, 3)/2)))); - -subplot(2, 3, 2), -imagesc(squeeze(Iblur(:, ceil(size(Iblur, 2)/2), :))); - -subplot(2, 3, 3), -imagesc(squeeze(Iblur( ceil(size(Iblur, 1)/2), :, :))); - -subplot(2, 3, 4), -imagesc( squeeze( out1(:, :, ceil(size(Ivote, 3)/2),:) ) ); - -subplot(2, 3, 5), -imagesc(squeeze(out1(:, ceil(size(Ivote, 2)/2), :, :))); - -subplot(2, 3, 6), -imagesc(squeeze(out1( ceil(size(Ivote, 1)/2), :, :, :))); - -colormap(gray); -%% -% figure, imagesc(squeeze(Iblur(:, :, ceil(size(Iblur, 3)/2)))); colormap(gray); -% figure, imagesc(squeeze(Ivote(:, :, ceil(size(Ivote, 3)/2),:))); colormap(gray); -% figure, imagesc(squeeze(Iblur(:, ceil(size(Iblur, 2)/2), :))); colormap(gray); -% figure, imagesc(squeeze(I(:, ceil(size(Ivote, 2)/2), :))); colormap(gray); -% % figure, imagesc(squeeze(Iblur( ceil(size(Iblur, 1)/2), :, :))); colormap(gray); -% figure, imagesc(squeeze(Ivote( ceil(size(Ivote, 1)/2), :, :))); colormap(gray); -% -% fid0 = fopen('D:\ivote3_files\iblur.vol', 'w'); -% fwrite(fid0, Iblur); -% fclose(fid0); -% -% fid1 = fopen('D:\ivote3_files\ivote1.vol', 'w'); -% fwrite(fid1, Ivote1); -% fclose(fid1); -% -% fid2 = fopen('D:\ivote3_files\ivote2.vol', 'w'); -% fwrite(fid2, Ivote2); -% fclose(fid2); -% -% fid3 = fopen('D:\ivote3_files\ivote3.vol', 'w'); -% fwrite(fid3, Ivote3); -% fclose(fid3); -% -% fid4 = fopen('D:\ivote3_files\ivote4.vol', 'w'); -% fwrite(fid4, Ivote4); -% fclose(fid4); -% -% fid5 = fopen('D:\ivote3_files\ivote5.vol', 'w'); -% fwrite(fid5, Ivote5); -% fclose(fid5); -% -% fid10 = fopen('D:\ivote3_files\ivote10.vol', 'w'); -% fwrite(fid10, Ivote); -% fclose(fid10); -- libgit2 0.21.4