|
a |
|
b/Image features calculation code/Not Working/Imagefill.m |
|
|
1 |
%filename = 'C:\Documents and Settings\akim2\Desktop\IMFILL\new_parsed_xml.csv'; |
|
|
2 |
filename = '\\ailab03\NEW_LIDC\LIDC\extract LIDC\new_parsed_xml.csv'; |
|
|
3 |
excelSheet = csvread_mod(filename); |
|
|
4 |
count= 1; |
|
|
5 |
for t= 1:size(excelSheet,1) |
|
|
6 |
R = rem(t,18); |
|
|
7 |
if R==0 |
|
|
8 |
coor(count,1)=excelSheet(t,1) ; |
|
|
9 |
count = count+1; |
|
|
10 |
end |
|
|
11 |
end |
|
|
12 |
counter =1; |
|
|
13 |
%Take imageSOPs and put them in imageSOP_UIDs matrix |
|
|
14 |
|
|
|
15 |
|
|
|
16 |
%for t=1:size(excelSheet, 1) |
|
|
17 |
fid = fopen ('nodules_features.txt', 'wt'); |
|
|
18 |
fid2 = fopen ('nodules_many_regions.txt', 'wt'); |
|
|
19 |
fprintf(fid,'%s,%s,%s,%s,%s,%s,%s,%s,%s \n','ImageName','Circularity','Roughness','Elongation','Compactness','Eccentricity','Solidity','Extent','RadialDistanceSD'); |
|
|
20 |
fprintf(fid2,'%s,%s,%s,%s,%s,%s,%s,%s,%s \n','ImageName','Circularity','Roughness','Elongation','Compactness','Eccentricity','Solidity','Extent','RadialDistanceSD'); |
|
|
21 |
|
|
|
22 |
for i=2:size(excelSheet, 1) |
|
|
23 |
s1 = coor{i,:}; |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
s2 = regexp(s1, '\|', 'split'); |
|
|
27 |
|
|
|
28 |
|
|
|
29 |
s2(:); |
|
|
30 |
for j= 1:size(s2,2) |
|
|
31 |
s3(j) = regexp(s2(j), '\;', 'split'); |
|
|
32 |
end |
|
|
33 |
|
|
|
34 |
for k=1:size(s2,2)-1 |
|
|
35 |
c=s3{k}; |
|
|
36 |
y=c{1}; |
|
|
37 |
x=c{2}; |
|
|
38 |
x=str2num(x); |
|
|
39 |
y=str2num(y); |
|
|
40 |
b(k)=x; |
|
|
41 |
d(k)=y; |
|
|
42 |
a(1,k)=x-287; |
|
|
43 |
a(2,k)=y-87; |
|
|
44 |
|
|
|
45 |
end |
|
|
46 |
maxx=0; |
|
|
47 |
maxy=0; |
|
|
48 |
minx=0; |
|
|
49 |
miny=0; |
|
|
50 |
%for c= 1:k |
|
|
51 |
maxx= max(b); |
|
|
52 |
maxy= max(d); |
|
|
53 |
minx= min(b); |
|
|
54 |
miny= min(d); |
|
|
55 |
I= zeros((maxx-minx)+1,(maxy-miny)+1); |
|
|
56 |
%end |
|
|
57 |
for f=1:size(s2,2)-1 |
|
|
58 |
x=b(f)-minx; |
|
|
59 |
y=d(f)-miny; |
|
|
60 |
I(x+1,y+1)= 1; |
|
|
61 |
end |
|
|
62 |
I2=im2bw(I); |
|
|
63 |
I3=imfill(I2,'holes'); |
|
|
64 |
%figure; |
|
|
65 |
%imshow(I3); |
|
|
66 |
|
|
|
67 |
%HERE GOES FEATURE CALCULATION STUFF |
|
|
68 |
count = 0; |
|
|
69 |
%for i = 1:size(files,1) |
|
|
70 |
% fn = sprintf('%s/%s', 'segmented_nodules', char(files(i).name)); |
|
|
71 |
% fn2 = sprintf('%s/%s', 'segmented_background', char(files(i).name)); |
|
|
72 |
% info = dicominfo(fn); |
|
|
73 |
% info4 = dicominfo(fn2); |
|
|
74 |
% I = dicomread(info); |
|
|
75 |
% I4 = dicomread(info4); |
|
|
76 |
% BW = (I~=-2000); |
|
|
77 |
L = bwlabel(I3); |
|
|
78 |
a = L; |
|
|
79 |
flag = 0; |
|
|
80 |
if (nanmax(a(:)) > 1) |
|
|
81 |
flag = 1; |
|
|
82 |
end |
|
|
83 |
a(a~=0 & a~=1) = 0; |
|
|
84 |
STATS = regionprops (a,'Area', 'Extent', 'Perimeter', 'Centroid', 'ConvexArea', 'ConvexImage', 'Solidity', 'Eccentricity', 'MajorAxisLength', 'EquivDiameter', 'MinorAxisLength'); |
|
|
85 |
STATS.ConvexPerimeter = 2 * (sqrt(pi*STATS.ConvexArea)); |
|
|
86 |
STATS.Circularity = (4*pi*STATS.Area)/(STATS.ConvexPerimeter .^ 2); |
|
|
87 |
STATS.Elongation = STATS.MajorAxisLength/STATS.MinorAxisLength; |
|
|
88 |
% b = double(I); |
|
|
89 |
% b(b==-2000) = NaN; |
|
|
90 |
% b4 = double(I4); |
|
|
91 |
% b4(b4==-2000) = NaN; |
|
|
92 |
% STATS.MinIntensity = nanmin(b(:)); |
|
|
93 |
% STATS.MaxIntensity = nanmax(b(:)); |
|
|
94 |
% STATS.MeanIntensity = nanmean(b(:)); |
|
|
95 |
% STATS.SDIntensity = nanstd(b(:)); |
|
|
96 |
% STATS.MinIntensityBG = nanmin(b4(:)); |
|
|
97 |
% STATS.MaxIntensityBG = nanmax(b4(:)); |
|
|
98 |
% STATS.SDIntensityBG = nanstd(b4(:)); |
|
|
99 |
% STATS.MeanIntensityBG = nanmean(b4(:)); |
|
|
100 |
% STATS.IntensityDifference = abs(STATS.MeanIntensity - STATS.MeanIntensityBG); |
|
|
101 |
% fprintf(files(i).name,',',STATS(1).Area,',', STATS(1).Extent,',', STATS(1).Perimeter,'\n'); |
|
|
102 |
% count = count+1 |
|
|
103 |
% fn2 = sprintf('%s/%s', 'contours', char(files(i).name)); |
|
|
104 |
% info2 = dicominfo(fn2); |
|
|
105 |
% I2 = dicomread(info2); |
|
|
106 |
d = NaN; |
|
|
107 |
j = 0; |
|
|
108 |
for r = 1:size(I3,1) |
|
|
109 |
for c = 1:size(I3,2) |
|
|
110 |
if (I2(r,c) == 1) |
|
|
111 |
j = j + 1; |
|
|
112 |
d(j) = sqrt(double((c-(STATS.Centroid(1)^2))+(r-(STATS.Centroid(2)^2)))); |
|
|
113 |
end |
|
|
114 |
end |
|
|
115 |
end |
|
|
116 |
STATS.RadialDistanceSD = nanstd(d(:)); |
|
|
117 |
STATS.Perimeter = j; |
|
|
118 |
I3 = bwperim(STATS.ConvexImage); |
|
|
119 |
j = 0; |
|
|
120 |
for r = 1:size(I3,1) |
|
|
121 |
for c = 1:size(I3,2) |
|
|
122 |
if (I3(r,c) == 1) |
|
|
123 |
j = j + 1; |
|
|
124 |
end |
|
|
125 |
end |
|
|
126 |
end |
|
|
127 |
STATS.ConvexPerimeter = j; |
|
|
128 |
STATS.Roughness = STATS.ConvexPerimeter/STATS.Perimeter; |
|
|
129 |
STATS.Compactness = STATS.Perimeter^2/(4*pi*STATS.Area); |
|
|
130 |
if (flag == 0) |
|
|
131 |
fprintf(fid,'%s,%f,%f,%f,%f,%f,%f,%f,%f \n',files(i).name,STATS.Circularity,STATS.Roughness,STATS.Elongation,STATS.Compactness,STATS.Eccentricity,STATS.Solidity,STATS.Extent,STATS.RadialDistanceSD); |
|
|
132 |
else |
|
|
133 |
fprintf(fid2,'%s,%f,%f,%f,%f,%f,%f,%f,%f \n',files(i).name,STATS.Circularity,STATS.Roughness,STATS.Elongation,STATS.Compactness,STATS.Eccentricity,STATS.Solidity,STATS.Extent,STATS.RadialDistanceSD); |
|
|
134 |
end |
|
|
135 |
%end |
|
|
136 |
|
|
|
137 |
|
|
|
138 |
clear I; |
|
|
139 |
clear d; |
|
|
140 |
clear b; |
|
|
141 |
clear I3; |
|
|
142 |
end |
|
|
143 |
fclose(fid); |
|
|
144 |
fclose(fid2); |
|
|
145 |
%end |
|
|
146 |
|