Skip to content

Commit

Permalink
new version
Browse files Browse the repository at this point in the history
  • Loading branch information
farrowlab committed Sep 20, 2017
1 parent c34a1d8 commit 5876548
Show file tree
Hide file tree
Showing 9 changed files with 362 additions and 154 deletions.
2 changes: 1 addition & 1 deletion CaffeInstallation.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ echo 'export CAFFE_ROOT=/opt/3D-Caffe' >> ~/.bashrc
echo 'export PYTHONPATH=/opt/3D-Caffe/distribute/python:$PYTHONPATH' >> ~/.bashrc
echo 'export PYTHONPATH=/opt/3D-Caffe/python:$PYTHONPATH' >> ~/.bashrc
echo 'export PATH=/usr/local/cuda-8.0/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/opt/3D-Caffe/distribute/lib:/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
Empty file modified CreateTrainingData.m
100644 → 100755
Empty file.
78 changes: 78 additions & 0 deletions DetectOFFSurface2.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
function [vzmesh] = DetectOFFSurface2(im, name)
%STEP 5%%%%%%%%%%%%%%%%SURFACE OFF DETECTION%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%files = dir('/home/quan/Desktop/VNet/Results/*_rotate.tif');
%for file = files'
FileTif = name;
existfile = strrep(FileTif,'_rotate.tif','_validation_ON_OFF_2.tif');
if exist(strcat('/media/areca_raid/VNet/SurfacesDetected/',existfile), 'file') ~= 2
%FileTif = '/home/quan/Desktop/VNet/Results/00643_1L_C05_chAT_STD_rotate.tif';
%FileTif = '00505_2R_C01_chAT_STD.tif'
%InfoImage=imfinfo(FileTif);
%mImage=InfoImage(1).Width;
%nImage=InfoImage(1).Height;
[a,b,c] = size(im);
NumberImages = c;
BW=zeros(a,b,c,'uint8');

for i=1:c
% TifLink.setDirectory(i);
% im(:,:,i)=TifLink.read();
BW(:,:,i)= imbinarize(im(:,:,i),0.01);
end

CC = bwconncomp(BW);
numOfPixels = cellfun(@numel,CC.PixelIdxList);
[unused, indexOfMax] = max(numOfPixels);
numOfPixels(indexOfMax) = [];
[unused2, indexOfSecondMax] = max(numOfPixels);
biggest = zeros(size(BW));
biggest(CC.PixelIdxList{indexOfMax}) = 1;
%biggest(CC.PixelIdxList{indexOfSecondMax}) = 1;
[r,c,h] = size(biggest);
ptOFFnum = 1;
for i=1:NumberImages
%imshow(biggest(:,:,i))
for cpix = 1:10:c
cnt = 1;
tempRow = zeros(1,50);
for rpix = 1:r
if biggest(rpix, cpix, i) == 1
tempRow(cnt) = rpix;
cnt = cnt + 1;
end
end
tempRow = tempRow(tempRow~=0);
if size(tempRow,2) > 1
randrow = tempRow(round(size(tempRow,2)/2));
OFFX(ptOFFnum) = randrow;
OFFY(ptOFFnum) = cpix;
OFFZ(ptOFFnum) = i;
ptOFFnum = ptOFFnum + 1;
end
%tempRow = [];
end
end

% ONX = ONX(ONX~=0);
% ONY = ONY(ONY~=0);
% ONZ = ONZ(ONZ~=0);

z = OFFX;
y = OFFY;
x = OFFZ;
%
xMax = max(x); yMax = max(y);
[zgrid,xgrid,ygrid] = gridfit(x,y,z,[[1:3:xMax-1] xMax],[[1:3:yMax-1] yMax],'smoothness',1);
% linearly (fast) interpolate to fine grid
[xi,yi]=meshgrid(1:xMax,1:yMax); xi = xi'; yi = yi';
vzmesh=interp2(xgrid,ygrid,zgrid,xi,yi,'*linear',mean(zgrid(:)));
% vz = uint16(vzmesh);
clear OFFX
clear OFFY
clear OFFZ
clear x
clear y
clear z
end

