-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubplot_auto_transparent.m
94 lines (81 loc) · 2.7 KB
/
subplot_auto_transparent.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
% Copyright (C) 2010 Joao Carreira
%
% This code is part of the extended implementation of the paper:
%
% J. Carreira, C. Sminchisescu, Constrained Parametric Min-Cuts for Automatic Object Segmentation, IEEE CVPR 2010
%
%function h = subplot_auto_transparent(segments, I, titles)
function [Imgs] = subplot_auto_transparent(segments, I, titles, voc_cmap_ids, grid_type)
segments(segments==inf) = 10000;
border_side = 0.05;
border_top = 0.1;
if(length(size(I))==2)
I = repmat(I, [1 1 3]);
end
if(issparse(segments))
segments = full(segments);
end
if(size(segments,1) ~= size(I,1))
n_imgs = size(segments,2);
else
n_imgs = size(segments,3);
segments = reshape(segments, size(segments,1) * size(segments,2), n_imgs);
end
n_rows = round(sqrt(n_imgs));
n_cols = ceil(n_imgs/n_rows);
assert(n_cols*n_rows >= n_imgs);
counter = 1;
if(exist('voc_cmap_ids', 'var') && ~isempty(voc_cmap_ids))
cmap = VOClabelcolormap();
assert(size(segments,2) == numel(voc_cmap_ids));
for i=1:size(segments,2)
bground{i} = zeros(size(I,1),size(I,2),3);
bground{i}(:,:,1) = cmap(voc_cmap_ids(i),1);
bground{i}(:,:,2) = cmap(voc_cmap_ids(i),2);
bground{i}(:,:,3) = cmap(voc_cmap_ids(i),3);
bground{i} = uint8(255*bground{i});
end
else
bground = zeros(size(I,1),size(I,2),3);
bground(:,:,2) = 255;
end
Imgs = cell(n_imgs,1);
for i=1:n_imgs
if(size(segments,1) ~= size(I,1))
alpha_chann = reshape(segments(:,i), size(I,1), size(I,2))*0.5;
else
alpha_chann = segments(:,:,i)*0.5;
end
%sc(sc(I).*sc(alpha_chann))
if(exist('voc_cmap_ids', 'var') && ~isempty(voc_cmap_ids))
Imgs{i} = immerge(I, bground{i}, alpha_chann);
else
Imgs{i} = immerge(I, bground, alpha_chann);
end
counter = counter + 1;
end
%montage_new(Imgs, titles, 'Size', [n_rows n_cols], 'Border', 0.1);
if(~exist('grid_type', 'var'))
grid_type = [];
end
if(exist('titles', 'var') && ~isempty(titles))
if(~iscell(titles)) % if not a cell assumes they're numbers
for i=1:length(titles)
new_titles{i} = sprintf('%f', titles(i));
end
titles = new_titles;
end
if(~exist('grid_type', 'var'))
montage_new(Imgs, titles, 'Border', [border_top border_side]);
else
montage_new(Imgs, titles, 'Border', [border_top border_side], 'Size', grid_type);
end
else
montage_new(Imgs, [], 'Border', [border_top border_side], 'Size', grid_type);
end
% hold on;
% for i=1:n_imgs
% if(nargin==3)
% h(counter) = subplot(n_rows,n_cols,i); title(titles{i});
% end
% end