forked from TunaliIlke/RDRG-v2.1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extractRGRD.m
162 lines (134 loc) · 7.3 KB
/
extractRGRD.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
153
154
155
156
157
158
159
160
161
162
function [Feature_Values, Feature_Names] = extractRGRD(TmrMask,Im,Spacing,inter_size,maskLung)
% *************************************************************************
% function [Feature_Values, Feature_Names] = extractRGRD(TmrMask,Im,Spacing,inter_size,maskLung)
% *************************************************************************
%
% ABOUT:
% This function gives radial gradient and radial deviation radiomic
% features as an output.
%
% Please reference the below article if you use the features deriven by
% this code.
%
% REFERENCE:
%
% [1] Tunali et al. (2017). "Radial gradient and radial deviation radiomic
% features from pre-surgical CT scans are associated with survival among
% lung adenocarcinoma patients". Oncotarget, 8:96013-26.
% doi: https://doi.org/10.18632/oncotarget.21629
%
% INPUTS:
%
% TmrMask: Tumor Mask in binary format.
% Im: 3D medical image (int 16 format)
%
% TmrMask and Im should be the same size.
%
% Spacing: Pixel spacing and slice thickness of the image. (ex: pixel
% spacing = 0.8685 and slice thickness = 2.5000, Spacing = [0.8685 2.500].
% If the images are interpolated BEFORE, please put the interpolated spacing values.
%
% inter_size: If interpolation is wanted to be done to the image inter_size
% should indicate what the interpolated size of the image should be.
% (ex: for 1mm X 1mm x 2mm spacing inter_size = % [1 2])
% If interpolation is NOT needed put inter_size = -1.
%
% maskLung: Lung region mask in binary format. If lung mask is not
% available leave it blank.
%
%
% OUTPUT:
%
% Feature_Values: 48 RD/RG features extracted.
% Feature_Names: Names of the features extracted.
%
% Please read the readme.txt file for information on the usage of function.
%
% For questions: <[email protected]>
%
% HISTORY:
%
% Created: February 2017
% Version 2.1 (January 2018)
%
% --> Copyright (C) 2018 Ilke Tunali
% *************************************************************************
if ~isequal(size(Im),size(TmrMask))
error('Tumor Mask and Image should be the same size')
end
maskTmrAll = bwareaopen3D(TmrMask,8);
L = bwlabeln(maskTmrAll,26);
r1 = regionprops(L,'BoundingBox');
roundR1 = round(r1(1).BoundingBox);
range = [max([roundR1(3)-1 1]), min([roundR1(3)+roundR1(6), size(L,3)])];
maskTmr = maskTmrAll(:,:,range(1):range(2));
if exist('maskLung')
maskLung = maskLung(:,:,range(1):range(2));
end
Im = Im(:,:,range(1):range(2));
r = regionprops(maskTmr,'centroid');
cent = [round(r.Centroid)];
sss = 75;
VOI = Im(max([cent(2)-sss,1]):min([512,cent(2)+sss]),max([1, cent(1)-sss]):min([cent(1)+sss,512]),:);
maskTmr = maskTmr(max([cent(2)-sss,1]):min([512,cent(2)+sss]),max([1, cent(1)-sss]):min([cent(1)+sss,512]),:);
VOI(VOI>=1024 ) = 1024;
VOI(VOI<=-1024) = -1024;
VOI = VOI./12;
[maskTmr,slices] = edit_slices(maskTmr);
foo = maskTmr(:,:,cent(3));
p = regionprops (foo,'MajorAxisLength');
pxSpac = Spacing(1);
maxDia = round(max([p.MajorAxisLength]).*pxSpac(1));
if isempty(maxDia)
maxDia = 0;
end
[sEs1,sEs2] = find_str_elem(maxDia,pxSpac(1));
sz = size(maskTmr);
if exist('maskLung')
LungMask = maskLung; t = 1;
LungMask = LungMask(max([cent(2)-sss,1]):min([512,cent(2)+sss]),max([1, cent(1)-sss]):min([cent(1)+sss,512]),:);
else
LungMask = ones(sz); t = 0;
end
maskOutside2 = outside_border(maskTmr,ones(sz),sEs2,1);
[maskBorder,maskErode] = outside_border2(maskTmr,LungMask,sEs1,t);
slices = editSliceNum(slices);
maskOutside2 = edit_slices2(maskOutside2,slices);
maskBorder = edit_slices2(maskBorder,slices);
maskErode = edit_slices2(maskErode,slices);
maskTmr = edit_slices2(maskTmr ,slices);
if inter_size ~= -1
ratio = inter_size(1)/(pxSpac(1));
ratio2 = inter_size(2)/Spacing(3);
VOI = interp3dim(VOI, round(size(VOI,1)/ratio),round(size(VOI,2)/ratio),round(size(VOI,3)/ratio2));
maskBorder = interp3dim(maskBorder, round(size(maskBorder,1)/ratio),round(size(maskBorder,2)/ratio),round(size(maskBorder,3)/ratio2))>0.20;
maskErode = interp3dim(maskErode, round(size(maskErode,1)/ratio),round(size(maskErode,2)/ratio),round(size(maskErode,3)/ratio2))>0.20;
maskTmr = interp3dim(maskTmr, round(size(maskTmr,1)/ratio),round(size(maskTmr,2)/ratio),round(size(maskTmr,3)/ratio2))>0.20;
maskOutside2 = interp3dim(maskOutside2, round(size(maskOutside2,1)/ratio),round(size(maskOutside2,2)/ratio),round(size(maskOutside2,3)/ratio2))>0.20;
end
r = regionprops(maskTmr,'centroid');
cent = round(r.Centroid);
r = regionprops(maskTmr(:,:,cent(3)),'Area');
mx_area = max([r.Area]);
if maskTmr(:,:,cent(3)) == 0
r = regionprops(maskTmr,'centroid');
cent2 = round(r.Centroid);
else
r = regionprops(bwareaopen(maskTmr(:,:,cent(3)),mx_area),'centroid');
cent2 = round(r.Centroid);
cent2(3) = cent(3);
end
if inter_size == -1
[RadGra, RadDev] = find_rad_dev_gra(VOI,cent2,Spacing);
else
[RadGra, RadDev] = find_rad_dev_gra(VOI,cent2,[inter_size(1) inter_size(2)]);
end
featuresTmr = feature_extraction(maskTmr,RadGra,RadDev,cent2);
featuresErode = feature_extraction(maskErode,RadGra,RadDev,cent2);
featuresOutside2 = feature_extraction(maskOutside2,RadGra,RadDev,cent2);
featuresBorder = feature_extraction(maskBorder,RadGra,RadDev,cent2);
Feature_Values = [featuresTmr featuresErode featuresBorder featuresOutside2...
(featuresOutside2-featuresTmr)./(featuresOutside2+featuresTmr)...
(featuresOutside2-featuresBorder)./(featuresOutside2+featuresBorder) ...
];
Feature_Names = {'radial deviation tumor mean' 'radial deviation tumor SD' 'radial gradient tumor mean' 'radial gradient tumor SD' 'radial deviation tumor mean (2D)' 'radial deviation tumor SD (2D)' 'radial gradient tumor mean (2D)' 'radial gradient tumor SD (2D)' 'radial deviation core mean' 'radial deviation core SD' 'radial gradient core mean' 'radial gradient core SD' 'radial deviation core mean (2D)' 'radial deviation core SD (2D)' 'radial gradient core mean (2D)' 'radial gradient core SD (2D)' 'radial deviation border mean' 'radial deviation border SD' 'radial gradient border mean' 'radial gradient border SD' 'radial deviation border mean (2D)' 'radial deviation border SD (2D)' 'radial gradient border mean (2D)' 'radial gradient border SD (2D)' 'radial deviation outside mean' 'radial deviation outside SD' 'radial gradient outside mean' 'radial gradient outside SD' 'radial deviation outside mean (2D)' 'radial deviation outside SD (2D)' 'radial gradient outside mean (2D)' 'radial gradient outside SD (2D)' 'radial deviation outside-tumor seperation mean' 'radial deviation outside-tumor seperation SD' 'radial gradient outside-tumor seperation mean' 'radial gradient outside-tumor seperation SD' 'radial deviation outside-tumor seperation mean (2D)' 'radial deviation outside-tumor seperation SD (2D)' 'radial gradient outside-tumor seperation mean (2D)' 'radial gradient outside-tumor seperation SD (2D)' 'radial deviation outside-border seperation mean' 'radial deviation outside-border seperation SD' 'radial gradient outside-border seperation mean' 'radial gradient outside-border seperation SD' 'radial deviation outside-border seperation mean (2D)' 'radial deviation outside-border seperation SD (2D)' 'radial gradient outside-border seperation mean (2D)' 'radial gradient outside-border seperation SD (2D)' };