Пример #1
0
def trim_tooth_box(mesh, output_file):
    your_mesh = mesh
    points = extract_vertex_boundary_box(your_mesh.points)
    pcd = open3d.PointCloud()
    pcd.points = open3d.Vector3dVector(points)
    visualization.draw_geometries([pcd])

    stl_point_cloud = points
    stl_pc_file = output_file
    Yomiwrite.write_csv_matrix(stl_pc_file, stl_point_cloud)
Пример #2
0
def trim_tooth_box(scan, tooth_number, z_boundary, box):
    i = tooth_number
    z_boundary = z_boundary
    #z_boundary = BOUNDARY[i-1,4:].astype(int)
    box = box
    #box = BOX[i-17]
    HU_trim, bone_surface_idx = trim_slice_box(scan, box, z_boundary)
    dicom_point_cloud = open3d_plot(bone_surface_idx)
    dicom_pc_file = 'G:\\My Drive\\Project\\IntraOral Scanner Registration\\DICOM_pc\\corrected\\corrected_dicom_points_tooth' + np.str(49-i) + '.csv'
    Yomiwrite.write_csv_matrix(dicom_pc_file, dicom_point_cloud)
    del HU_trim
Пример #3
0
def trim_tooth_box(scan, slice_properties, tooth_number, z_boundary, box,
                   threshold, surface_name):
    i = tooth_number
    z_boundary = z_boundary
    #z_boundary = BOUNDARY[i-1,4:].astype(int)
    box = box
    #box = BOX[i-17]
    HU_trim, bone_surface_idx = trim_slice_box(scan, slice_properties, box,
                                               z_boundary, threshold)
    dicom_point_cloud = open3d_plot(bone_surface_idx, slice_properties,
                                    z_boundary)
    dicom_pc_file = 'C:\\tooth segmentation raw\\tooth_' + np.str(
        i + 1) + '_surface_' + surface_name + '.csv'
    Yomiwrite.write_csv_matrix(dicom_pc_file, dicom_point_cloud)
    del HU_trim, bone_surface_idx, dicom_point_cloud
Пример #4
0
import Readers as Yomiread
import Writers as Yomiwrite
import fileDialog

folder = fileDialog.select_folder()
file = folder + '/points.igs'
data = Yomiread.read_csv_D_type(file, 4, 20)
print('data is', data)
Yomiwrite.write_csv_matrix(folder + '/points.txt', data)
Пример #5
0
mtx_file = "G:\\My Drive\\Project\\IntraOral Scanner Registration\\TRE_verification\\result\\transforamtion_from_fiducial_space_to_ct.csv"
mtx_f2c = Yomiread.read_csv(mtx_file, 4, 5, flag=1)

splint_file = "G:\\My Drive\\Project\\IntraOral Scanner Registration\\Yomiplan fiducial registration\\Splint files\\FXT-0086-07-LRUL-MFG-Splint.txt"

fiducial_fiducial_space = Yomiread.read_csv(splint_file,
                                            4,
                                            9,
                                            flag=1,
                                            delimiter=" ")[:, 1:4]
print('fiducial is', fiducial_fiducial_space)
fiducial_ct_space = transpose_pc(fiducial_fiducial_space, mtx_f2c)

python_yomi = np.eye(4)
python_yomi[0:3, 3] = np.array([0, 0, (304 + 130) * 0.2])
python_yomi[0:3, 0] = np.array([0, 1, 0])
python_yomi[0:3, 1] = np.array([1, 0, 0])
python_yomi[0:3, 2] = np.array([0, 0, -1])

python_yomi_real = np.linalg.inv(python_yomi)
print('fiducial_ct_space is', fiducial_ct_space)

fiducial_ct_space = transpose_pc(fiducial_ct_space, python_yomi_real)
print('fiducial_ct_space is', fiducial_ct_space)

RESULT_TEM_BASE = "G:\\My Drive\\Project\\IntraOral Scanner Registration\\TRE_verification\\result\\"
Yomiwrite.write_csv_matrix(RESULT_TEM_BASE + 'fiducials_in_ct.csv',
                           fiducial_ct_space,
                           fmt='%0.8f')
