-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp.m
152 lines (75 loc) · 2.56 KB
/
temp.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
addpath("C:\Users\GregP\Documents\MATLAB\lung-segmentation");
addpath("C:\Users\GregP\Documents\MATLAB\frangi_filter_version2a");
addpath("C:\Users\GregP\Documents\MATLAB\bwdistsc");
addpath("C:\Users\GregP\Documents\MATLAB\viewer3d_version12a\ReadData3D\dicom");
%dp="D:\Tomograms\Anonimous - 1516125\Pet Petct_Wholebody_Routine (Adult)\CT WB 1.5 B30f - 4";
%dp="D:\Tomograms\Chest_CT\PA000001\ST000001\SE000002";
srcDicomSeriesFolderPath="D:\Tomograms\Chest_CT\PA000001\ST000001\SE000002";
V=getRescaledDicomVolume(srcDicomSeriesFolderPath);
% Reduce the volume to accelerate computing.
%k=nthroot(50000000/numel(V),3);
%if (k<1)
% fprintf("The volume is too large for computing. Reducing the volume...\n");
% fprintf("Volume reducing coefficient: "+k+"\n");
% Vr=imresize3(V,k);
% fprintf("New voxel count: "+numel(Vr)+"\n");
%end
CRO=getRespiratoryOrgans(V);
%saveVoxelVolumeToBinaryFileGroup(F,"C:/Users/GregP/Documents/MATLAB/binary/fissures/");
Vd=double(V);
A=~imbinarize(Vd,-900);
LA=~imbinarize(Vd,-300);
[T,CL,EL1,EL2]=getTracheaFromRespiratoryOrgans(CRO,A,LA);
DT1=bwdist(EL1);
DT2=bwdist(EL2);
NNT=DT1<DT2;
L1=CL&NNT;
L2=CL&(~NNT);
CROs=getByMask(V,CRO);
F=getFissures(CROs,1);
E1=L1&(~erode(L1,3,1,'sphere'));
E2=L2&(~erode(L2,3,1,'sphere'));
F1=F&L1|E1;
F2=F&L2|E2;
DT1=bwdist(F1);
DT2=bwdist(F2);
DTM1=getByMask(DT1,L1);
DTM2=getByMask(DT2,L2);
DTO1=zeros(size(DTM1),'int32');
s=size(DTO1);
for x=1:s(1)
fprintf("x=%d\n",x);
for y=1:s(2)
for z=1:s(3)
v1=DTM1(x,y,z);
if (v1 ~= 0)
DTO1(x,y,z)=v1+300;
end
%if (F1(x,y,z) ~= 0)
% DTO1(x,y,z)=1524;
%end
end
end
end
fprintf("OK\n");
DTO2=zeros(size(DTM2),'int32');
s=size(DTO2);
for x=1:s(1)
fprintf("x=%d\n",x);
for y=1:s(2)
for z=1:s(3)
v1=DTM2(x,y,z);
if (v1 ~= 0)
DTO2(x,y,z)=v1+300;
end
%if (F2(x,y,z) ~= 0)
% DTO2(x,y,z)=1524;
%end
end
end
end
fprintf("OK\n");
newDicomSeriesFolderPath1="C:\Users\GregP\Documents\MATLAB\dicom9";
newDicomSeriesFolderPath2="C:\Users\GregP\Documents\MATLAB\dicom10";
saveVoxelVolumeToDicomFile(DTO1, srcDicomSeriesFolderPath, newDicomSeriesFolderPath1);
saveVoxelVolumeToDicomFile(DTO2, srcDicomSeriesFolderPath, newDicomSeriesFolderPath2);