-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathGenPartMask.m
More file actions
executable file
·67 lines (53 loc) · 1.96 KB
/
GenPartMask.m
File metadata and controls
executable file
·67 lines (53 loc) · 1.96 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
56
57
58
59
60
61
62
63
64
65
66
67
function [partsMask, instbox, varargout] = GenPartMask(anno, img, pimap, objID_all, mappings)
% instbox: l top, left, down , right
[cls_mask, inst_mask, part_mask] = mat2map(anno, img, pimap);
class = unique(cls_mask(:));
[~,~,id] = intersect(class, objID_all, 'stable'); % object id exist in the image
if isempty(id); partsMask = zeros(size(part_mask),'single');
partsMask = [];
instbox = [];
return;
end
cls_mask = Map2ID(cls_mask, objID_all, id);
partsMask = Mappnig2JointLabel(cls_mask, part_mask, mappings); % map cls mask find the part slots and put the label in
inst_mask(cls_mask == 0) = 0;
instbox = GetInstBox(inst_mask);
if nargin > 2
varargout{1} = cls_mask;
varargout{2} = inst_mask;
end
end
function cls_mask2 = Map2ID(cls_mask, objID, id)
cls_mask2 = zeros(size(cls_mask), 'uint8');
for iclass = id'
cls_mask2(cls_mask == objID(iclass)) = iclass; % turn the cls map into current lable sets
end
end
function partMask = Mappnig2JointLabel(cls_mask, part_mask, mappings)
clsID = unique(cls_mask); clsID(clsID == 0) = [];
partMask = zeros(size(cls_mask), 'uint8');
for icls = 1:length(clsID)
cls_id = clsID(icls);
obj_mask = cls_mask == cls_id ;
partMap = zeros(size(obj_mask), 'uint8') ;
partMap(obj_mask) = part_mask(obj_mask);
partID = unique(part_mask(obj_mask)); partID(partID == 0) = [];
if (sum(partID > length(mappings(cls_id).pid)) > 0)
partID(partID > length(mappings(cls_id).pid)) = [];
end
for ipart = 1:length(partID);
prt_id = partID(ipart);
partMask(partMap == prt_id) = mappings(cls_id).pid(prt_id);
end
end
end
function instbox = GetInstBox(inst_mask);
inst = unique(inst_mask);
inst(inst == 0) = [];
instnum = max(inst);
instbox = zeros(instnum, 4);
for iinst = 1:length(inst)
mask = inst_mask == inst(iinst);
instbox(iinst, :) = region2box(mask);
end
end