Download this file

83 lines (70 with data), 2.1 kB

 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
%Take imageSOPs and put them in imageSOP_UIDs matrix
for i=1573:size(coords, 1)
s1 = coords{i,:};
imname = paths(i);
s2 = regexp(s1, '\|', 'split');
s2(:);
for j= 1:size(s2,2)
s3(j) = regexp(s2(j), '\;', 'split');
end
for k=1:size(s2,2)-1
c=s3{k};
y=c{1};
x=c{2};
x=str2num(x);
y=str2num(y);
b(k)=x;
d(k)=y;
a(1,k)=x-287;
a(2,k)=y-87;
end
maxx=0;
maxy=0;
minx=0;
miny=0;
maxx= max(b);
maxy= max(d);
minx= min(b);
miny= min(d);
if exist(imname{:})>0
I = dicomread(imname{:});
J=dicominfo(imname{:});
RI=J.RescaleIntercept;
Icropped = I(minx:maxx,miny:maxy)-RI;
contour=zeros(size(Icropped));
Ibg=int16(zeros(size(Icropped)));
Inod=int16(zeros(size(Icropped)));
for f=1:size(s2,2)-1
x=b(f)-minx;
y=d(f)-miny;
contour(x+1,y+1)= 1;
end
contour=im2bw(contour);
I3=imfill(contour,'holes');
for l=1:size(contour,1)
for m=1:size(contour,2)
if I3(l,m)==0
Ibg(l,m)=Icropped(l,m);
Inod(l,m)=0;
else if I3(l,m)==1
Ibg(l,m)=0;
Inod(l,m)=Icropped(l,m);
end
end
end
end
%imshow(Icropped, [min(min(Icropped)) max(max(Icropped))]);
dicomwrite(Icropped, strcat('new/crop/',int2str(i),'.dcm'));
dicomwrite(contour, strcat('new/contours/',int2str(i),'.dcm'));
dicomwrite(int16(Ibg), strcat('new/segmented_background/',int2str(i),'.dcm'));
dicomwrite(int16(Inod), strcat('new/segmented_nodules/',int2str(i),'.dcm'));
i
clear I;
clear I3;
end
clear d;
clear b;
end
fclose(fid);
fclose(fid2);
%end