I use napari to define ROIs for a number of different image stacks. To do this, I use a Jupyter notebook with a for loop that runs through all of my stacks. This loop relies on an imported function that calls napari and then extracts shapes from a layer in the viewer. Here’s the function:
def getROIs(stack, roiFN, oldROIs, oldType): """ Use napari to get ROIs from a stack, using a given ROI function """ # Load the stack in napari viewer = napari.Viewer() viewer.add_image(stack) if len(oldROIs) > 0: viewer.add_shapes(oldROIs, shape_type=oldType, name = 'Shapes') napari.run() # Use the ROIs that were drawn in napari to get image masks [napOut, allROIs, allMasks] = roiFN(viewer, stack) return [napOut, allROIs, allMasks]
I originally ran this function on my Windows machine, using napari 0.4.4 and
with napari.gui_qt() at the beginning instead of
napari.run() at the end. In that case, my code waited until I defined my ROIs and closed the napari window to advance to the
[napOut, allROIs, allMasks] = roiFN(viewer, stack) line. I am now trying to run it on my Mac using napari 0.4.7, and it automatically advances to the
[napOut, allROIs, allMasks] = roiFN(viewer, stack) line without waiting (regardless of whether I use
with naprit.gui_qt()). What am I missing?