forked from YiduoWang47/do-slam
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateImageObject.m
More file actions
96 lines (89 loc) · 3.19 KB
/
Copy pathcreateImageObject.m
File metadata and controls
96 lines (89 loc) · 3.19 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
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
95
96
function image = createImageObject(segmentationFile,detectionFile,i,imageList,assignObjectID)
I = imread(strcat('/home/mina/Downloads/vKitti/vkitti_1.3.1_scenegt/0001/clone/00',...
num2str(imageList(i)),'.png'));
rgbImage = imread(strcat('/home/mina/Downloads/vKitti/rgbImages/00',...
num2str(imageList(i)),'.png'));
image.I = rgbImage;
depthImage = imread(strcat('/home/mina/Downloads/vKitti/depthImages/00',...
num2str(imageList(i)),'.png'));
image.depth = depthImage;
for j=1:size(I,1)
for k=1:size(I,2)
if j==1 && k==1
%first pixel
image.nObjects = 1;
image.objects(1).rgb = [I(j,k,1),I(j,k,2),I(j,k,3)];
if assignObjectID
image.objects(1).id = 1;
image.uniqueID = 1;
end
image.uniqueRGB = [I(j,k,1),I(j,k,2),I(j,k,3)];
else
%every other pixel
rgb = [I(j,k,1),I(j,k,2),I(j,k,3)];
if ~ismember(rgb,image.uniqueRGB,'rows')
%increase nObjects
image.nObjects = image.nObjects+1;
%assign object rgb & id
image.objects(image.nObjects).rgb = rgb;
if assignObjectID
image.objects(image.nObjects).id = max([image.objects.id])+1;
% add id to uniqueID
image.uniqueID = [image.uniqueID;image.objects(image.nObjects).id];
end
% add rgb to uniqueRGB
image.uniqueRGB = [image.uniqueRGB;rgb];
end
end
end
end
for y=1:image.nObjects
objectRGB = image.uniqueRGB(y,:);
objectMask = I(:,:,1)==objectRGB(1) & I(:,:,2)==objectRGB(2) &...
I(:,:,3)==objectRGB(3);
%store object mask
image.objects(y).mask = objectMask;
%store object centroids
objectCentroid = getObjectCentroid(objectMask);
image.objects(y).centroid = objectCentroid;
%store object classes
[objectClass, objectClassGT] = getObjectClass(segmentationFile, objectRGB);
image.objects(y).class = objectClass;
image.objects(y).classGT = objectClassGT;
end
nDeleted = 0;
for y=1:image.nObjects
switch image.objects(y-nDeleted).class
case{'Sky','Pole','Tree','Building','Vegetation','TrafficLight',...
'TrafficSign','Terrain','Road','Misc'}
image.objects(y-nDeleted) = [];
image.uniqueRGB(y-nDeleted,:) = [];
if assignObjectID
image.uniqueID(y-nDeleted,:) = [];
end
nDeleted = nDeleted + 1;
end
end
image.nObjects = length(image.objects);
for y=1:image.nObjects
%store object bounding box
objectBoundingBox = getObjectBoundingBox(detectionFile,imageList(i),...
image.objects(y).classGT);
image.objects(y).boundingBox = objectBoundingBox;
if ~assignObjectID
image.uniqueID = [];
end
end
nDeleted = 0;
for y=1:image.nObjects
if isempty(image.objects(y-nDeleted).boundingBox)
image.objects(y-nDeleted) = [];
image.uniqueRGB(y-nDeleted,:) = [];
if assignObjectID
image.uniqueID(y-nDeleted,:) = [];
end
nDeleted = nDeleted + 1;
end
end
image.nObjects = length(image.objects);
end