def find_segmented_regions(seeds, autof_stack, imsave):

    min_autof_proj = min_intensity_projection(autof_stack)
    equal_autof = equalize_adaptive(min_autof_proj, "equal_autof")
    smoothed_autof = gaussian_filter(equal_autof, sigma=5, name="smooth_autof")
    edge_autof = find_edges(smoothed_autof, name="edge_autof")
    thresh_autof = threshold_otsu(smoothed_autof, mult=0.6, name="thresh_autof")

    # ndfeed = skimage.img_as_uint(edge_autof.image_array & thresh_autof)
    # imsave('ndfeed.png', ndfeed)
    # altseg = watershed_ift(ndfeed, seeds.image_array)
    # imsave('altseg.png', altseg)

    # segmentation = watershed_with_seeds(smoothed_autof, ImageArray(altseg, 'atseg'),
    segmentation = watershed_with_seeds(smoothed_autof, seeds, mask_image=thresh_autof)

    # my_maker = make_named_transform('hughbert')
    # my_filter = my_maker(filter_segmentation)
    # filtered_segmentation = my_filter(segmentation)
    filtered_segmentation = filter_segmentation(segmentation)

    re_watershed = watershed_with_seeds(
        smoothed_autof, filtered_segmentation, mask_image=thresh_autof, name="re_watershed"
    )

    return re_watershed
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
Example #3
0
def hough_stuff(imsave):
    """Deprecated. Template matching works better."""
    thresh = threshold_otsu(edges, mult=1.5)

    hough_radii = np.arange(1, 3, 1)
    hough_res = skimage.transform.hough_circle(thresh.image_array, hough_radii)
    hough_data = hough_res[0] + hough_res[1]
    #loc_array = peak_local_max(hough_data, min_distance=5, threshold_rel=0.5)
    cloc_array = peak_local_max(hough_data, min_distance=5, threshold_rel=0.5, indices=False)
    imsave('cloc.png', cloc_array)
    connected_components, n_cc = skimage.measure.label(cloc_array, neighbors=8, return_num=True)

    labels = np.unique(connected_components)

    annot = np.zeros((512, 512, 3), dtype=np.uint8)
    annot[:,:] = 255, 255, 255
    annot[np.where(thresh.image_array)] = [0, 0, 0]

    def draw_cross(x, y, c):
        for xo in np.arange(-4, 5, 1):
            annot[x+xo, y] = c
        for yo in np.arange(-4, 5, 1):
            annot[x,y+yo] = c

    probe_locs = []
    for label in labels:
        coord_list = zip(*np.where(connected_components == label))
        probe_locs.append(coord_list[0])

    for coords in probe_locs:
        x, y = coords
        c = random_rgb()
        draw_cross(x, y, c)
    
    imsave('probe_locations.png', annot)
    #print '\n'.join(thresh.history)

    return probe_locs