end
215 changes: 115 additions & 100 deletions DetectONOFFSurface.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
% im(:,:,i)=TifLink.read();
a = mat2gray(im(:,:,i));
%T = adaptthresh(a,0.9);
%BW = imbinarize(a,T)
%BW = imbinarize(a,T)
BW(:,:,i)= imbinarize(a,0.7);
end
% TifLink.close();
Expand All @@ -41,9 +41,9 @@
%rgb = label2rgb(L(:,:,i), 'jet', [.7 .7 .7], 'shuffle');
%imshow(rgb)
%end

for i=1:NumberImages

sliceONx = zeros(10000,1);
sliceONy = zeros(10000,1);
sliceONz = zeros(10000,1);
Expand Down Expand Up @@ -74,7 +74,7 @@
tempy = zeros(6,1); %init at every col
tempz = zeros(6,1);
tempsize = zeros(6,1);

%tic
for rowpix = 1:r
if L(rowpix,colpix) ~= 0
Expand All @@ -93,74 +93,74 @@
end

if count == 2
if slicePtsON == 1
if slicePtsON == 1
%%%%initially, first 2 points just pick ...
sliceONx(slicePtsON) = tempx(1);
sliceONy(slicePtsON) = tempy(1);
sliceONz(slicePtsON) = tempz(1);
slicePtsON = slicePtsON + 1;
if ~ismember(L(tempx(1),tempy(1)),GROUPON(:))
GROUPON(groupONcount) = L(tempx(1),tempy(1));
groupONcount = groupONcount + 1;
end
ONX(ptONnum) = tempx(1);
ONY(ptONnum) = tempy(1);
ONZ(ptONnum) = tempz(1);
ptONnum = ptONnum + 1;
sliceONx(slicePtsON) = tempx(1);
sliceONy(slicePtsON) = tempy(1);
sliceONz(slicePtsON) = tempz(1);
slicePtsON = slicePtsON + 1;
if ~ismember(L(tempx(1),tempy(1)),GROUPON(:))
GROUPON(groupONcount) = L(tempx(1),tempy(1));
groupONcount = groupONcount + 1;
end
ONX(ptONnum) = tempx(1);
ONY(ptONnum) = tempy(1);
ONZ(ptONnum) = tempz(1);
ptONnum = ptONnum + 1;

end
if slicePtsOFF == 1
sliceOFFx(slicePtsOFF) = tempx(2);
sliceOFFy(slicePtsOFF) = tempy(2);
sliceOFFz(slicePtsOFF) = tempz(2);
slicePtsOFF = slicePtsOFF + 1;
if slicePtsOFF == 1
sliceOFFx(slicePtsOFF) = tempx(2);
sliceOFFy(slicePtsOFF) = tempy(2);
sliceOFFz(slicePtsOFF) = tempz(2);
slicePtsOFF = slicePtsOFF + 1;

if ~ismember(L(tempx(2),tempy(2)),GROUPOFF(:))
GROUPOFF(groupOFFcount) = L(tempx(2),tempy(2));
groupOFFcount = groupOFFcount + 1;
end
OFFX(ptOFFnum) = tempx(2);
OFFY(ptOFFnum) = tempy(2);
OFFZ(ptOFFnum) = tempz(2);
%groundImage(ONX(ptONnum),ONY(ptONnum),ONZ(ptONnum)) = 255 ;
ptOFFnum = ptOFFnum + 1;
if ~ismember(L(tempx(2),tempy(2)),GROUPOFF(:))
GROUPOFF(groupOFFcount) = L(tempx(2),tempy(2));
groupOFFcount = groupOFFcount + 1;
end
OFFX(ptOFFnum) = tempx(2);
OFFY(ptOFFnum) = tempy(2);
OFFZ(ptOFFnum) = tempz(2);
%groundImage(ONX(ptONnum),ONY(ptONnum),ONZ(ptONnum)) = 255 ;
ptOFFnum = ptOFFnum + 1;
end
%%if more pts now, check
% if ptONnum > 1 && abs(tempx(1) - ONX(ptONnum - 1)) < 10
% sliceONx(slicePtsON) = tempx(1);
% sliceONy(slicePtsON) = tempy(1);
% sliceONz(slicePtsON) = tempz(1);
% slicePtsON = slicePtsON + 1;
% if ~ismember(L(tempx(1),tempy(1)),GROUPON(:))
% GROUPON(groupONcount) = L(tempx(1),tempy(1));
% groupONcount = groupONcount + 1;
% end
% ONX(ptONnum) = tempx(1);
% ONY(ptONnum) = tempy(1);
% ONZ(ptONnum) = tempz(1);
% ptONnum = ptONnum + 1;
% end
% if ptOFFnum > 1 && abs(tempx(2) - OFFX(ptOFFnum - 1)) < 10
% sliceOFFx(slicePtsOFF) = tempx(2);
% sliceOFFy(slicePtsOFF) = tempy(2);
% sliceOFFz(slicePtsOFF) = tempz(2);
% slicePtsOFF = slicePtsOFF + 1;
%
%
% if ~ismember(L(tempx(2),tempy(2)),GROUPOFF(:))
% GROUPOFF(groupOFFcount) = L(tempx(2),tempy(2));
% groupOFFcount = groupOFFcount + 1;
% end
% OFFX(ptOFFnum) = tempx(2);
% OFFY(ptOFFnum) = tempy(2);
% OFFZ(ptOFFnum) = tempz(2);
% %groundImage(ONX(ptONnum),ONY(ptONnum),ONZ(ptONnum)) = 255 ;
% ptOFFnum = ptOFFnum + 1;
% end