Пример #6
0
    source_ctl = []  # source feature points
    target_ctl = []  # target feature points
    for i in range(16):
        source_ctl_tem, target_ctl_tem = prepare_data.find_ctl_points(
            prepare_data.source_stl_points[i],
            prepare_data.target_dicom_points[i], ICP_local[i].transformation)
        source_ctl.append(source_ctl_tem)
        target_ctl.append(target_ctl_tem)

    spline_source = np.vstack((source_ctl[0][1], source_ctl[1][1]))
    spline_target = np.vstack((target_ctl[0][1], target_ctl[1][1]))
    for i in range(14):
        spline_source = np.vstack((spline_source, source_ctl[i + 2][1]))
        spline_target = np.vstack((spline_target, target_ctl[i + 2][1]))
    Yomiwrite.write_csv_matrix(
        "G:\\My Drive\\Project\\IntraOral Scanner Registration\\STL_pc - trial1\\spline_target_points.csv",
        spline_target)
    Yomiwrite.write_csv_matrix(
        "G:\\My Drive\\Project\\IntraOral Scanner Registration\\STL_pc - trial1\\spline_source_points.csv",
        spline_source)

    control_list = range(16)  # if all teeth are used as landmarks
    # control_list = [0, 1, 2, 8, 9, 13, 14, 15]  # if specific landmarks are selected

    # land marks definition. Landmarks can be surface points or centroids
    j = 0  # use surface as landmarks
    # j = 1     # use centroid as landmarks

    for i in range(len(control_list)):
        if ICP_rms[i] < 0.3:  # Implement this for outlier rejection
            # if ICP_rms[i] > 0:        # Allow outlier
Пример #7
0

if __name__ == "__main__":
    stl_base = "G:\\My Drive\\Project\\HW-9232 Registration method for edentulous" \
               "\\Edentulous registration error analysis\\Typodont_scan\\Edentulous_scan\\"
    all_regions = []
    file = stl_base + 'full_arch.txt'
    if os.path.isfile(file):
        print('read txt')
        full_region = Yomiread.read_csv(file, 3, -1)
    else:
        stl_file = 'full_arch.stl'
        print('read stl')
        full_region = region_points.read_regions(stl_base + stl_file,
                                                 voxel_size=0.05)
        Yomiwrite.write_csv_matrix(stl_base + 'full_arch.txt', full_region)

    base = "G:\\My Drive\\Project\\HW-9232 Registration method for edentulous" \
           "\\Edentulous registration error analysis\\Stage2_more_regions\\"
    target_measurement_file = "targets.txt"
    points = Yomiread.read_csv(base + target_measurement_file, 4, 10, flag=1)
    targets_original = points[0:4, 1:4]

    arch1 = edentulous_arch.Edentulous_arch(full_region, targets_original)
    print('angle range is', arch1.target_angle_range)
    print('target position is',
          arch1.target_origins_cylindrical[:, 1] * 180 / np.pi)
    print('default fiducial is', arch1.default_fiducial)

    # Define configurations
    angle_span = 20
Пример #8
0
    # # Perform 2D spline fitting and generate guide points
    # guide_points_ct_in_ios, guide_points_theta_boundary_0 = sc.fit_spline_and_split(arch_ct_in_ios.spline_points,
    #                                                 arch_ct_in_ios.spline_points_cylindrical_center,
    #                                                 NUMBER_SPLINE_GUIDED_POINTS)
    # guide_points_ct_to_ios, guide_points_theta_boundary_2 = sc.fit_spline_and_split(arch_ct_to_ios.spline_points,
    #                                                arch_ct_to_ios.spline_points_cylindrical_center,
    #                                                 NUMBER_SPLINE_GUIDED_POINTS)
    # displacement = guide_points_ct_to_ios - guide_points_ct_in_ios  # move ct_in_ios points to ct_to_ios
    #
    #
    # test = guide_points_ct_in_ios + displacement
    # guide_points_theta_boundary_1 = guide_points_theta_boundary_0 #+ np.pi/(2*NUMBER_SPLINE_GUIDED_POINTS)

    # Perform 3D spline fitting and generate guide points
    Yomiwrite.write_csv_matrix(RESULT_TEM_BASE + "spline_target_points.csv", arch_ct_to_ios.spline_points)
    Yomiwrite.write_csv_matrix(RESULT_TEM_BASE + "spline_rigid_points.csv", arch_ct_in_ios.spline_points)
    control_list = arch_ct_in_ios.existing_tooth_list
    # # step2 generate mesh grid points
    breaks_file_rigid = RESULT_TEM_BASE + 'spline_rigid_breaks.csv'
    coe_file_rigid = RESULT_TEM_BASE + 'spline_rigid_coefficients.csv'
    breaks_rigid = Yomiread.read_csv(breaks_file_rigid, len(control_list))[0]
    coe_rigid = Yomiread.read_csv(coe_file_rigid, 4)
    fine_rigid = i3d.pp_matlab(breaks_rigid, coe_rigid, 100)
    fine_ct_in_ios = fine_rigid
    #
    breaks_file_target = RESULT_TEM_BASE + 'spline_target_breaks.csv'
    coe_file_target = RESULT_TEM_BASE + 'spline_target_coefficients.csv'
    breaks_target = Yomiread.read_csv(breaks_file_target, len(control_list))[0]
    coe_target = Yomiread.read_csv(coe_file_target, 4)
    fine_ct_to_ios = i3d.pp_matlab(breaks_target, coe_target, 100)
