-
Notifications
You must be signed in to change notification settings - Fork 8
/
mlrfsSegment.m
47 lines (37 loc) · 1.31 KB
/
mlrfsSegment.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
% Multi-Layer Random Forest Segmentation: Segment
clear, clc
%% load image, model
Image = imread('~/Desktop/MLRFS/Test/I01.tif');
Label = imread('~/Desktop/MLRFS/Test/L01.tif'); % for comparison with rf segmentation output
rfModelFilePath = '/home/mc457/Desktop/MLRFS/Model/rfModel.mat';
disp('loading rfModel')
tic
load(rfModelFilePath); % loads rfModel
toc
%% segmentation
I0 = Image;
I = double(imresize(I0,rfModel.resizeFactor));
I = I/max(max(I));
% layer 1
F = imageFeatures(I,rfModel.sigmas);
fprintf('rf layer 1...'); tic
[imL,classProbs] = imclassify(F,rfModel.treeBags{1});
fprintf('time: %f s\n', toc);
% remaining layers
F = cat(3,F,repmat(zeros(size(I)),[1 1 rfModel.nLabels+rfModel.nProbMapsFeats]));
for layer = 2:rfModel.nLayers
F(:,:,rfModel.nImageFeatures+1:rfModel.nImageFeatures+rfModel.nLabels) = classProbs;
F(:,:,rfModel.nImageFeatures+rfModel.nLabels+1:end) = offsetFeatures(classProbs,rfModel.offsets);
fprintf('rf layer %d...',layer); tic
[imL,classProbs] = imclassify(F,rfModel.treeBags{layer});
fprintf('time: %f s\n', toc);
end
%% display
L = imresize(imL,1/rfModel.resizeFactor,'nearest');
figureQSS
subplot(1,3,1)
imshow(I0), title('image')
subplot(1,3,2)
imshow(label2rgb(L)), title('rf segmentation output')
subplot(1,3,3)
imshow(label2rgb(Label)), title('ground truth')