def test_tjoints_levels(img_file, rect=None, levels=None): img = misc.imread(img_file) if rect is None: rect = RR.RectangularRegion((50, 50), (50, 70), (70, 70), (70, 50)) if levels is None: levels = [5 * i for i in range(0, 51)] grid = HI.region_to_half_grid(rect) extended_grid = HI.add_level_information(img, grid) tjoints_grid = {} for level in levels: level_line = LL.compute_level_line(img, level) level_intersection = RI.intersect_region_level_line( rect.extended_boundary, level_line) tjoints_grid.update( compute_level_tjoints(extended_grid, level_intersection)) # print( len(tjoints_grid.keys()) ) x = [] y = [] for k, v in tjoints_grid.items(): x.append(k[0]) y.append(k[1]) plt.plot(x, y, 'bo') plt.show()
def test_all_intermediate_levels(img_file, rect=None, levels=None): img = misc.imread(img_file) if rect is None: rect = RR.RectangularRegion((50, 50), (50, 70), (70, 70), (70, 50)) if levels is None: levels = [5 * i for i in range(0, 51)] grid = HI.region_to_half_grid(rect) extended_grid = HI.add_level_information(img, grid) tjoints_grid = {} for level in levels: level_line = LL.compute_level_line(img, level) level_intersection = RI.intersect_region_level_line( rect.extended_boundary, level_line) tjoints_grid.update( compute_level_tjoints(extended_grid, level_intersection)) extended_tjoints = create_intermediate_levels(tjoints_grid) list_tjoints = extended_tjoints.values() list_tjoints = sorted(list_tjoints, key=lambda x: x["order"]) for data in list_tjoints: print(data["grid"], " : ", data["levels"])
def test_directions(rect=None): if rect is None: rect = RR.RectangularRegion((50, 50), (50, 70), (70, 70), (70, 50)) grid = region_to_half_grid(rect) x = [k[0] for k in grid.keys()] y = [k[1] for k in grid.keys()] plt.plot(x[::3], y[::3], 'ro') i = 0 for k, v in grid.items(): i += 1 if i % 3 != 0: continue x, y = k direction = v["out"] plt.arrow(x, y, direction[0] * 0.2, direction[1] * 0.2, color='g', head_width=0.5, head_length=0.5) plt.show()
def test_match(img_file, rect=None, levels=None): img = misc.imread(img_file) if rect is None: rect = RR.RectangularRegion((50, 50), (50, 70), (70, 70), (70, 50)) if levels is None: levels = [5 * i for i in range(0, 51)] grid = HI.region_to_half_grid(rect) extended_grid = HI.add_level_information(img, grid) tjoints_grid = {} for level in levels: level_line = LL.compute_level_line(img, level) level_intersection = RI.intersect_region_level_line( rect.extended_boundary, level_line) tjoints_grid.update( TJ.compute_level_tjoints(extended_grid, level_intersection)) extended_tjoints = TJ.create_intermediate_levels(tjoints_grid) for k, v in extended_tjoints.items(): extended_tjoints[k]["grid"] = k tjoints_list = sorted(extended_tjoints.values(), key=lambda x: x["order"]) connections = match_tjoints_pairs(tjoints_list) print(connections)
def test_region_grid(rect=None): if rect is None: rect = RR.RectangularRegion((50, 50), (50, 70), (70, 70), (70, 50)) grid = region_to_half_grid(rect) x = [k[0] for k in grid.keys()] y = [k[1] for k in grid.keys()] plt.plot(x, y, 'ro') plt.show()
def test_intermediate_levels(img_file, level, rect=None): img = misc.imread(img_file) if rect is None: rect = RR.RectangularRegion((50, 50), (50, 70), (70, 70), (70, 50)) level_line = LL.compute_level_line(img, level) grid = HI.region_to_half_grid(rect) extended_grid = HI.add_level_information(img, grid) level_intersection = RI.intersect_region_level_line( rect.extended_boundary, level_line) tjoints_grid = compute_level_tjoints(extended_grid, level_intersection) extended_tjoints = create_intermediate_levels(tjoints_grid) for k, v in extended_tjoints.items(): print(v["levels"])
def test_intersection(img_file, rect=None, levels=None): img = misc.imread(img_file) if levels is None: levels = [i * 5 for i in range(50)] if rect is None: rect = RR.RectangularRegion((50, 50), (50, 70), (70, 70), (70, 50)) level_lines = [] for l in levels: level_line = LL.compute_level_line(img, l) level_lines.append(level_line) img[rect.extended_boundary[:, 1], rect.extended_boundary[:, 0]] = 200 for lvl in level_lines: intersection = intersect_region_level_line(rect.extended_boundary, lvl) print(intersection.any()) img[intersection] = 100 plt.imshow(img, cmap="gray") plt.show()
def test_paint_lines(img_file, lines=None, rect=None): img = misc.imread(img_file) if rect is None: rect = RR.RectangularRegion((50, 50), (50, 70), (70, 70), (70, 50)) if lines is None: lines = [[52, 71, 55, 71, 107], [60, 71, 63, 71, 154], [59, 71, 64, 71, 143], [50, 71, 66, 71, 102], [49, 51, 67, 71, 102], [70, 71, 71, 71, 104], [69, 71, 71, 70, 104], [71, 67, 71, 66, 100], [71, 68, 71, 65, 109], [68, 71, 71, 63, 105], [71, 62, 71, 59, 108], [49, 50, 71, 58, 105], [49, 50, 71, 57, 105], [71, 53, 71, 52, 103], [65, 49, 64, 49, 122]] img[rect.closure[:, 1], rect.closure[:, 0]] = 255 colors = np.linspace(0, 180, len(lines)) for i, line in enumerate(lines): paint_line(img, line[0], line[1], line[2], line[3], colors[i]) plt.imshow(img, cmap='gray') plt.show()