Пример #9
0
barlength = Yomiread.read_barset(base + '\\barset_measurements.txt')
sb_bb = barlength[0] / 1000
mb_bb = barlength[1] / 1000
lb_bb = barlength[2] / 1000
print('barlength is', np.shape(barlength))
#
# sb_bb = 201.813/1000
# mb_bb = 265.456/1000
# lb_bb = 353.918/1000

sb = Yomiread.read_calibration_measurements(base + '\\sb1.m')[:, 6:13]
mb = Yomiread.read_calibration_measurements(base + '\\mb1.m')[:, 6:13]
lb = Yomiread.read_calibration_measurements(base + '\\lb1.m')[:, 6:13]
#s1 = Yomiread.read_calibration_measurements(base + '\\divot_s1_jointangles.m' )[:, 6:13]
#s2 = Yomiread.read_calibration_measurements(base + '\\divot_s2_jointangles.m' )[:, 6:13]
#s3 = Yomiread.read_calibration_measurements(base + '\\divot_s3_jointangles.m')[:, 6:13]

result = opt_full_bar_ball_data_check(sb, sb_bb, mb, mb_bb, lb, lb_bb)
print('result is', result)

# np.asarray(ball), mean, variance, stdev, bar_length_diff

time_stamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
if not os.path.exists(base + "\\result"):
    os.makedirs(base + "\\result")
filename1 = base + "\\result\\ball_bar_data_check.csv"
string = 'mean, variance, stdev, bar_length_diff'
#Yomiwrite.write_csv_string(filename1, string)
Yomiwrite.write_csv_matrix(filename1, result)
print('done')
Пример #10
0
z_premolar_2 = [130, 175]

# typodont dicom thresholds
THRESHOLD = -600  # original -350 - 5    # working case -600 200
THO_DELTA = 200

# dicom slice plot
plot_2D_slice(scan[z_premolar[0] + 10])

# trim molar and plot
HU_trim_molar, bone_surface_idx_molar = trim_slice(scan, x_molar, y_molar,
                                                   z_molar)
print('bone_surface_idx_molar is', bone_surface_idx_molar)
dicom_point_cloud = open3d_plot(bone_surface_idx_molar)
dicom_pc_file = 'G:\My Drive\Project\IntraOral Scanner Registration\dicom_points.csv'
Yomiwrite.write_csv_matrix(dicom_pc_file, dicom_point_cloud)

del HU_trim_molar

# trim premolar and plot
HU_trim_premolar, bone_surface_idx_premolar = trim_slice(
    scan, x_premolar, y_premolar, z_premolar)
dicom_point_cloud_premolar = open3d_plot(bone_surface_idx_premolar)
dicom_pc_2teeth_file = 'G:\My Drive\Project\IntraOral Scanner Registration\dicom_points_2teeth.csv'
dicom_point_cloud_2teeth = np.vstack(
    (dicom_point_cloud, dicom_point_cloud_premolar))
Yomiwrite.write_csv_matrix(dicom_pc_2teeth_file, dicom_point_cloud_2teeth)
#plot_3D_point_cloud(bone_surface_idx_premolar)
del HU_trim_premolar

# trim 2nd premolar and plot
Пример #11
0
stl_point_cloud = points
stl_pc_file = 'G:\My Drive\Project\IntraOral Scanner Registration\stl_points.csv'
#Yomiwrite.write_csv_matrix(stl_pc_file, stl_point_cloud)

pcd = open3d.PointCloud()
pcd.points = open3d.Vector3dVector(points)
#pcd.paint_uniform_color([0, 0.651, 0.929])
visualization.draw_geometries([pcd])

# extract premolar based on boundary
pre_molar_points = extract_vertex_boundary(your_mesh.points, premolar_x,
                                           premolar_y, premolar_z)
stl_point_cloud_2teeth = np.vstack((points, pre_molar_points))
stl_pc_file_2teeth = 'G:\My Drive\Project\IntraOral Scanner Registration\stl_points_2teeth.csv'
#Yomiwrite.write_csv_matrix(stl_pc_file_2teeth, stl_point_cloud_2teeth)
pcd_pre = open3d.PointCloud()
pcd_pre.points = open3d.Vector3dVector(pre_molar_points)
visualization.draw_geometries([pcd_pre])

