예제 #1
0
def show_results():
    piece = fm.load_img_piece()
    edge_img = prep.canny(piece)
    tooth = fm.load_tooth_of_piece(2)
    fm.show_with_points(edge_img, tooth)

    new_tooth = active_contour(tooth, edge_img, 25, 1)
    fm.show_with_points(edge_img, new_tooth)
예제 #2
0
def preperation_all(radiograph, all_landmarks):

    #median = prep.median_filter(radiograph)
    #     edge_img = prep.edge_detection_low(median)
    edge_img = prep.calc_external_img_active_contour(radiograph)
    pcas_tooth = PCA.PCA_analysis_all(all_landmarks, None)

    return edge_img, pcas_tooth
예제 #3
0
def active_shape_scale(img, tooth_points, pca_tooth, length, scale):

    scaled_img, scaled_tooth_points = scaling(img, tooth_points, 1 / scale)
    edge_img = prep.calc_external_img_active_contour(scaled_img)
    new_points = active_shape(edge_img, scaled_tooth_points, pca_tooth, length)
    new_img, new_scaled_points = scaling(scaled_img, new_points, scale)

    return new_scaled_points
예제 #4
0
def preperation(radiograph, tooth_variations):

    #median = prep.median_filter(radiograph)
    #     edge_img = prep.edge_detection_low(median)

    edge_img = prep.calc_external_img_active_contour(radiograph)
    pca_tooth = PCA.PCA_analysis(tooth_variations, None)

    return edge_img, pca_tooth
def show_results_fitting():
    piece = fm.load_img_piece()
    edge_img = prep.canny(piece)
    tooth = fm.load_tooth_of_piece(0)
    new_points_list, total_error = fit_measure(tooth, 25, edge_img)
    for i in range(7):
        tooth = fm.load_tooth_of_piece(i + 1)
        new_points, total_error = fit_measure(tooth, 25, edge_img)
        new_points_list = np.append(new_points_list, new_points)
    fm.show_with_points(edge_img, new_points_list.reshape(-1, 2))
예제 #6
0
def run(img, centroid):

    # --------------- TESTING ----------------- #

    idge_canny = prep.calc_external_img_active_contour(img)
    edge_sobel = prep.sobel(img)
    testimage, testlandmarks = test_set
    test = Shape(testlandmarks)

    pose_para = aligner.get_pose_parameters(pca.mean, test)
    lst = list(pose_para)
    lst[0] = 0
    lst[1] = 0
    lst[2] = pose_para[2]
    lst[3] = 0

    t = tuple(lst)

    points = aligner.transform(pca.mean, t)

    plt.imshow(img)
    plt.plot(points.x, points.y, "r.")

    meanShapeCentroid = (np.sum(points.x) / 30, np.sum(points.y) / 30)
    #perform manual centroid
    # centroid= tran.set_clicked_center(np.uint8(testimage))
    matches1 = tran.initalizeShape(centroid, meanShapeCentroid,
                                   points.matrix.T)
    if not isinstance(matches1, Shape):
        matches1 = Shape(matches1.T)

    # meanShapeCentroid = (np.sum(testlandmarks.x)/30,np.sum(testlandmarks.y)/30)
    plt.imshow(img)
    plt.plot(matches1.x, matches1.y, '.')
    plt.show()

    x, y, new_p = active_shape(edge_sobel, matches1, pca, img, centroid)

    return y
예제 #7
0
def active_shape_scale_n_times(img, tooth_points, pca_tooth, length, scale,
                               n_times):

    points = [0] * (n_times + 1)
    points[0] = tooth_points

    scaled_img, scaled_tooth_points = scaling(img, tooth_points, 1 / scale)
    edge_img = prep.calc_external_img_active_contour(scaled_img)
    new_points = active_shape(edge_img, scaled_tooth_points, pca_tooth, length)

    for i in range(n_times):
        new_points = active_shape(edge_img, new_points, pca_tooth, length)
        points[i + 1] = np.around(new_points * scale)

    return points
