-
Notifications
You must be signed in to change notification settings - Fork 2
/
Skeletonize_all_rework_22.m
81 lines (59 loc) · 2.3 KB
/
Skeletonize_all_rework_22.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
clear
%%% Parallel control
% This part is only for HPC to distribute the parallel profiles
% coreCount :: number of cores per node
coreCount =22;
aa = parcluster
temp_folder = ['./matlab_cluster_', datestr(now,'yyyy-mm-dd-HH-MM-SS-FFF')];
mkdir(temp_folder);
aa.JobStorageLocation = temp_folder;
parpool(aa,coreCount ,'IdleTimeout',inf)
%% General setting
% dir_in :: input folder
% dir_out :: output folder
dir_in = [pwd '/binarized'];
dir_out = [pwd '/skeletonized'];
mkdir(dir_out);
% functions
% dialate_erode(dir_in, core_using)
% :: remove small cavities by using dialation and errodsion (current hard codded setting 4 pixxels)
% The results will be store in the dir_in as bin files,
% each file contain 50 pixels slices in z
% preparingFiles(dir_in, dir_out,coreCount)
% :: make copies of the first and last slice in z for each
% file and move it to dir_out. The extra slice is prepared
% for the later parallelization since skeletonization
% require +1 info for each step
% Skeleton3D_YTW_sub_sub :: parallel optimized skeletonization step that
% read from files and write to files
dialate_erode(dir_in,coreCount);
preparingFiles(dir_in, dir_out,coreCount);
DirTif = dir([dir_in '/*.tif']);
numberFiles = length(DirTif);
FileTif=[DirTif(1).folder '/' DirTif(1).name];
InfoImage=imfinfo(FileTif);
mImage=InfoImage(1).Width;
nImage=InfoImage(1).Height;
lImage= length(InfoImage);
cropSize = [nImage, mImage, lImage];
mkdir([dir_out '/temp/']);
loopNumber = 1;
unchangedBorders = 0;
while unchangedBorders ~= 6
unchangedBorders = 0;
for currentBorder=1:6 % loop over all 6 directions
fprintf(['loop #' num2str(loopNumber) ' boarder #' num2str(currentBorder) '\n' ]);
noChange = false(1,numberFiles);
tic
parfor (ii = 1:numberFiles, coreCount)
noChange(ii) = Skeleton3D_YTW_sub_sub(currentBorder,ii,numberFiles,cropSize,dir_out);
end
movefile([dir_out '/temp/*'], dir_out);
toc
fprintf(['stacks changing: ' num2str(sum(~noChange,'all')) '\n']);
if( ~any(~noChange) )
unchangedBorders = unchangedBorders + 1;
end
end
loopNumber = loopNumber +1;
end