# extract 2nd premolar based on boundary
pre_molar_points_2 = extract_vertex_boundary(your_mesh.points, premolar_x_2,
                                             premolar_y_2, premolar_z_2)
stl_point_cloud_3teeth = np.vstack(
    (stl_point_cloud_2teeth, pre_molar_points_2))
stl_pc_file_3teeth = 'G:\My Drive\Project\IntraOral Scanner Registration\stl_points_3teeth.csv'
Yomiwrite.write_csv_matrix(stl_pc_file_3teeth, stl_point_cloud_3teeth)
pcd_pre_2 = open3d.PointCloud()
pcd_pre_2.points = open3d.Vector3dVector(pre_molar_points_2)
visualization.draw_geometries([pcd_pre_2])
Пример #12
0
y_incisor = [25, 33]
z_incisor = [210.5, 230]

# cylinders near right molar in stl
x_cylinder = [10, 18.2]
y_cylinder = [-10.5, 7.5]
z_cylinder = [210.5, 230]

# extract incisor based on boundary
points_cylinder = extract_vertex_boundary(your_mesh.points, x_cylinder,
                                          y_cylinder, z_cylinder)
print('shape of points is', np.shape(points_cylinder))

stl_point_cloud_cylinder = points_cylinder
stl_pc_file_cylinder = 'G:\My Drive\Project\IntraOral Scanner Registration\stl_points_cylinder.csv'
Yomiwrite.write_csv_matrix(stl_pc_file_cylinder, stl_point_cloud_cylinder)

pcd_cylinder = open3d.PointCloud()
pcd_cylinder.points = open3d.Vector3dVector(points_cylinder)
#pcd.paint_uniform_color([0, 0.651, 0.929])
visualization.draw_geometries([pcd_cylinder])

# extract incisor based on boundary
points_incisor = extract_vertex_boundary(your_mesh.points, x_incisor,
                                         y_incisor, z_incisor)
print('shape of points is', np.shape(points_incisor))

stl_point_cloud_incisor = points_incisor
stl_pc_file_incisor = 'G:\My Drive\Project\IntraOral Scanner Registration\stl_points_incisor.csv'
#Yomiwrite.write_csv_matrix(stl_pc_file_incisor, stl_point_cloud_incisor)
Пример #13
0
    # ctl_source2 = []
    # for i in NEIGHBOUR_TOOTH_TARGET:
    #     ctl_target2.append(arch_ct.get_tooth(i).points)
    #     ctl_source2.append(arch_ct_in_ios.get_tooth(i).points)
    # ctl_source2 = combine_pc(ctl_source2)
    # ctl_target2 = combine_pc(ctl_target2)

    trans_init1 = arch_ios_splint_correction.get_tooth(17).local_ICP_transformation
    print('transformation check is', np.matmul(arch_ios_splint_correction.get_tooth(17).local_ICP_transformation, arch_ct.get_tooth(17).local_ICP_transformation))
    rigid_init_parameter1 = Yomikin.Yomi_parameters(trans_init1)
    if path.exists(RESULT_TEM_BASE + 'optimized_rigid_transformation_1st.csv'):
        trans_rigid = Yomiread.read_csv(RESULT_TEM_BASE + 'optimized_rigid_transformation_1st.csv', 4, 4)
    else:
        affine_rigid_part = affine_registration.rigid_registration(rigid_init_parameter1, ctl_ct, ctl_ios)
        trans_rigid = Yomikin.Yomi_Base_Matrix(affine_rigid_part)
        Yomiwrite.write_csv_matrix(RESULT_TEM_BASE + 'optimized_rigid_transformation_1st.csv', trans_rigid,
                                   fmt='%0.8f')

    yomi_plan_fiducial_ios_ct = transpose_pc(yomi_plan_fiducial_ios, trans_rigid)
    yomi_plan_fiducial_ct = transpose_pc(yomi_plan_fiducial_ground, trans_rigid)
    print('yomi_plan_fiducial difference is', yomi_plan_fiducial_ct-yomi_plan_fiducial_ios_ct)

    #fiducial_test = transpose_pc(yomi_plan_fiducial_ct, np.linalg.inv(trans_rigid))
    fiducial_test = yomi_plan_fiducial_ground
    fiducial_test = transpose_pc(fiducial_test, fiducial_frame)
    fiducial_test = transpose_pc(fiducial_test, golden_transformation)
    print('delta is', fiducial_test - yomi_plan_fiduial_fiducialFrame)

    mtx = np.matmul(golden_transformation, fiducial_frame)
    mtx = np.matmul(mtx, np.linalg.inv(trans_rigid))

    check_pc = transpose_pc(yomi_plan_fiducial_ct, mtx)
