Exemplo n.º 1
0
def load_stack_and_segment(path, imsave):
    """Load a stack from the given path and segment it."""

    autof_stack = Stack.from_path(path, channel=2)
    nuclear_stack = Stack.from_path(path, channel=2)

    return segmentation_from_stacks(nuclear_stack, autof_stack, imsave)
Exemplo n.º 2
0
def find_probe_locations(stack_dir, imsave, pchannel):
    """Find probe locations. Given a path, we construct a z stack from the first
    channel of the images in that path, and then find probes within that stack.
    Returns a list of coordinate pairs, representing x, y locations of probes.
    """

    zstack = Stack.from_path(stack_dir, channel=pchannel)
    # For comparative purposes (so we save the image)
    projection = max_intensity_projection(zstack)
    # Normalise each image in the stack
    norm_stack = normalise_stack(zstack)
    # Now take a maximum intensity projection
    norm_projection = max_intensity_projection(norm_stack, 'norm_projection')
    # Find edges should show the circle-like probes as annuli
    edges = find_edges(norm_projection)

    # Find a suitable template image for matching
    template = find_best_template(edges, imsave)

    match_result = match_template(edges.image_array, template, pad_input=True)
    imsave('stage2_match.png', match_result)

    # Set a threshold for matched locations

    match_thresh = 0.6

    print "t,c"
    for t in np.arange(0.1, 1, 0.05):
        print "{},{}".format(t, len(np.where(match_result > t)[0]))

    locs = np.where(match_result > match_thresh)
    annotated_edges = grayscale_to_rgb(edges.image_array)
    annotated_edges[locs] = edges.image_array.max(), 0, 0
    imsave('annotated_edges.png', annotated_edges)

    # Find the centroids of the locations where we think there's a probe
    cloc_array = match_result > match_thresh
    ia_locs = ImageArray(cloc_array, name='new_cloc')
    connected_components = find_connected_components(ia_locs)
    centroids = component_centroids(connected_components)
    probe_locs = zip(*np.where(centroids.image_array != 0))

    generate_probe_loc_image(norm_projection, probe_locs, imsave)

    return probe_locs