-
Notifications
You must be signed in to change notification settings - Fork 11
/
demo.m
57 lines (45 loc) · 1.34 KB
/
demo.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
57
clc; clear; close all;
addpath('src/');
% parameter setting
fullcrfPara.uw = 1;
fullcrfPara.sw = 8;
fullcrfPara.bw = 9;
fullcrfPara.s = 5;
fullcrfPara.bl = 31;
fullcrfPara.bc = 15;
numlabels = 14;
% Load unary (textonboost)
[textonboost, L_t] = loadTextonboost('test.unary', numlabels);
% Load colorimg
img = imread('test.png');
% convert matlab index to c++ index
u = -1*textonboost;
u = reshape(u, size(img, 1), size(img, 2), numlabels);
u = permute(u, [2 1 3]);
u = reshape(u, size(img, 1)*size(img, 2), numlabels);
u = u'*fullcrfPara.uw;
tmpImg = reshape(img, [], 3);
tmpImg = tmpImg';
tmpImg = reshape(tmpImg, 3, size(img, 1), size(img, 2));
tmpImg = permute(tmpImg, [1 3 2]);
% Do the hard work
tic;
%note: the weight of the unary should be set outside the function
%{
@params
unary (num_labels*num_pixels)
img (channel * width * height)
...
@output:
map (0 - num_label-1)
probability
%}
[L, prob] = fullCRFinfer(single(u), uint8(tmpImg), fullcrfPara.s, fullcrfPara.s, ...
fullcrfPara.sw, fullcrfPara.bl, fullcrfPara.bl, fullcrfPara.bc, fullcrfPara.bc, ...
fullcrfPara.bc, fullcrfPara.bw, size(img, 2), size(img, 1));
toc;
map = (reshape(L, size(img, 2), size(img, 1)))';
p = reshape(prob, numlabels, size(img, 2), size(img, 1));
p = permute(p, [3 2 1]);
figure; imagesc(map);truesize;colormap jet;
figure; imshow(img);