plt.imshow(skeleton)
plt.plot(corners[:,1], corners[:,0], 'ro')
plt.title('ridge skeleton w/ branch points')
plt.axis('off')
plt.subplot(223)
plt.imshow(skeleton)
plt.autoscale(False)
plt.plot(corners[:,1], corners[:,0], 'ro')
plt.title('ridge skeleton w/ branch points')
plt.subplot(224)
plt.imshow(edge_dist)
plt.title('distance transform of skeleton')
plt.axis('off')
plt.ioff()
plt.show()


# show an animation of the fitting procedure
fig = plt.figure()
plt.imshow(im, cmap='gray')
plt.plot(x, y, 'bo')
line_obj, = plt.plot(x, y, 'ro')
plt.axis('off')
    
plt.ion()
plt.pause(0.01)
snake_pts = fit_snake(boundary_pts, edge_dist, nits=60, alpha=0.5, beta=0.2, point_plot=line_obj)
plt.ioff()
plt.pause(0.01)
plt.show()
    
Example #2
0
    # allocate array
    all_boundary_pts = np.empty((len(frames), boundary_pts.shape[0], boundary_pts.shape[1]))

    # Frame-by-frame snake fit. This is fairly slow; takes ~80 sec on my laptop.
    tsta = time.clock()
    print('Tracking cell %i across %i frames...' % (selected_label, len(frames)))
    for frame_num, frame in enumerate(frames):

        # print progress
        if frame_num%10 == 0:
            print('Frame %i of %i' % (frame_num, len(frames)))
            sys.stdout.flush()

        # compute distance transforms and fit snake
        edge_dist, corner_dist = frame_to_distance_images(frame)
        boundary_pts = fit_snake(boundary_pts, edge_dist, alpha=alpha, beta=beta, nits=40)

        # check if the cell went off the edge (i.e., out of view)
        single_cell_mask = measure.grid_points_in_poly(frame.shape, boundary_pts)
        if np.any(np.logical_and(~mask, single_cell_mask)):
            print('cell went off edge on frame %i' % frame_num)
            all_boundary_pts = np.delete(all_boundary_pts, np.s_[frame_num:], 0)
            break

        # TODO: resample the points along the curve to maintain contant spacing?
        # store results in big array
        all_boundary_pts[frame_num] = boundary_pts

    print('elapsed time:', time.clock() - tsta)

    ### write boundary points to file
Example #3
0
    # allocate array
    all_boundary_pts = np.empty((len(frames), boundary_pts.shape[0], boundary_pts.shape[1]))

    # Frame-by-frame snake fit. This is fairly slow; takes ~80 sec on my laptop.
    tsta = time.clock()
    print 'Tracking cell %i across %i frames...' % (selected_label, len(frames))
    for frame_num, frame in enumerate(frames):

        # print progress
        if frame_num%10 == 0:
            print 'Frame %i of %i' % (frame_num, len(frames))
            sys.stdout.flush()

        # compute distance transforms and fit snake
        edge_dist, corner_dist = frame_to_distance_images(frame)
        boundary_pts = fit_snake(boundary_pts, edge_dist, alpha=alpha, beta=beta, nits=40)

        # check if the cell went off the edge (i.e., out of view)
        single_cell_mask = measure.grid_points_in_poly(frame.shape, boundary_pts)
        if np.any(np.logical_and(~mask, single_cell_mask)):
            print 'cell went off edge on frame %i' % frame_num
            all_boundary_pts = np.delete(all_boundary_pts, np.s_[frame_num:], 0)
            break

        # TODO: resample the points along the curve to maintain contant spacing?
        # store results in big array
        all_boundary_pts[frame_num,:,:] = boundary_pts

    print 'elapsed time:', time.clock() - tsta

    ### write boundary points to file
plt.subplot(223)
plt.imshow(skeleton)
plt.autoscale(False)
plt.plot(corners[:, 1], corners[:, 0], 'ro')
plt.title('ridge skeleton w/ branch points')
plt.subplot(224)
plt.imshow(edge_dist)
plt.title('distance transform of skeleton')
plt.axis('off')
plt.ioff()
plt.show()

# show an animation of the fitting procedure
fig = plt.figure()
plt.imshow(im, cmap='gray')
plt.plot(x, y, 'bo')
line_obj, = plt.plot(x, y, 'ro')
plt.axis('off')

plt.ion()
plt.pause(0.01)
snake_pts = fit_snake(boundary_pts,
                      edge_dist,
                      nits=60,
                      alpha=0.5,
                      beta=0.2,
                      point_plot=line_obj)
plt.ioff()
plt.pause(0.01)
plt.show()