def test_normal_on_edge():

    piece = fm.load_img_piece()
    new_pice = piece[300:450, 100:250]

    tooth = fm.load_tooth_of_piece()
    points = tooth

    fm.show_with_points(piece, points)

    new_points = np.copy(points)
    new_points[:, 0] = points[:, 0] - 100
    new_points[:, 1] = points[:, 1] - 300

    a, b, c = new_points[0:3]
    rad = get_normal_angle(a, b, c)
    p1 = get_point_at_distance(b, 20, rad)
    p2 = get_point_at_distance(b, -20, rad)
    img_copy = new_pice.copy()
    p1 = np.array(p1, dtype=int)
    p2 = np.array(p2, dtype=int)
    make_line(img_copy, p1, p2)

    visualize_points = new_points.take([38, 39, 0, 1, 2, 3], axis=0)
    proj = project_on(b, a, c)
    visualize_points = np.append(visualize_points, proj).reshape(-1, 2)

    show_with_points(img_copy, visualize_points)

    edges = get_points_on_angle_normal(b, rad, 20)
    edge_img = prep.edge_detection_high(new_pice)
    strength = edge_strength_at_points(edges, edge_img)

    show_with_points(new_pice, edges)

    fig, ax = plt.subplots(figsize=(7, 7))
    plt.plot(np.arange(-20, 21), strength)
    plt.show()
예제 #9
0
def pre_pocess(img):
    median = prep.median_filter(img)
    contrast = prep.contrast_stretching(median)
    return contrast
    img_copy = new_pice.copy()

    p1 = np.array(p1, dtype=int)
    p2 = np.array(p2, dtype=int)
    make_line(img_copy, p1, p2)

    visualize_points = new_points.take([38, 39, 0, 1, 2, 3, 4, 5], axis=0)
    proj = project_on(b, a, c)
    #new_visualize_points = np.append(visualize_points,proj).reshape(-1,2)

    show_with_points(img_copy, visualize_points)

    edges = get_points_on_angle_normal(b, rad, 20)
    #edge_img = prep.sobel(new_pice)
    edge_img = prep.canny(new_pice)
    strength = edge_strength_at_points(edges, edge_img)

    #show_with_points(new_pice,np.append(edges,visualize_points).reshape(-1,2))

    fig, ax = plt.subplots(figsize=(7, 7))
    plt.plot(np.arange(-20, 21), strength)
    plt.show()

    p = strongest_edge_point_on_normal(a, b, c, 20, edge_img)
    show_with_points(edge_img, np.append(visualize_points, p).reshape(-1, 2))
    show_results_fitting()

#     piece = prep.median_filter(piece)
#     edge_img = prep.edge_detection_high(piece)
#     show_with_points(edge_img, points)
예제 #11
0
def calc_external_img2(img):
    median = prep.median_filter(img)
    edges = prep.edge_detection_low(median)
    return -edges
예제 #12
0
    tooth = fm.load_tooth_of_piece(2)
    fm.show_with_points(edge_img, tooth)

    new_tooth = active_contour(tooth, edge_img, 25, 1)
    fm.show_with_points(edge_img, new_tooth)
    
def show_influence_ext_int():
    new_piece, new_tooth = piece, tooth 

    mean = calc_mean(new_tooth)
    ext = calc_external_img(new_piece)
    fm.show_with_points(ext, new_tooth[0:2])

    print(calc_external(new_tooth[0],ext))
    print(calc_internal(new_tooth[0], new_tooth[1], mean))
    print(calc_energy(new_tooth[0],new_tooth[1],ext,mean,10))


# In[ ]:


if __name__ == "__main__":

    piece = fm.load_img_piece()
    tooth = fm.load_tooth_of_piece()
    ext = prep.calc_external_img_active_contour(piece) 
    fm.show_with_points(ext, tooth)
    ext2, stooth = fm.resolution_scale(ext, tooth, 1/6)
    fm.show_with_points(ext2, stooth)