Пример #14
0
trial3 = Yomiread.read_csv(trial3_file, 4)[:,1:]
ground = Yomiread.read_csv(ground_file,4)[:,1:]

trans_init = np.eye(4)
rigid_init_parameter = Yomikin.Yomi_parameters(trans_init)
affine_rigid_part = affine_registration.rigid_registration(rigid_init_parameter, ground, trial3)
trans_rigid = Yomikin.Yomi_Base_Matrix(affine_rigid_part)

ground_transformed = transpose_pc(ground, np.linalg.inv(trans_rigid))
delta = trial3 - ground_transformed
print('delta is', trial3 - ground_transformed)
print('delta is', np.linalg.norm(delta, axis=1))

center_2 = np.array([-30.3, 6.5, 211])

Yomiwrite.write_csv_matrix(trial3_result, ground_transformed)

#fiducial_list = np.array([0, 1, 4, 7])
fiducial_list = np.array([1, 3, 6, 7])

splint_geometry = fe.Splint(fiducial_list, type='Geometry', spline_base_axis='x')
splint_ios = fe.Splint(fiducial_list, type='IOS', spline_base_axis='x')
splint_ios_corrected = fe.Splint(fiducial_list, type='IOS', spline_base_axis='x')

ground_transformed = np.flip(ground_transformed, 0)
trial3 = np.flip(trial3, 0)

ground_transformed_tem = np.copy(ground_transformed)
trial3_tem = np.copy(trial3)
print('ground_transformed_tem is', ground_transformed)
Пример #15
0

if __name__ == "__main__":
    stl_base = "G:\\My Drive\\Project\\HW-9232 Registration method for edentulous" \
               "\\Edentulous registration error analysis\\Typodont_scan\\Edentulous_scan\\"
    all_regions = []
    file = stl_base + 'full_arch.txt'
    if os.path.isfile(file):
        print('read txt')
        full_region = Yomiread.read_csv(file, 3, -1)
    else:
        stl_file = 'full_arch.stl'
        print('read stl')
        full_region = region_points.read_regions(stl_base + stl_file,
                                                 voxel_size=0.05)
        Yomiwrite.write_csv_matrix(stl_base + 'full_arch.txt', full_region)

    base = "G:\\My Drive\\Project\\HW-9232 Registration method for edentulous" \
           "\\Edentulous registration error analysis\\Stage2_more_regions\\"
    target_measurement_file = "targets.txt"
    points = Yomiread.read_csv(base + target_measurement_file, 4, 10, flag=1)
    targets_original = points[0:4, 1:4]

    arch1 = edentulous_arch.Edentulous_arch(full_region, targets_original)
    print('angle range is', arch1.target_angle_range)
    print('target position is',
          arch1.target_origins_cylindrical[:, 1] * 180 / np.pi)

    # Set up simulation conditions
    D_ANGLE = 3
    D_HEIGHT = 1
Пример #16
0
    fig1 = plt.figure()
    ax = fig1.add_subplot(111, projection='3d')
    Yomiplot.plot_3d_points(marker_ct_selected, ax, color='g')
    Yomiplot.plot_3d_points(marker_ga_selected, ax, color='blue')
    plt.show()
    # Point-pair registration (ct = R * ga + t)
    R, t = registration.point_set_registration(marker_ct_selected,
                                               marker_ga_selected)
    print('R is', R)
    print('t is', t)

    # Generate fiducial array in image space
    fiducial_array_fs = Yomiread.read_csv_specific_rows(FIDUCIAL_ARRAY_FS_FILE,
                                                        4, [3, -1],
                                                        delimiter=' ')[:, 1:]
    fiducial_array_ct = []
    for point in fiducial_array_fs:
        #fiducial_array_ct.append(np.matmul(R, point) + t)
        fiducial_array_ct.append(np.matmul(np.linalg.inv(R), (point - t)))
    fiducial_array_ct = np.asarray(fiducial_array_ct)
    Yomiwrite.write_csv_matrix(FIDUCIAL_ARRAY_CT_FILE,
                               fiducial_array_ct,
                               fmt='%.6f',
                               delim=' ')

    landmark_ct = np.array(
        [45.872546347336275, 47.517325926047029, 52.978035379603348])
    #landmark_fs = np.matmul(np.linalg.inv(R),(landmark_ct - t))
    landmark_fs = np.matmul(R, landmark_ct) + t
    print('landmark_fs is', landmark_fs)
