rtsEnviRandomForest2C_apply.m 1.05 KB
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);