-
Notifications
You must be signed in to change notification settings - Fork 1
/
cascadeRandomForestMap.m
56 lines (41 loc) · 1.56 KB
/
cascadeRandomForestMap.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
function [maskVolume, maskPancreas] = cascadeRandomForestMap(data,pbs,limit)
% This function creates a probability mapping (using cascade random forest predictions)
% and a binary mask for every slice in a given image volume (3D array),
% and creates a binary volume to contain the main pancreas regions of interest.
% INPUTS:
% data - 3D array (matrix) containing image data;
% pbs - corresponding 3D array of probabilities (as predicted by cascade
% random forest);
% limit - minimum probability.
% OUTPUTS:
% maskVolume - 3D array containing the predicted major pancreas region of
% interest as a binary;
% maskPancreas - 3D array containing the predicted major pancreas region of
% interest;
% set default value
if (nargin < 3)
limit = 0;
end
% initialise binaryVolume
maskVolume = zeros(size(data));
maskPancreas = zeros(size(data));
for sliceN = 1:size(data,3) % sliceN represents slice number in data (3D array of image data)
% read slice of image data
slice_data = data(:,:,sliceN);
% read predicted probabilities for sliceN
slice_pbs = pbs(:,:,sliceN);
% create probability distribution for mask using limit
p_mask = slice_pbs >= limit;
slice_pbs(~p_mask) = 0;
% create binary mask for sliceN
mask = zeros(size(slice_data));
mask (slice_pbs >= limit) = 1;
mask = imfill(mask,'holes');
% mask out (set to 0) the region in the image slice
% that does not contain binary 1 (mask)
slice_data(~mask) = 0;
% add mask to maskVolume
maskVolume(:,:,sliceN) = mask;
maskPancreas(:,:,sliceN) = slice_data;
end
end