%%if more pts now, check
% if ptONnum > 1 && abs(tempx(1) - ONX(ptONnum - 1)) < 10
% sliceONx(slicePtsON) = tempx(1);
% sliceONy(slicePtsON) = tempy(1);
% sliceONz(slicePtsON) = tempz(1);
% slicePtsON = slicePtsON + 1;
% if ~ismember(L(tempx(1),tempy(1)),GROUPON(:))
% GROUPON(groupONcount) = L(tempx(1),tempy(1));
% groupONcount = groupONcount + 1;
% end
% ONX(ptONnum) = tempx(1);
% ONY(ptONnum) = tempy(1);
% ONZ(ptONnum) = tempz(1);
% ptONnum = ptONnum + 1;
% end
% if ptOFFnum > 1 && abs(tempx(2) - OFFX(ptOFFnum - 1)) < 10
% sliceOFFx(slicePtsOFF) = tempx(2);
% sliceOFFy(slicePtsOFF) = tempy(2);
% sliceOFFz(slicePtsOFF) = tempz(2);
% slicePtsOFF = slicePtsOFF + 1;
%
%
% if ~ismember(L(tempx(2),tempy(2)),GROUPOFF(:))
% GROUPOFF(groupOFFcount) = L(tempx(2),tempy(2));
% groupOFFcount = groupOFFcount + 1;
% end
% OFFX(ptOFFnum) = tempx(2);
% OFFY(ptOFFnum) = tempy(2);
% OFFZ(ptOFFnum) = tempz(2);
% %groundImage(ONX(ptONnum),ONY(ptONnum),ONZ(ptONnum)) = 255 ;
% ptOFFnum = ptOFFnum + 1;
% end

if slicePtsON > 1
if abs(tempx(1) - sliceONx(slicePtsON - 1)) < 10
if abs(tempx(1) - sliceONx(slicePtsON - 1)) < 15
sliceONx(slicePtsON) = tempx(1);
sliceONy(slicePtsON) = tempy(1);
sliceONz(slicePtsON) = tempz(1);
Expand All @@ -180,7 +180,7 @@
end

if slicePtsOFF > 1
if abs(tempx(2) - sliceOFFx(slicePtsOFF - 1)) < 10
if abs(tempx(2) - sliceOFFx(slicePtsOFF - 1)) < 15
sliceOFFx(slicePtsOFF) = tempx(2);
sliceOFFy(slicePtsOFF) = tempy(2);
sliceOFFz(slicePtsOFF) = tempz(2);
Expand Down Expand Up @@ -283,16 +283,16 @@
ONY = ONY(ONY~=0);
ONZ = ONZ(ONZ~=0);

