def test_interpol(self): asm, imgshps = load_incisor() shape = imgshps[0].shape image = imgshps[0].image vecs, tck = shape.get_orthogonal_vectors(with_tck=True) plot_shape(shape, display=False, overlay_image=image) plot_vecs(vecs, shape.as_point_list(), display=False) plot_interpol(tck)
def test_conform_to_rect(self): s1 = Shape([(-20, 20), (0, 20), (0, -40), (-20, -40)]) bottom_left = Point(0, 0) top_right = Point(50, 50) plot_rectangle(bottom_left, top_right, display=False) s2 = s1.conform_to_rect(bottom_left, top_right) plot_shape([s1, s2]) npt.assert_equal(s2.axis_means(), np.array([25, 25]))
def test_propose_shape(self): # Arrange asm, image_shapes = load_incisor(blur=True, sobel=True) # Manually fit bottom_left = Point(1310, 745) top_right = Point(1410, 1000) original_imgshp = ImageShape( image_shapes[0].image, asm.mean_shape.conform_to_rect(bottom_left, top_right), ) # Act imageshape = original_imgshp for i in range(5): proposed_shape = asm.propose_shape(imageshape) matched_shape, *_ = asm.match_target(proposed_shape) # Assert plot_image_shape(imageshape, display=False) plot_shape([proposed_shape, matched_shape]) imageshape = ImageShape(imageshape.image, matched_shape)
def test_get_orthogonal_vectors(self): round_shape = Shape( [ (4.5, 1), (4, 1), (3.5, 1), (3, 1), (2.5, 1.5), (2, 2), (1.5, 2.5), (1, 3), (1, 3.5), (1, 4), (1.5, 4.5), (2, 5), (2.5, 5.5), (3, 6), (3.5, 6), (4, 6), (4.5, 6), (5, 6), (5.5, 5.5), (6, 5), (6.5, 4.5), (7, 4), (7, 3.5), (7, 3), (6.5, 2.5), (6, 2), (5.5, 1.5), (5, 1), ] ) ort_vects = round_shape.get_orthogonal_vectors() print(ort_vects) plot_shape(round_shape, display=False) plot_vecs(ort_vects, round_shape.as_point_list())
s1 = Shape([(1, 2), (1, 3), (1, 4), (2, 4), (3, 4), (3, 3), (3, 2), (2, 2)]) s2 = Shape([(5, 2), (6, 3), (7, 4), (8, 3), (9, 2), (8, 1), (7, 0), (6, 1)]) s3 = Shape([(5, 2), (6, 3), (8, 4), (8, 3), (9, 2), (8, 1), (7, 0), (6, 1)]) s4 = Shape([(5, 2), (6, 3), (6, 4), (8, 3), (9, 2), (8, 1), (7, 0), (6, 1)]) s5 = Shape([(5, 2), (6, 2), (8, 4), (8, 3), (9, 2), (8, 1), (7, 0), (6, 1)]) s6 = Shape([(5, 2), (6, 4), (8, 4), (8, 3), (9, 2), (8, 1), (7, 0), (6, 1)]) se1 = Shape([(1, 1), (2, 1), (3, 1), (3, 2), (3, 3), (2, 3), (1, 3), (1, 2)]) se2 = Shape([(1, 1), (2, 1), (3, 1), (3, 2), (3, 4), (2, 3.5), (1, 3), (1, 2)]) # am = ActiveShapeModel.from_shapes([se1, se2]) # util.plot_shape([se1, se2] + [am.mean_shape] + # [am.create_shape(am.eigenvalues)]) am = ActiveShapeModel.from_shapes([s1, s2, s3, s4, s5, s6]) # Estimated shape 1 es1 = am.match_target(s1) # shapes = [] # for b in np.arange(-0.3 * am.eigenvalues[0], 0.3 * am.eigenvalues[0], # 0.6 * am.eigenvalues[0] / 5): # shape_params = np.zeros(len(am)) # shape_params[0] = b # print(shape_params) # shapes.append(am.create_shape(shape_params)) util.plot_shape([es1, s1]) # s1.get_orthogonal_vectors()
def test_apply_procrustes(self): asm, image_shapes = load_incisor() shapes = [imgshp.shape for imgshp in image_shapes] Shape.apply_procrustes(shapes) # Shape.translate_all_to_origin(shapes) plot_shape(shapes, dots=False)