-
Notifications
You must be signed in to change notification settings - Fork 4
/
Volume_discretization.m
47 lines (43 loc) · 1.76 KB
/
Volume_discretization.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
function [ROIonly,levels] = Volume_discretization(volume,mask,pixelW,sliceS,scale,bin)
% 1. Computation of the smallest box containing region of interest (ROI),
% if necessary (ROIbox).
% 2. Isotropic resampling.
% 3. Tumor discretization using equal bin width.
%
%Southern Medical University
%
% COMPUTATION OF THE SMALLEST BOX CONTAINING THE ROI
[boxBound] = computeBoundingBox(mask);
maskBox = mask(boxBound(1,1):boxBound(1,2),boxBound(2,1):boxBound(2,2),boxBound(3,1):boxBound(3,2));
ROIbox = volume(boxBound(1,1):boxBound(1,2),boxBound(2,1):boxBound(2,2),boxBound(3,1):boxBound(3,2));
% ISOTROPIC RESAMPLING
flagPW = 0;
if strcmp(scale,'pixelW')
flagPW = 1;
end
if flagPW
a = 1;
b = 1;
c = sliceS/pixelW;
else
a = pixelW/scale;
b = pixelW/scale;
c = sliceS/scale;
end
if numel(size(ROIbox))==3
if a + b + c ~= 3 % If false, no resampling is needed
maskBox = imresize3D(maskBox,[],[round(double(size(maskBox,1))*a),round(double(size(maskBox,2))*b),round(double(size(maskBox,3))*c)],'nearest','fill');
ROIbox = imresize3D(ROIbox,[],[round(double(size(ROIbox,1))*a),round(double(size(ROIbox,2))*b),round(double(size(ROIbox,3))*c)],'cubic','fill');
end
elseif numel(size(ROIbox))==2
if a + b ~= 2 % If false, no resampling is needed
maskBox = imresize(maskBox,[round(double(size(maskBox,1))*a),round(double(size(maskBox,2))*b)],'nearest');
ROIbox = imresize(ROIbox,[round(double(size(ROIbox,1))*a),round(double(size(ROIbox,2))*b)],'cubic','Antialiasing',true);
end
end
ROIonly = ROIbox; ROIonly(~maskBox) = NaN; ROIonly(maskBox<0) = NaN;
ROIonly(maskBox==0) = NaN;
% discretization method
[ROIonly,levels] = binWidthDiscretization(ROIonly,bin);
end