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
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