-
Notifications
You must be signed in to change notification settings - Fork 0
/
readCMSOJSON.m
79 lines (67 loc) · 2.33 KB
/
readCMSOJSON.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
function [objects, links, tracks] = readCMSOJSON(filePath, fileName)
%Read the CMSOJSON file and find the indices of the columns in Objects and
%Links csv files.
jsonTxt = fileread([filePath fileName]);
CMSOjson = jsondecode(jsonTxt);
%Find the index of 'objects' and 'links'
numRes = numel(CMSOjson.resources);
tracksTableIdx = [];
for thisRes = 1:numRes
thisColName = CMSOjson.resources(thisRes).name;
if contains(thisColName, 'objects')
objectsTableIdx = thisRes;
objects.fileName = CMSOjson.resources(thisRes).path;
end
if contains(thisColName, 'links')
linksTableIdx = thisRes;
links.fileName = CMSOjson.resources(thisRes).path;
end
if contains(thisColName, 'tracks')
tracksTableIdx = thisRes;
tracks.fileName = CMSOjson.resources(thisRes).path;
end
end
%Find the column indices of the 'objects' table
numCols = numel(CMSOjson.resources(objectsTableIdx).schema.fields);
for thisCol = 1:numCols
thisColName = CMSOjson.resources(objectsTableIdx).schema.fields{thisCol}.name;
if contains(thisColName, 'object')
objects.objectIdIdx = thisCol;
end
if contains(thisColName, 'frame')
objects.frameIdIdx = thisCol;
end
if contains(thisColName, 'x_coord')
objects.xCoordIdx = thisCol;
end
if contains(thisColName, 'y_coord')
objects.yCoordIdx = thisCol;
end
end
%Find the column indices of the 'links' table
numCols = numel(CMSOjson.resources(linksTableIdx).schema.fields);
for thisCol = 1:numCols
thisColName = CMSOjson.resources(linksTableIdx).schema.fields(thisCol).name;
if contains(thisColName, 'link')
links.linkIdIdx = thisCol;
end
if contains(thisColName, 'object')
links.objectIdIdx = thisCol;
end
end
%Is there a tracks.csv?
if ~isempty(tracksTableIdx)
%Find the column indices of the 'tracks' table
numCols = numel(CMSOjson.resources(tracksTableIdx).schema.fields);
for thisCol = 1:numCols
thisColName = CMSOjson.resources(tracksTableIdx).schema.fields(thisCol).name;
if contains(thisColName, 'track')
tracks.trackIdIdx = thisCol;
end
if contains(thisColName, 'link')
tracks.linkIdIdx = thisCol;
end
end
else
tracks = [];
end