rtsEnviRandomForest2C_apply.m
1.05 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
function P = rtsEnviRandomForest2C_apply(RF, EnviFileName, EnviHeaderName, TissueMask, reference)
%Applies a 2-class random forest classifier to the given image. Only
%pixels specified in TissueMask are classified. The estimated rule data is
%returned as an image sequence.
%load the tissue mask
maskImage = imread(TissueMask);
maskBinary = (maskImage(:, :, 1) > 0)';
nPixels = nnz(maskBinary);
disp(['Number of pixels: ' num2str(nPixels)]);
%load the data
disp(['Loading Features: ' EnviFileName]);
tLoadTime = tic;
fid = rtsEnviOpen(EnviFileName, EnviHeaderName, maskBinary);
F = rtsEnviRead(fid, nPixels);
rtsEnviClose(fid);
disp(['Time: ' num2str(toc(tLoadTime)) 's']);
%transpose
F = F';
%apply the reference
if nargin == 5
Fnorm = repmat(F(:, reference), 1, size(F, 2));
F = F./Fnorm;
F(:, reference) = [];
end
%classify the data
disp('Classifying...');
tClassTime = tic;
T = predict(RF, F);
disp(['Time: ' num2str(toc(tClassTime)) 's']);
%Cl = Cpost > threshold;
%reconstruct the image from the mask
P = rtsMaskReconstruct(T', maskBinary, -1);