Пример #17
0
    BIAS_ERROR_FLAG = 0
    ORIENTATION = 1

    stl_base = "G:\\My Drive\\Project\\HW-9232 Registration method for edentulous\\Edentulous registration error analysis\\Typodont_scan\\Edentulous_scan\\"
    all_regions = []

    for i in range(5):
        file = stl_base + 'region_points_' + np.str(i+1) + '.txt'
        if os.path.isfile(file):
            print('read txt')
            individual_region = Yomiread.read_csv(file,3,-1)
        else:
            stl_file = 'Fiducial_region_' + np.str(i+1) + '.stl'
            print('read stl')
            individual_region = region_points.read_regions(stl_base + stl_file, voxel_size = 2.0)
            Yomiwrite.write_csv_matrix(stl_base + 'region_points_' + np.str(i + 1) + '.txt', individual_region)
        all_regions.append(individual_region)

    for i in range(len(all_regions)):
        value_95 = []
        fiducials_new = np.copy(fiducials_original)
        mm = 0
        for point in all_regions[i]:
            print('checking point ', mm + 1)
            fiducials_new[i,:] = point
            #print('fiducials are ', fiducials_new)
            value_95_tem = check_tre(targets_original, fiducials_new)
            value_95.append(value_95_tem)
            if np.ndim(targets_original) == 1:
                if (value_95_tem < THRESHOLD_0):
                    green_point.append(point)
Пример #18
0
z_incisor = [130, 176]

# typodont dicom thresholds
THRESHOLD = -600  # original -350 - 5    # working case -600 200   # -50 60
THO_DELTA = 200

# dicom slice plot
#plot_2D_slice(scan[z_premolar[0] + 10])

# trim incisor and plot
HU_trim_incisor, bone_surface_idx_incisor = trim_slice(scan, x_incisor,
                                                       y_incisor, z_incisor)
dicom_point_cloud_incisor = open3d_plot(bone_surface_idx_incisor)
dicom_pc_incisor_file = 'G:\My Drive\Project\IntraOral Scanner Registration\dicom_points_incisor.csv'
#dicom_point_cloud_3teeth = np.vstack((dicom_point_cloud_2teeth, dicom_point_cloud_premolar_2))
Yomiwrite.write_csv_matrix(dicom_pc_incisor_file, dicom_point_cloud_incisor)
del HU_trim_incisor

# trim molar and plot
HU_trim_molar, bone_surface_idx_molar = trim_slice(scan, x_Rmolar1, y_Rmolar1,
                                                   z_Rmolar1)
print('bone_surface_idx_molar is', bone_surface_idx_molar)
dicom_point_cloud = open3d_plot(bone_surface_idx_molar)
dicom_pc_file = 'G:\My Drive\Project\IntraOral Scanner Registration\dicom_points_Rmolar1.csv'
#Yomiwrite.write_csv_matrix(dicom_pc_file, dicom_point_cloud)

del HU_trim_molar

# trim premolar and plot
HU_trim_premolar, bone_surface_idx_premolar = trim_slice(
    scan, x_Rmolar2, y_Rmolar2, z_Rmolar2)
Пример #19
0
        point, point_cylindrical,
        splint_ios.spline_points_fine_cylindrical_mid_points, displacement)
    print('moved point is', point_moved)
    print('target point is', splint_geometry.get_pyramid(i))
    splint_ios_corrected.add_pyramid(i, point_moved)

diff_before = np.asarray(splint_geometry.pyramid_points) - np.asarray(
    splint_ios.pyramid_points)
diff_after = np.asarray(splint_geometry.pyramid_points) - np.asarray(
    splint_ios_corrected.pyramid_points)
diff_before_norm = np.linalg.norm(diff_before, axis=1)
diff_after_norm = np.linalg.norm(diff_after, axis=1)
diff_before_norm_2d = np.linalg.norm(diff_before[:, 0:2], axis=1)
diff_after_norm_2d = np.linalg.norm(diff_after[:, 0:2], axis=1)

Yomiwrite.write_csv_matrix(v2_result_2_before, diff_before_norm)
Yomiwrite.write_csv_matrix(v2_result_2_after, diff_after_norm)

print('point is', splint_geometry.pyramid_points)

fig1 = plt.figure()
plt.scatter(range(
    np.shape(splint_geometry.spline_points_fine_cylindrical_mid_points)[0]),
            splint_geometry.spline_points_fine_cylindrical_mid_points,
            label='theta check')
