5 import matplotlib.patches
as patches
6 import matplotlib.pyplot
as plt
9 import scipy.stats
as stats
10 import skimage.draw
as sk_draw
11 from scipy
import ndimage
12 from scipy.signal
import find_peaks
13 from skimage.filters
import threshold_yen
14 from skimage.segmentation
import flood_fill
15 from skimage.morphology
import binary_dilation
16 from sklearn
import mixture
17 from sklearn.cluster
import DBSCAN
18 from sklearn.neighbors
import KernelDensity
20 import rose_v1_repo.segment_handling
as sh
21 import rose_v1_repo.helpers
as he
26 slices_lines.append([s[0][0][0], s[1][0][0], s[0][0][-1], s[1][0][-1]])
31 with open(name,
"wb")
as out:
32 png_writer = png.Writer(shape[1], shape[0], greyscale=
True, alpha=
False, bitdepth=1)
33 img = map_to_save[:shape[0], :shape[1]]
34 png_writer.write(out, img)
38 def __init__(self, grid_map, ang_tr=0.1, amp_tr=0.8, peak_height=0.5, par=200, smooth=False, sigma=3):
109 rospy.loginfo(
"[ROSE] Load Map.....")
111 if len(grid_map.shape) == 3:
112 grid_map = grid_map[:, :, 1]
113 thresh = threshold_yen(grid_map)
126 square_map = np.zeros((np.max(self.
binary_map.shape), np.max(self.
binary_map.shape)), dtype=bool)
130 rospy.loginfo(
"[ROSE] OK ({0:.2f})".format(time.time() - ti))
133 rospy.loginfo(
"[ROSE] Compute FFT.....")
140 rospy.loginfo(
"[ROSE] OK ({0:.2f})".format(time.time() - t))
142 def generate_mask(self, x1_1, y1_1, x2_1, y2_1, x1_2, y1_2, x2_2, y2_2, y_org):
147 if np.abs(y_org) > 3 * np.max(self.
binary_map.shape):
150 r_1 = np.array([x1_1, x2_1, 0, 0])
151 rr, cc = he.generate_mask(r_1, c_1, self.
norm_ft_image.shape)
153 mask_1 = np.flipud(mask_1)
156 c_2 = np.array([y1_2, y2_2, 0, 0])
158 if np.abs(y_org) > 3 * np.max(self.
binary_map.shape):
162 rr, cc = he.generate_mask(r_2, c_2, self.
norm_ft_image.shape)
164 mask_2 = np.flipud(mask_2)
166 mask_l = np.logical_and(mask_1, mask_2)
172 rospy.loginfo(
"[ROSE] Find Dominant directions.....")
175 pol_l = self.
pol.shape[1]
176 self.
pol = np.concatenate((self.
pol, self.
pol[:, 1:], self.
pol[:, 1:]), axis=1)
177 self.
angles = np.concatenate(
179 np.max(self.
angles))), axis=0)
183 self.
pol = ndimage.gaussian_filter1d(self.
pol, self.
sigma)
185 self.
pol_h = np.array([sum(x)
for x
in zip(*self.
pol)])
190 self.
pol = self.
pol[:, 0:pol_l]
203 if np.abs(np.pi - he.ang_dist(a, b)) < self.
ang_tr:
204 pairs.append([aind, bind])
207 pairs = np.array(pairs)
208 pairs = np.unique(np.sort(pairs), axis=0)
215 if np.abs(a - b) / amp < self.
amp_tr:
217 rospy.loginfo(
"[ROSE] OK ({0:.2f})".format(time.time() - t))
218 rospy.loginfo(
"[ROSE] Found directions.....{}".format(len(self.
comp)))
225 p0 = p0 % (2 * np.pi)
226 p1 = p1 % (2 * np.pi)
231 rospy.loginfo(
"[ROSE] Score map.....")
233 if not self.
comp or len(self.
comp) == 1:
249 x1, y1 = he.pol2cart(diag, self.
angles[p[0]] + np.pi / 2.0)
250 x2, y2 = he.pol2cart(diag, self.
angles[p[1]] + np.pi / 2.0)
266 Y1_l = (c - a * X1_l) / b
268 Y2_l = (c - a * X2_l) / b
271 Y1 = (c - a * X1) / b
273 Y2 = (c - a * X2) / b
276 Y1_1 = (c1 - a * X1_1) / b
278 Y2_1 = (c1 - a * X2_1) / b
281 Y1_2 = (c2 - a * X1_2) / b
283 Y2_2 = (c2 - a * X2_2) / b
288 if np.abs(Y_org) > 3 * np.max(self.
binary_map.shape):
291 X1_l = (c - b * Y1_l) / a
293 X2_l = (c - b * Y2_l) / a
296 X1 = (c - b * Y1) / a
298 X2 = (c - b * Y2) / a
301 X1_1 = (c1 - b * Y1_1) / a
303 X2_1 = (c1 - b * Y2_1) / a
306 X1_2 = (c2 - b * Y1_2) / a
308 X2_2 = (c2 - b * Y2_2) / a
310 if max(X1_l, X2_l) < max(Y1_l, Y2_l):
316 self.
lines.append([X1, Y1, X2, Y2])
318 mask_l = self.
generate_mask(X1_1, Y1_1, X2_1, Y2_1, X1_2, Y1_2, X2_2, Y2_2, Y_org)
320 if not np.any(mask_l == 1):
321 mask_l = self.
generate_mask(X1_2, Y1_2, X2_2, Y2_2, X1_1, Y1_1, X2_1, Y2_1, Y_org)
324 l_mask_ftimage = self.
ft_image * mask_l
325 l_mask_iftimage = np.fft.ifft2(l_mask_ftimage)
327 l_map_scored_good = np.abs(l_mask_iftimage) * (self.
binary_map * 1)
330 mask_all = np.logical_or(mask_all, mask_l)
331 mask_ftimage_l = self.
ft_image * mask_l
332 mask_iftimage_l = np.fft.ifft2(mask_ftimage_l)
333 sm_l = np.abs(mask_iftimage_l) * (self.
binary_map * 1)
334 sm_l = sm_l / np.max(sm_l)
336 mask_all = np.flipud(mask_all)
337 mask_all_inv = np.ones(mask_all.shape)
338 mask_all_inv[mask_all == 1] = 0
339 rospy.loginfo(
"[ROSE] OK ({0:.2f})".format(time.time() - t))
360 rospy.loginfo(
"[ROSE] Simple filter map.....")
366 rospy.loginfo(
"[ROSE] OK ({0:.2f})".format(time.time() - t))
369 rospy.loginfo(
"[ROSE] Histogram filter map.....")
373 clf = mixture.GaussianMixture(n_components=2)
374 clf.fit(pixels.ravel().reshape(-1, 1))
375 self.
pixel_quality_gmm = {
"means": clf.means_,
"weights": clf.weights_,
"covariances": clf.covariances_}
377 bins, edges = np.histogram(pixels.ravel(), density=
True)
379 "centers": [(a + b) / 2
for a, b
in zip(edges[:-1], edges[1:])],
380 "width": [(a - b)
for a, b
in zip(edges[:-1], edges[1:])]}
400 ind = np.argmax(y_g > y_b)
405 rospy.loginfo(
"[ROSE] OK ({0:.2f})".format(time.time() - t))
413 lines_hypothesis = []
415 kde_hypothesis_cut = []
420 for s
in np.arange(-1 * max_len, max_len, 1):
422 rr, cc = sk_draw.line(int(round(l[0] + s)), int(round(l[3])), int(round(l[2] + s)),
425 rr, cc = sk_draw.line(int(round(l[0])), int(round(l[3] + s)), int(round(l[2])),
426 int(round(l[1] + s)))
429 rospy.loginfo(
"[ROSE] ERROR")
431 rr_flag = (np.logical_or(rr < 0, rr >= self.
analysed_map.shape[1]))
432 cc_flag = (np.logical_or(cc < 0, cc >= self.
analysed_map.shape[0]))
433 flag = np.logical_not(np.logical_or(rr_flag, cc_flag))
435 if np.sum(self.
analysed_map[cc[flag], rr[flag]] * 1) > 1:
439 t_row = np.ones(row.shape) - row
440 d_row = ndimage.distance_transform_cdt(t_row)
441 d_row = max_len - d_row
442 d_row = d_row.reshape(-1, 1)
444 d_row_ret.append(d_row)
445 kde = KernelDensity(kernel=
'gaussian', bandwidth=bandwidth).fit(d_row)
447 temp_row_full = np.exp(kde.score_samples(d_row))
448 temp_row_cut = temp_row_full.copy()
449 temp_row_cut[temp_row_full < cutoff_percent * min(np.exp(kde.score_samples(d_row)))] = 0
453 for i, t
in enumerate(temp_row_cut):
454 if t == 0
and pt == 0:
456 elif pt == 0
and t != 0:
460 elif pt != 0
and t != 0:
463 elif t == 0
and pt != 0:
464 l_slice_ids.append(ts)
474 for tslice
in l_slice_ids:
475 if len(tslice) > cell_tr:
481 cc_slices.append(cc_s)
482 rr_slices.append(rr_s)
484 temp_slice.append((cc_slices, rr_slices))
486 slices_ids.append((cc_slices, rr_slices))
488 slices.append((cc_slices, rr_slices))
491 cell_hypothesis.append((cc[flag], rr[flag]))
493 lines_hypothesis.append([l[0] + s, l[1], l[2] + s, l[3]])
495 lines_hypothesis.append([l[0], l[1] + s, l[2], l[3] + s])
497 rospy.loginfo(
"[ROSE] ERROR")
498 kde_hypothesis.append(temp_row_full)
499 kde_hypothesis_cut.append(temp_row_cut)
502 slices_dir.append(temp_slice)
503 return d_row_ret, slices_ids, slices, cell_hypothesis, lines_hypothesis, kde_hypothesis, kde_hypothesis_cut, slices_dir
510 lines_hypothesis = []
512 kde_hypothesis_cut = []
517 for s
in np.arange(-1 * max_len, max_len, 1):
519 rr, cc = sk_draw.line(int(round(l[0] + s)), int(round(l[3])), int(round(l[2] + s)),
522 rr, cc = sk_draw.line(int(round(l[0])), int(round(l[3] + s)), int(round(l[2])),
523 int(round(l[1] + s)))
526 rospy.loginfo(
"[ROSE] ERROR")
528 rr_flag = (np.logical_or(rr < 0, rr >= self.
analysed_map.shape[1]))
529 cc_flag = (np.logical_or(cc < 0, cc >= self.
analysed_map.shape[0]))
530 flag = np.logical_not(np.logical_or(rr_flag, cc_flag))
532 if np.sum(self.
analysed_map[cc[flag], rr[flag]] * 1) > 1:
537 row.shape = (row.shape[0], 1)
538 temp_row_full = binary_dilation(row, footprint=np.ones((padding, padding)))
539 temp_row_full = temp_row_full * 1
540 temp_row_cut = temp_row_full.copy()
556 for i, t
in enumerate(temp_row_cut):
557 if t == 0
and pt == 0:
559 elif pt == 0
and t != 0:
563 elif pt != 0
and t != 0:
566 elif t == 0
and pt != 0:
567 l_slice_ids.append(ts)
577 for tslice
in l_slice_ids:
578 if len(tslice) > cell_tr:
584 cc_slices.append(cc_s)
585 rr_slices.append(rr_s)
587 temp_slice.append((cc_slices, rr_slices))
589 slices_ids.append((cc_slices, rr_slices))
591 slices.append((cc_slices, rr_slices))
594 cell_hypothesis.append((cc[flag], rr[flag]))
596 lines_hypothesis.append([l[0] + s, l[1], l[2] + s, l[3]])
598 lines_hypothesis.append([l[0], l[1] + s, l[2], l[3] + s])
600 rospy.loginfo(
"[ROSE] ERROR")
601 kde_hypothesis.append(temp_row_full)
602 kde_hypothesis_cut.append(temp_row_cut)
605 slices_dir.append(temp_slice)
606 return d_row_ret, slices_ids, slices, cell_hypothesis, lines_hypothesis, kde_hypothesis, kde_hypothesis_cut, slices_dir
609 rospy.loginfo(
"[ROSE] Generate initial hypothesis with kde.....")
616 self.
lines_long_v, max_len, bandwidth, cutoff_percent, cell_tr,
True)
618 self.
lines_long_h, max_len, bandwidth, cutoff_percent, cell_tr,
False)
619 rospy.loginfo(
"[ROSE] OK ({0:.2f})".format(time.time() - t))
622 rospy.loginfo(
"[ROSE] Generate initial hypothesis simple.....")
632 rospy.loginfo(
"[ROSE] OK ({0:.2f})".format(time.time() - t))
635 rospy.loginfo(
"[ROSE] Find Walls with flood filing.....")
643 for q
in zip(p[0], p[1]):
644 temp_map[q[0], q[1]] = 1
646 temp_map_fill = temp_map.copy()
649 seed = np.argwhere(temp_map_fill == 1)
652 temp_map_fill = flood_fill(temp_map_fill, (seed[0][0], seed[0][1]), id)
657 local_segment = sh.Segment()
658 cluster = np.where(temp_map_fill == id - 1)
659 cluster = np.column_stack((cluster[0], cluster[1]))
660 local_segment.add_cells(cluster)
661 local_segment.compute_hull()
662 local_segment.compute_mbb()
663 local_segment.id = id
664 local_segments.append(local_segment)
668 for l_segment
in local_segments:
669 x1, y1 = l_segment.center
670 x2, y2 = l_segment.center[0] + l_segment.rectangle_direction[0], l_segment.center[1] + \
671 l_segment.rectangle_direction[1]
674 c = a * (x1) + b * (y1)
677 Y1 = (c - a * X1) / b
679 Y2 = (c - a * X2) / b
680 if np.abs(Y1) > 3 * np.max(self.
binary_map.shape)
or b == 0:
683 X1 = (c - b * Y1) / a
685 X2 = (c - b * Y2) / a
687 local_mbb_lines.append({
"X1": X1,
"X2": X2,
"Y1": Y1,
"Y2": Y2})
688 self.
all_lines.append(((X1, Y1), (X2, Y2)))
695 for q
in zip(p[0], p[1]):
696 temp_map[q[0], q[1]] = 1
697 temp_map_fill = temp_map.copy()
700 seed = np.argwhere(temp_map_fill == 1)
702 temp_map_fill = flood_fill(temp_map_fill, (seed[0][0], seed[0][1]), id)
706 local_segment = sh.Segment()
707 cluster = np.where(temp_map_fill == id - 1)
708 cluster = np.column_stack((cluster[0], cluster[1]))
709 local_segment.add_cells(cluster)
710 local_segment.compute_hull()
711 local_segment.compute_mbb()
712 local_segment.id = id
713 local_segments.append(local_segment)
717 for l_segment
in local_segments:
718 x1, y1 = l_segment.center
719 x2, y2 = l_segment.center[0] + l_segment.rectangle_direction[0], l_segment.center[1] + \
720 l_segment.rectangle_direction[1]
723 c = a * (x1) + b * (y1)
726 Y1 = (c - a * X1) / b
728 Y2 = (c - a * X2) / b
729 if np.abs(Y1) > 3 * np.max(self.
binary_map.shape)
or b == 0:
732 X1 = (c - b * Y1) / a
734 X2 = (c - b * Y2) / a
736 local_mbb_lines.append({
"X1": X1,
"X2": X2,
"Y1": Y1,
"Y2": Y2})
737 self.
all_lines.append(((X1, Y1), (X2, Y2)))
740 rospy.loginfo(
"[ROSE] OK ({0:.2f})".format(time.time() - t))
743 rospy.loginfo(
"[ROSE] Find Walls with line segment clustering.....")
750 clustering_h = DBSCAN(eps=eps, min_samples=min_samples,
751 metric=he.shortest_distance_between_segements).fit(
759 clustering_v = DBSCAN(eps=eps, min_samples=min_samples,
760 metric=he.shortest_distance_between_segements).fit(
770 if last_label != label:
772 for s
in zip(slice[0][0], slice[1][0]):
773 temp_map[s[0]][s[1]] = id
777 if last_label != label:
779 for s
in zip(slice[0][0], slice[1][0]):
780 temp_map[s[0]][s[1]] = id
783 rospy.loginfo(
"[ROSE] OK ({0:.2f})".format(time.time() - t))
789 rospy.loginfo(
"[ROSE] dir:", self.
angles[p[0]] * 180.0 / np.pi, self.
angles[p[1]] * 180.0 / np.pi)
791 def show(self, visualisation, path, shape, format='.png'):
792 rospy.loginfo(
"[ROSE] Generating visualisation.....")
795 if visualisation[
"Binary map"]:
796 fig, ax = plt.subplots(nrows=1, ncols=1)
801 fig.canvas.set_window_title(name)
802 title = os.path.join(path, name + format)
805 if visualisation[
"FFT Spectrum"]:
806 fig, ax = plt.subplots(nrows=1, ncols=1)
807 ax.imshow((np.abs(self.
ft_image)), cmap=
"nipy_spectral")
809 name =
"FFT Spectrum"
811 fig.canvas.set_window_title(name)
812 title = os.path.join(path, name + format)
815 if visualisation[
"FFT spectrum with directions"]:
816 fig, ax = plt.subplots(nrows=1, ncols=1)
817 ax.imshow((np.abs(self.
ft_image)), cmap=
"nipy_spectral")
819 ax.plot([l[1], l[3]], [l[0], l[2]])
821 name =
"FFT Spectrum with directions"
823 fig.canvas.set_window_title(name)
824 ax.set_xlim(0, self.
ft_image.shape[1])
825 ax.set_ylim(0, self.
ft_image.shape[0])
826 title = os.path.join(path, name + format)
829 if visualisation[
"Map with walls"]:
830 fig, ax = plt.subplots(nrows=1, ncols=1)
833 for indices
in zip(indices_slice[0], indices_slice[1]):
834 for i
in zip(indices[0], indices[1]):
835 ax.plot(i[1], i[0],
'rx')
837 for indices
in zip(indices_slice[0], indices_slice[1]):
838 for i
in zip(indices[0], indices[1]):
839 ax.plot(i[1], i[0],
'rx')
841 name =
"Map with walls"
843 fig.canvas.set_window_title(name)
844 title = os.path.join(path, name + format)
847 if visualisation[
"Map with directions"]:
848 fig, ax = plt.subplots(nrows=1, ncols=1)
851 ax.plot([line[0], line[2]], [line[3], line[1]], alpha=0.5)
853 ax.plot([line[0], line[2]], [line[3], line[1]], alpha=0.5)
855 ax.scatter(cells[1], cells[0], c=
'r', s=values * 100, alpha=0.5)
857 ax.scatter(cells[1], cells[0], c=
'r', s=values * 100, alpha=0.5)
859 ax.scatter(cells[1], cells[0], c=
'g', s=values * 100, alpha=0.5)
861 ax.scatter(cells[1], cells[0], c=
'g', s=values * 100, alpha=0.5)
863 name =
"Map with directions"
865 fig.canvas.set_window_title(name)
868 title = os.path.join(path, name + format)
871 if visualisation[
"Unfolded FFT Spectrum"]:
872 fig, ax = plt.subplots(1, 1)
873 ax.imshow(np.flipud(self.
pol), cmap=
"nipy_spectral", aspect=
'auto',
876 ax.set_xlabel(
"Orientation [rad]")
877 ax.set_ylabel(
"Radius in pixel")
882 ax2.scatter(self.
angles[p], self.
pol_h[p], marker=
'^', s=120)
883 ax2.set_ylabel(
"Orientation score")
884 name =
"Unfolded FFT Spectrum"
886 fig.canvas.set_window_title(name)
887 title = os.path.join(path, name + format)
890 if visualisation[
"FFT Spectrum Signal"]:
891 fig, ax = plt.subplots(nrows=1, ncols=1)
892 ax.imshow((np.abs(self.
mask_ft_image)), cmap=
"nipy_spectral")
894 name =
"FFT Spectrum Signal"
895 fig.canvas.set_window_title(name)
897 title = os.path.join(path, name + format)
900 if visualisation[
"FFT Spectrum Noise"]:
901 fig, ax = plt.subplots(nrows=1, ncols=1)
904 name =
"FFT Spectrum Noise"
905 fig.canvas.set_window_title(name)
907 title = os.path.join(path, name + format)
910 if visualisation[
"Map Scored Good"]:
911 fig, ax = plt.subplots(nrows=1, ncols=1)
914 name =
"Map Scored Good"
915 fig.canvas.set_window_title(name)
917 title = os.path.join(path, name + format)
920 if visualisation[
"Map Scored Bad"]:
921 fig, ax = plt.subplots(nrows=1, ncols=1)
924 name =
"Map Scored Bad"
925 fig.canvas.set_window_title(name)
927 title = os.path.join(path, name + format)
930 if visualisation[
"Map Scored Diff"]:
931 fig, ax = plt.subplots(nrows=1, ncols=1)
934 name =
"Map Scored Diff"
935 fig.canvas.set_window_title(name)
937 title = os.path.join(path, name + format)
940 if visualisation[
"Map Split Good"]:
941 fig, ax = plt.subplots(nrows=1, ncols=1)
944 name =
"Map Split Good"
945 fig.canvas.set_window_title(name)
947 title = os.path.join(path, name + format)
950 if visualisation[
"FFT Map Split Good"]:
951 fig, ax = plt.subplots(nrows=1, ncols=1)
954 name =
"FFT Map Split Good"
955 fig.canvas.set_window_title(name)
957 title = os.path.join(path, name + format)
960 if visualisation[
"Side by Side"]:
961 fig, ax = plt.subplots(nrows=1, ncols=2, sharex=
True, sharey=
True)
962 ax[0].imshow(self.
binary_map * 1, cmap=
"gray")
968 fig.canvas.set_window_title(
"Map Quality assessment")
969 ax[0].set_title(name1)
970 ax[1].set_title(name2)
972 plt.subplots_adjust(left=0.0, right=1.0, top=1.0, bottom=0, wspace=0, hspace=0)
973 title = os.path.join(path, name + format)
976 if visualisation[
"Simple Filtered Map"]:
977 fig, ax = plt.subplots(nrows=1, ncols=1)
980 for ind
in zip(non_zero_ind[0], non_zero_ind[1]):
981 square = patches.Rectangle((ind[1], ind[0]), 1, 1, color=
'green')
985 fig.canvas.set_window_title(name)
987 title = os.path.join(path, name + format)
990 if visualisation[
"Threshold Setup with Clusters"]:
1010 fig, ax = plt.subplots(nrows=1, ncols=1)
1013 ax.plot(x, y_b,
'r')
1014 ax.plot(x, y_g,
'g')
1016 name =
"Treshold Setup with Clusters"
1017 fig.canvas.set_window_title(name)
1019 title = os.path.join(path, name + format)
1022 if visualisation[
"Cluster Filtered Map"]:
1023 fig, ax = plt.subplots(nrows=1, ncols=1)
1026 for ind
in zip(non_zero_ind[0], non_zero_ind[1]):
1027 square = patches.Rectangle((ind[1], ind[0]), 1, 1, color=
'green')
1028 ax.add_patch(square)
1031 fig.canvas.set_window_title(name)
1033 title = os.path.join(path, name + format)
1036 if visualisation[
"Map with slices"]:
1037 fig, ax = plt.subplots(nrows=1, ncols=1)
1040 for s
in zip(l[0], l[1]):
1041 ax.plot(s[1], s[0],
'.')
1043 for s
in zip(l[0], l[1]):
1044 ax.plot(s[1], s[0],
'.')
1046 name =
"Map with slices"
1048 fig.canvas.set_window_title(name)
1049 title = os.path.join(path, name + format)
1052 if visualisation[
"Partial Scores"]:
1056 div = he.proper_divs2(int(co))
1059 div = he.proper_divs2(int(co))
1063 if len(div) % 2 == 0:
1064 nrows = div[int(len(div) / 2) - 1]
1065 ncols = div[int(len(div) / 2)]
1067 nrows = div[int(len(div) / 2)]
1068 ncols = div[int(len(div) / 2)]
1072 fig, ax = plt.subplots(nrows=nrows, ncols=ncols, sharex=
True, sharey=
True)
1075 ax[int(i / ncols)][int(i % ncols)].imshow(p)
1076 ax[int(i / ncols)][int(i % ncols)].axis(
'off')
1078 name =
"Partial Scores"
1079 fig.canvas.set_window_title(name)
1080 title = os.path.join(path, name + format)
1083 fig, ax = plt.subplots(nrows=1, ncols=1, sharex=
True, sharey=
True)
1086 name =
"Partial Scores"
1087 fig.canvas.set_window_title(name)
1088 title = os.path.join(path, name + format)
1091 if visualisation[
"Partial Reconstructs"]:
1095 div = he.proper_divs2(int(co))
1098 div = he.proper_divs2(int(co))
1102 if len(div) % 2 == 0:
1103 nrows = div[int(len(div) / 2) - 1]
1104 ncols = div[int(len(div) / 2)]
1106 nrows = div[int(len(div) / 2)]
1107 ncols = div[int(len(div) / 2)]
1111 fig, ax = plt.subplots(nrows=nrows, ncols=ncols, sharex=
True, sharey=
True)
1114 ax[int(i / ncols)][int(i % ncols)].imshow(p)
1115 ax[int(i / ncols)][int(i % ncols)].axis(
'off')
1117 name =
"Partial Reconstruct"
1118 fig.canvas.set_window_title(name)
1119 title = os.path.join(path, name + format)
1122 fig, ax = plt.subplots(nrows=1, ncols=1, sharex=
True, sharey=
True)
1125 name =
"Partial Reconstruct"
1126 fig.canvas.set_window_title(name)
1127 title = os.path.join(path, name + format)
1130 if visualisation[
"Wall lines from mbb"]:
1131 cmap = plt.cm.get_cmap(
"tab10")
1132 cmap.set_under(
"black")
1133 cmap.set_over(
"yellow")
1134 fig, ax = plt.subplots(nrows=1, ncols=1, sharey=
True, sharex=
True)
1137 for l_segment, l_mbb_lines
in zip(local_segments, local_mbb_lines):
1138 ax.plot(l_segment.minimal_bounding_box[:, 1], l_segment.minimal_bounding_box[:, 0],
'r')
1139 if l_segment.mbb_area > 10:
1140 ax.plot([l_mbb_lines[
"Y1"], l_mbb_lines[
"Y2"]], [l_mbb_lines[
"X1"], l_mbb_lines[
"X2"]],
'g')
1142 for l_segment, l_mbb_lines
in zip(local_segments, local_mbb_lines):
1143 ax.plot(l_segment.minimal_bounding_box[:, 1], l_segment.minimal_bounding_box[:, 0],
'r')
1144 if l_segment.mbb_area > 10:
1145 ax.plot([l_mbb_lines[
"Y1"], l_mbb_lines[
"Y2"]], [l_mbb_lines[
"X1"], l_mbb_lines[
"X2"]],
'g')
1149 name =
"Wall lines from mbb"
1150 fig.canvas.set_window_title(name)
1151 title = os.path.join(path, name + format)
1154 if visualisation[
"Short wall lines from mbb"]:
1155 cmap = plt.cm.get_cmap(
"tab10")
1156 cmap.set_under(
"black")
1157 cmap.set_over(
"yellow")
1158 fig, ax = plt.subplots(nrows=1, ncols=1, sharey=
True, sharex=
True)
1162 for l_segment, l_mbb_lines
in zip(local_segments, local_mbb_lines):
1163 ax.plot(l_segment.minimal_bounding_box[:, 1], l_segment.minimal_bounding_box[:, 0],
'r')
1164 wall=he.cetral_line(l_segment.minimal_bounding_box)
1165 ax.plot([wall[0].y, wall[1].y], [wall[0].x, wall[1].x],
'c')
1169 for l_segment, l_mbb_lines
in zip(local_segments, local_mbb_lines):
1170 ax.plot(l_segment.minimal_bounding_box[:, 1], l_segment.minimal_bounding_box[:, 0],
'r')
1171 wall = he.cetral_line(l_segment.minimal_bounding_box)
1172 ax.plot([wall[0].y, wall[1].y], [wall[0].x, wall[1].x],
'c')
1178 name =
"Short wall lines from mbb"
1179 fig.canvas.set_window_title(name)
1180 title = os.path.join(path, name + format)
1183 if visualisation[
"Short wall lines over original map"]:
1184 fig, ax = plt.subplots(nrows=1, ncols=1, sharey=
True, sharex=
True)
1187 for l_segment, l_mbb_lines
in zip(local_segments, local_mbb_lines):
1188 ax.plot(l_segment.minimal_bounding_box[:, 1], l_segment.minimal_bounding_box[:, 0],
'r')
1189 wall = he.cetral_line(l_segment.minimal_bounding_box)
1190 ax.plot([wall[0].y, wall[1].y], [wall[0].x, wall[1].x],
'c')
1194 for l_segment, l_mbb_lines
in zip(local_segments, local_mbb_lines):
1195 ax.plot(l_segment.minimal_bounding_box[:, 1], l_segment.minimal_bounding_box[:, 0],
'r')
1196 wall = he.cetral_line(l_segment.minimal_bounding_box)
1197 ax.plot([wall[0].y, wall[1].y], [wall[0].x, wall[1].x],
'c')
1203 name =
"Short wall lines over original map"
1204 fig.canvas.set_window_title(name)
1205 title = os.path.join(path, name + format)
1208 if visualisation[
"Labels and Raw map"]:
1209 cmap = plt.cm.get_cmap(
"tab10")
1210 cmap.set_under(
"black")
1211 cmap.set_over(
"yellow")
1212 fig, ax = plt.subplots(nrows=1, ncols=1, sharey=
True, sharex=
True)
1214 ax.imshow(self.
binary_map, cmap=
"gray", alpha=0.5)
1216 for l_segment, l_mbb_lines
in zip(local_segments, local_mbb_lines):
1217 ax.plot(l_segment.minimal_bounding_box[:, 1], l_segment.minimal_bounding_box[:, 0],
'r')
1219 for l_segment, l_mbb_lines
in zip(local_segments, local_mbb_lines):
1220 ax.plot(l_segment.minimal_bounding_box[:, 1], l_segment.minimal_bounding_box[:, 0],
'r')
1224 name =
"Labels and Raw map"
1225 fig.canvas.set_window_title(name)
1226 title = os.path.join(path, name + format)
1229 if visualisation[
"Raw line segments"]:
1230 fig, ax = plt.subplots(nrows=1, ncols=1, sharey=
True, sharex=
True)
1233 ax.plot([segment[1], segment[3]], [segment[0], segment[2]])
1236 ax.plot([segment[1], segment[3]], [segment[0], segment[2]])
1238 name =
"Raw line segments"
1239 fig.canvas.set_window_title(name)
1241 title = os.path.join(path, name + format)
1244 rospy.loginfo(
"[ROSE] OK ({0:.2f})".format(time.time() - t))