-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap_segmentation_demo_unpickle.py
49 lines (39 loc) · 2 KB
/
map_segmentation_demo_unpickle.py
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
import argparse
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm
from GridMapDecompose import map_handling as mh
import matplotlib as mpl
from mpl_toolkits.axes_grid1 import make_axes_locatable
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('img_file', help='Path to the map')
parser.add_argument('threshold_type', help='Threshold type')
args = parser.parse_args()
test_map = mh.GridMapHandling()
test_map = mh.load("test_map")
fig, ax = plt.subplots(nrows=1, ncols=3, sharex=True, sharey=True)
ax[0].imshow(test_map.labeled_map, cmap="nipy_spectral")
ax[0].axis('off')
ax[1].imshow(test_map.binary_map, cmap="nipy_spectral")
for local_segment, local_segment_type in zip(test_map.segments, test_map.segment_type):
if local_segment_type is 'w':
ax[1].plot(local_segment.minimal_bounding_box[:, 1], local_segment.minimal_bounding_box[:, 0], 'g')
if local_segment_type is 'f':
ax[1].plot(local_segment.minimal_bounding_box[:, 1], local_segment.minimal_bounding_box[:, 0], 'r')
ax[1].axis('off')
ax[2].imshow(test_map.binary_map, cmap="nipy_spectral")
for local_segment, local_segment_type in zip(test_map.segments, test_map.segment_type):
if local_segment_type is 'w':
ax[2].plot(local_segment.minimal_bounding_box[:, 1], local_segment.minimal_bounding_box[:, 0], 'g')
if local_segment_type is 'f':
ax[2].plot(local_segment.minimal_bounding_box[:, 1], local_segment.minimal_bounding_box[:, 0], 'r')
# quickly find edges
LU_adjacency_matrix = np.triu(test_map.adjacency_matrix_segments)
edges = np.column_stack(np.nonzero(LU_adjacency_matrix))
for edge in edges:
x = (test_map.segments[edge[0] - 1].center[1], test_map.segments[edge[1] - 1].center[1])
y = (test_map.segments[edge[0] - 1].center[0], test_map.segments[edge[1] - 1].center[0])
ax[2].plot(x, y, 'b')
ax[2].axis('off')
plt.show()