dv = mm.displays().get_active_data_viewer() ds = dv.get_datastore() cb = mm.data().get_coords_builder() coord = cb.c(0).t(0).p(0).z(0).build() img = ds.get_image(coord) pixels = np.reshape(img.get_raw_pixels(), newshape=[img.get_height(), img.get_width()]) # find organelles using a combination of thresholding and watershed segmented = find_blobs(pixels, threshold_otsu(pixels), 500, 200) label_img = label(segmented) label_img = morphology.remove_small_objects(label_img, 5) blobs = regionprops(label_img) # select two sizes, small and large. Select those that are away from the border centered = select(blobs, 'centroid', img.get_width() / 10, 0.9 * img.get_width()) small = select(centered, 'area', 5, 45) large = select(centered, 'area', 90, 600) # for each, select up to 10, but no more than half of the spots, and send them to SLM nr = 20 projector.enable_point_and_shoot_mode(True) mm.acquisitions().run_acquisition_nonblocking() # Trick to get timing right. Wait for Core to report that Sequence is running while not mmc.is_sequence_running(mmc.get_camera_device()): time.sleep(0.1) time.sleep(0.5) for region_list in [small, large]: nr_shots = nr if len(region_list) >= (2 * nr) else int(len(region_list) / 2) shots = random.sample(region_list, nr_shots) # shots = region_list[0:10]
count -= 1 else: count = 0 if calibrated: continue count += 1 img = mm.live().snap(False).get(0) pixels = np.reshape(img.get_raw_pixels(), newshape=[img.get_height(), img.get_width()]) # find organelles using a combination of thresholding and watershed _, segmented = find_organelle(pixels, 'local-nucleoli', 500, 200, 10, 1000) label_img = label(segmented) label_img = morphology.remove_small_objects(label_img, 5) blobs = regionprops(label_img) centered = select(blobs, 'centroid', img.get_width() / 10, 0.9 * img.get_width()) if len(centered) > (nr // 2): projector.enable_point_and_shoot_mode(True) ssb = mm.acquisitions().get_acquisition_settings().copy_builder() mm.acquisitions().set_acquisition_settings( ssb.prefix(pos.get_label()).build()) ds = mm.acquisitions().run_acquisition_nonblocking() # Trick to get timing right. Wait for Core to report that Sequence is running while not mmc.is_sequence_running(mmc.get_camera_device()): time.sleep(0.1) time.sleep(1.5) for region_list in [centered]: nr_shots = nr if len(region_list) >= (2 * nr) else int( len(region_list) / 2)
# reference image of time 0 # if decide to use other image as ref_image # be sure to check photobleaching correction for all reported intensities temp = store.get_image(cb.c(data_c).t(0).build()) pix = np.reshape(temp.get_raw_pixels(), newshape=[temp.get_height(), temp.get_width()]) _, organelle = find_organelle(pix, thresholding, min_size=min_size, max_size=max_size) label_organelle = label(organelle, connectivity=1) blobs = regionprops(label_organelle) selected = select(blobs, 'centroid', temp.get_width() / 10, 0.9 * temp.get_width()) print(selected) spots = obj.select_random_in_label(label_organelle, 1) if display_mode == 'Y': print("### Output display ...") with napari.gui_qt(): # embed mpl widget in napari viewer mpl_widget = FigureCanvas(Figure(figsize=(5, 3))) [ax1, ax2, ax3] = mpl_widget.figure.subplots(nrows=1, ncols=3) viewer = napari.Viewer() viewer.window.add_dock_widget(mpl_widget) # napari display