% Data = [ONX, ONY, ONZ];
% datanum = size(ONX,1);
% datanum = round((datanum/100)*30);
% Data = datasample(Data,datanum);
% %ONY = datasample(ONY,datanum);
% %ONZ = datasample(ONZ,datanum);
% %
% ONX= Data(:,1);
% ONY = Data(:,2);
% ONZ = Data(:,3);
% Data = [ONX, ONY, ONZ];
% datanum = size(ONX,1);
% datanum = round((datanum/100)*30);
% Data = datasample(Data,datanum);
% %ONY = datasample(ONY,datanum);
% %ONZ = datasample(ONZ,datanum);
% %
% ONX= Data(:,1);
% ONY = Data(:,2);
% ONZ = Data(:,3);
z = ONX;
y = ONY;
x = ONZ;
Expand All @@ -302,23 +302,23 @@
% linearly (fast) interpolate to fine grid
[xi,yi]=meshgrid(1:xMax,1:yMax); xi = xi'; yi = yi';
vzmesh=interp2(xgrid,ygrid,zgrid,xi,yi,'*spline',mean(zgrid(:)));
vz = uint16(vzmesh);



OFFX = OFFX(OFFX~=0);
OFFY = OFFY(OFFY~=0);
OFFZ = OFFZ(OFFZ~=0);

% Data = [OFFX, OFFY, OFFZ];
% datanum = size(OFFX,1);
% datanum = round((datanum/100)*30);
% Data = datasample(Data,datanum);
% %ONY = datasample(ONY,datanum);
% %ONZ = datasample(ONZ,datanum);
% %
% OFFX= Data(:,1);
% OFFY = Data(:,2);
% OFFZ = Data(:,3);
% Data = [OFFX, OFFY, OFFZ];
% datanum = size(OFFX,1);
% datanum = round((datanum/100)*30);
% Data = datasample(Data,datanum);
% %ONY = datasample(ONY,datanum);
% %ONZ = datasample(ONZ,datanum);
% %
% OFFX= Data(:,1);
% OFFY = Data(:,2);
% OFFZ = Data(:,3);

z2 = OFFX;
y2 = OFFY;
Expand All @@ -329,15 +329,29 @@
% linearly (fast) interpolate to fine grid
[xi2,yi2]=meshgrid(1:xMax2,1:yMax2); xi2 = xi2'; yi2 = yi2';
vzmesh2=interp2(xgrid2,ygrid2,zgrid2,xi2,yi2,'*spline',mean(zgrid2(:)));
vz2 = uint16(vzmesh2);

%mesh(vzmesh);hold on;mesh(vzmesh2);


diff = vzmesh2 - vzmesh;
B = diff<0;
[a b] = size(B);
for i = 1:a
for j = 1:b
if B(i,j) == 1
temp = vzmesh2(i,j);
vzmesh2(i,j) = vzmesh(i,j);
vzmesh(i,j) = temp;
end
end
end
vz = uint16(vzmesh);
vz2 = uint16(vzmesh2);
%%%create groundtruth to test
%'/home/quan/Desktop/VNet/ImagesHere/*chAT_STD.tif'
orgname = strrep(FileTif,'_rotate.tif','');
orgname = strcat(orgname,'.tif');
orgname = strcat('/home/quan/Desktop/VNet/ImagesHere/',orgname);
orgname = strcat('/media/areca_raid/VNet/ImagesHere/',orgname);

[a,b,c] = size(BW);
groundImage = zeros(c,b,a);
Expand All @@ -361,21 +375,22 @@
vz(i,j) = 1;
end
groundImage(i,j, vz(i,j)) = 255;
if vz2(i,j) == 0
vz2(i,j) = 1;
end
groundImage(i,j,vz2(i,j)) = 255;
%validationImage(i,j,vz(i,j)) = 0;
end
end


[r c] = size(vz2);
for i = 1:r
for j = 1:c
if vz2(i,j) == 0
vz2(i,j) = 1;
end
groundImage(i,j,vz2(i,j)) = 255;
% validationImage(j,i,vz2(i,j)) = 0;
end
end
% [r c] = size(vz2);
% for i = 1:r
% for j = 1:c

% validationImage(j,i,vz2(i,j)) = 0;
% end
% end


%%%store mask to verify correctness%%%%%
Expand Down
Loading

0 comments on commit 5876548

Please sign in to comment.