#plt.scatter(range(np.shape(splint_geometry.spline_points_fine_cylindrical_mid_points)[0]), splint_geometry.spline_points_fine_cylindrical_mid_points[:,0], label='r check')
#plt.scatter(range(np.shape(splint_geometry.spline_points_fine)[0]), splint_geometry.spline_points_fine[:,1], label='y check')
#plt.scatter(range(np.shape(splint_geometry.spline_points_fine)[0]), splint_geometry.spline_points_fine[:,0], label='x check')
plt.legend()

fig2 = plt.figure(2)
        print('maximum 95% value is', max_value_95)
        print('minimum 95% value is', min_value_95)
    #value_95, model = check_tre(targets_original, fiducials_original)

    #green_file = "Results\\" + np.str(N_REGION) + "_region_" + np.str(RAN_MEAN) + "_random_tolerance_green.txt"
    #yellow_file = "Results\\" + np.str(N_REGION) + "_region_" + np.str(MEAN) + "_tolerance_yellow.txt"
    #red_file = "Results\\" + np.str(N_REGION) + "_region_" + np.str(MEAN) + "_tolerance_red.txt"

    #Yomiwrite.write_csv_matrix(base+green_file, green_point)
    #Yomiwrite.write_csv_matrix(base + yellow_file, yellow_point)
    #Yomiwrite.write_csv_matrix(base + red_file, red_point)

    for i in range(N_REGION):
        Yomiwrite.write_csv_matrix(
            base + "Results\\" + np.str(N_REGION) + "_region_" +
            np.str(RAN_MEAN) + "_random_tolerance_and " + np.str(BIAS_MEAN) +
            "_bias_tolerance_value_95_region_" + np.str(i + 1) + ".txt",
            total_value_95[i])
        Yomiwrite.write_csv_matrix(
            base + "Results\\" + np.str(N_REGION) + "_region_" +
            np.str(RAN_MEAN) + "_random_tolerance_and " + np.str(BIAS_MEAN) +
            "_bias_tolerance_points_region_" + np.str(i + 1) + ".txt",
            all_vertex[i])

    fig1 = plt.figure()
    ax = fig1.add_subplot(111, projection='3d')
    if len(green_point) > 0:
        Yomiplot.plot_3d_points(np.asarray(green_point), ax, color='g')
    if len(yellow_point) > 0:
        Yomiplot.plot_3d_points(np.asarray(yellow_point), ax, color='y')
    if len(red_point) > 0:
    # ctl_source2 = []
    # for i in NEIGHBOUR_TOOTH_TARGET:
    #     ctl_target2.append(arch_ct.get_tooth(i).points)
    #     ctl_source2.append(arch_ct_in_ios.get_tooth(i).points)
    # ctl_source2 = combine_pc(ctl_source2)
    # ctl_target2 = combine_pc(ctl_target2)

    trans_init1 = arch_ios_splint_correction.get_tooth(17).local_ICP_transformation
    print('transformation check is', np.matmul(arch_ios_splint_correction.get_tooth(17).local_ICP_transformation, arch_ct.get_tooth(17).local_ICP_transformation))
    rigid_init_parameter1 = Yomikin.Yomi_parameters(trans_init1)
    if path.exists(RESULT_TEM_BASE + 'optimized_rigid_transformation_1st.csv'):
        trans_rigid = Yomiread.read_csv(RESULT_TEM_BASE + 'optimized_rigid_transformation_1st.csv', 4, 4)
    else:
        affine_rigid_part = affine_registration.rigid_registration(rigid_init_parameter1, ctl_ct, ctl_ios)
        trans_rigid = Yomikin.Yomi_Base_Matrix(affine_rigid_part)
        Yomiwrite.write_csv_matrix(RESULT_TEM_BASE + 'optimized_rigid_transformation_1st.csv', trans_rigid,
                                   fmt='%0.8f')

    FIDUCIAL_ARRAY_FS_FILE = "C:\\Neocis\\FiducialArrays\\FXT-0086-07-LRUL-MFG-Splint.txt"
    fiducial_array_fs = Yomiread.read_csv_specific_rows(FIDUCIAL_ARRAY_FS_FILE, 4, [3, -1], delimiter=' ')[:,1:]

    fiducial_array_ct = transpose_pc(fiducial_array_fs, trans_rigid)
    fiducial_array_ct_2 = transpose_pc(fiducial_array_fs, np.linalg.inv(trans_rigid))

    FIDUCIAL_ARRAY_CT_FILE = RESULT_TEM_BASE + "fiducials_array_cadaver_lab_ios1.txt"
    Yomiwrite.write_csv_matrix(FIDUCIAL_ARRAY_CT_FILE, fiducial_array_ct, fmt='%.6f', delim=' ')
    FIDUCIAL_ARRAY_CT_FILE_2 = RESULT_TEM_BASE + "fiducials_array_cadaver_lab_ios2.txt"
    Yomiwrite.write_csv_matrix(FIDUCIAL_ARRAY_CT_FILE_2, fiducial_array_ct_2, fmt='%.6f', delim=' ')

    draw_registration_result_points_array(ctl_ios, ctl_ct, trans_rigid)
