-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrigId2ImgId.m
More file actions
31 lines (24 loc) · 815 Bytes
/
Copy pathtrigId2ImgId.m
File metadata and controls
31 lines (24 loc) · 815 Bytes
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
function [imgId,isTarget] = trigId2ImgId(trigId)
% Inverse of getTrigId: maps trigId -> imgId and isTarget
% Check inputs
if ~isnumeric(trigId)
error('Bad inputs');
end
% Cast to cell array
trigId = num2cell(trigId);
% Convert to binary strings (8 bits total: 1 + 4 + 3)
trigBin = cellfun(@(ii){dec2bin(ii,8)},trigId);
% Extract parts
isTargetStr = cellfun(@(s){s(1)},trigBin);
catIdStr = cellfun(@(s){s(2:5)},trigBin);
imgNumStr = cellfun(@(s){s(6:8)},trigBin);
% Convert back to numeric values
isTarget = cellfun(@(s){str2double(s)},isTargetStr);
catId = cellfun(@(s){bin2dec(s)},catIdStr);
imgNum = cellfun(@(s){bin2dec(s)},imgNumStr);
% Combine to form imgId
imgId = cellfun(@(c,n){6*c + n+1},catId,imgNum);
% Unwrap from cells
imgId = cell2mat(imgId);
isTarget = cell2mat(isTarget);
return