-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplotSegmentation.m
More file actions
55 lines (41 loc) · 1.18 KB
/
plotSegmentation.m
File metadata and controls
55 lines (41 loc) · 1.18 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function rendered = plotSegmentation(im, pred, gt)
% Plot a 2D segmentation with the image, prediction and ground truth masks
% Parameters
gtColor = [5 231 252] / 255;
predColor = [252 41 22] / 255;
% Convert the image to RGB
imColor = zeros([size(im) 3]);
for c = 1 : size(imColor, 3)
imColor(:, :, c) = im;
end
% Add in the masks
rendered = addBorderOverlay(imColor, gt, gtColor);
rendered = addBorderOverlay(rendered, pred, predColor);
% Plot
imshow(rendered)
end
function overlaid = addBorderOverlay(im, mask, maskColor)
% Like addOverlay, but opaque border
% Avoid NaNs if empty
if ~any(mask(:))
overlaid = im;
return
end
opacity = 0.9;
aaSigma = 1.25;
% Get the border
maskBorder = bwperim(mask);
% Apply anti-aliasing and opacity
maskAA = imgaussfilt(single(maskBorder), aaSigma);
maskOpacity = maskAA * opacity / max(maskAA(:));
overlaid = addOverlay(im, maskOpacity, maskColor);
end
function overlaid = addOverlay(im, mask, maskColor)
% Uses a mask with opacity in [0, 1]
% Apply the blend
overlaid = zeros(size(im));
for c = 1 : size(im, 3)
imChannel = im(:, :, c);
overlaid(:, :, c) = imChannel .* (1 - mask) + mask * maskColor(c);
end
end