Пример #22
0
    ctl_target2 = []
    ctl_source2 = []
    for i in NEIGHBOUR_TOOTH_TARGET:
        ctl_target2.append(arch_ct.get_tooth(i).points)
        ctl_source2.append(arch_ct_in_ios.get_tooth(i).points)
    ctl_source2 = combine_pc(ctl_source2)
    ctl_target2 = combine_pc(ctl_target2)

    trans_init1 = arch_ct.get_tooth(17).local_ICP_transformation
    rigid_init_parameter1 = Yomikin.Yomi_parameters(trans_init1)
    if path.exists(RESULT_TEM_BASE + 'optimized_rigid_transformation_1st.csv'):
        trans_rigid = Yomiread.read_csv(RESULT_TEM_BASE + 'optimized_rigid_transformation_1st.csv', 4, 4)
    else:
        affine_rigid_part = affine_registration.rigid_registration(rigid_init_parameter1, ctl_source, ctl_target)
        trans_rigid = Yomikin.Yomi_Base_Matrix(affine_rigid_part)
        Yomiwrite.write_csv_matrix(RESULT_TEM_BASE + 'optimized_rigid_transformation_1st.csv', trans_rigid,
                                   fmt='%0.8f')

    yomi_plan_fiducial_ios = transpose_pc(yomi_plan_fiducial_ios, modify_matrix2)
    yomi_plan_fiducial_ct = transpose_pc(yomi_plan_fiducial_ios, np.linalg.inv(trans_rigid))

    fiducial_test = transpose_pc(yomi_plan_fiducial_ct, trans_rigid)
    fiducial_test = transpose_pc(fiducial_test, np.linalg.inv(modify_matrix2))
    fiducial_test = transpose_pc(fiducial_test, np.linalg.inv(modify_matrix))
    fiducial_test = transpose_pc(fiducial_test, trans_rigid0)
    fiducial_test = transpose_pc(fiducial_test, fiducial_frame)
    fiducial_test = transpose_pc(fiducial_test, golden_transformation)
    print('delta is', fiducial_test - yomi_plan_fiduial_fiducialFrame)

    mtx = np.matmul(golden_transformation, fiducial_frame)
    mtx = np.matmul(mtx, trans_rigid0)
    mtx = np.matmul(mtx, np.linalg.inv(modify_matrix))
Пример #23
0
            arch_ct_in_ios_curvilinear_correction.get_spline_points(i))
        # correction_spline.append(arch_ct_in_ios.get_spline_points(i))
    corrected_spline = np.asarray(corrected_spline)
    # original_spline = np.asarray(original_spline)
    # correction_spline = np.asarray(correction_spline)

    original_full_spline = np.asarray(original_full_spline)
    fig1 = plt.figure()
    plt.scatter(range(len(correction_error)), correction_error)
    plt.savefig(RESULT_TEM_BASE + "matching_error_missing_teeth" +
                np.str(MISSING_TOOTH_NUMBER[0]) + '_' +
                np.str(MISSING_TOOTH_NUMBER[1]) + '_' +
                np.str(MISSING_TOOTH_NUMBER[2]))
    Yomiwrite.write_csv_matrix(
        RESULT_TEM_BASE + "matching_error_missing_teeth" +
        np.str(MISSING_TOOTH_NUMBER[0]) + '_' +
        np.str(MISSING_TOOTH_NUMBER[1]) + '_' +
        np.str(MISSING_TOOTH_NUMBER[2]) + '.txt', correction_error)

    fig2 = plt.figure()
    plt.scatter(original_full_spline[:, 0],
                original_full_spline[:, 1],
                label='Spline Landmarks',
                color='red')
    plt.plot(arch_ct_to_ios.spline_guided_points_fine[:, 0],
             arch_ct_to_ios.spline_guided_points_fine[:, 1],
             '-',
             label='Fitted Spline',
             color='green')
    # plt.scatter(corrected_spline[:, 0], corrected_spline[:, 1], label='corrected spline', color='blue')
    # plt.plot(test[:,0], test[:,1], label='test')