def visualize_direction(seg, segment_id): import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D SUBSAMPLE_TARGET = 500 MIN_SAMPLE_STRIDE = 10 BOX_RADIUS = 110 binary_volume1 = imio.extract_segments(seg, [segment_id]) all_points_1 = points_from_binary_volume(binary_volume1) print all_points_1.shape center = random_edge_point(all_points_1, seg) binary_volume2 = imio.extract_segments(seg, [seg[tuple(center)]]) all_points_2 = points_from_binary_volume(binary_volume2) stretch_dimension(all_points_1, 0, 5) stretch_dimension(all_points_2, 0, 5) vectors = features.direction.compute_pc_vectors( all_points_1, all_points_2, center, BOX_RADIUS, SUBSAMPLE_TARGET, MIN_SAMPLE_STRIDE ) cropped_points_1 = features.direction.limit_to_radius( all_points_1, center, BOX_RADIUS, SUBSAMPLE_TARGET, MIN_SAMPLE_STRIDE ) cropped_points_2 = features.direction.limit_to_radius( all_points_2, center, BOX_RADIUS, SUBSAMPLE_TARGET, MIN_SAMPLE_STRIDE ) print "pc vectors:", vectors print "feature vector:", features.direction.compute_feature_vector(vectors) center_of_1 = cropped_points_1.mean(axis=0) center_of_2 = cropped_points_2.mean(axis=0) svd_1_points = generate_points_on_vector(vectors[0, :], center_of_1, BOX_RADIUS) svd_2_points = generate_points_on_vector(vectors[1, :], center_of_2, BOX_RADIUS) between_center_points = generate_points_on_vector( vectors[2, :], center_of_2, np.sqrt((center_of_1 - center_of_2).dot(center_of_1 - center_of_2)).astype(np.integer), ) fig = plt.figure() ax = fig.add_subplot(111, projection="3d") for points, color, marker in [ (cropped_points_2, "b", "o"), (cropped_points_1, "y", "s"), (svd_1_points, "g", "^"), (svd_2_points, "r", "v"), (between_center_points, "k", "<"), ]: print points.shape ax.scatter(points[:, 2], points[:, 1], points[:, 0], c=color, marker=marker) plt.show()
def view_biggest_cross_section(seg, segment_ids): extracted = imio.extract_segments(seg, segment_ids) biggest_index = np.argmax(extracted.sum(axis=2).sum(axis=1)) disp = np.zeros_like(seg) disp[biggest_index, :, :] = extracted[biggest_index, :, :] mayavi.mlab.contour3d(disp) mayavi.mlab.show()
def view_mistake(seg, gt, target_id, overlap_ids, seg_color_map, gt_color_map): fig = mayavi.mlab.gcf() # display attempts for idx, overlap_id in enumerate(overlap_ids): extracted = imio.extract_segments(seg, [overlap_id]) unsquished = np.repeat(extracted, 5, axis=0) color = seg_color_map(idx, len(overlap_ids)) print "Writing contour with color " + str(color) mayavi.mlab.contour3d(unsquished, color=color, figure=fig) # display target extracted = imio.extract_segments(gt, [target_id]) unsquished = np.repeat(extracted, 5, axis=0) color = gt_color_map(0, 1) mayavi.mlab.contour3d(unsquished, color=color, figure=mayavi.mlab.figure()) mayavi.mlab.show()
def view_segments(seg, segment_ids): fig = maya.mlab.gcf() extracted = imio.extract_segments(seg, segment_ids) unsquished = np.repeat(extracted, 5, axis=0) mayavi.mlab.contour3d(unsquished) mayavi.mlab.show()