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