Exemplo n.º 1
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
Exemplo n.º 2
0
def generate_segmentation_seeds(nuclear_stack):
    """Given the nuclear fluorescence channel, find markers representing the
    locations of those nuclei so that they can be used to seed a segmentation.
    """

    normed_stack = normalise_stack(nuclear_stack)
    max_nuclear_proj = max_intensity_projection(normed_stack)
    eq_proj = equalize_adaptive(max_nuclear_proj, n_tiles=16, name="equalized_nuclear_proj")
    gauss = gaussian_filter(eq_proj, sigma=3)
    edges = find_edges(gauss, name="seed_edges")
    thresh = threshold_otsu(edges, mult=1)
    nosmall = remove_small_objects(thresh, min_size=500)
    # dilated = dilate_simple(nosmall)
    connected_components = find_connected_components(nosmall, background=0, name="conn_seeds")
    seeds = component_centroids(connected_components, name="seed_centroids")

    return seeds