Drawing and generating ROIs¶
ROIs live in the rois Labels layer of the viewer. You can paint them by hand or let twopy generate them.
twopy draws and shows ROIs on the alignment-valid crop — the part of every frame that stays in-field after motion correction. When you save or run analysis, the ROIs are converted back to full-frame coordinates automatically. You can ignore this; it just means response updates only work while the active Labels layer matches the displayed crop.
Draw by hand¶
Select the
roislayer in the layer list.Pick the paint tool in the napari layer controls (top-left).
Set the
labelnumber before painting each cell so each ROI gets its own number.Edit existing ROIs with the same tool; commit the edit (release the mouse) and the response plots update.
Generate from the ROIs tab¶
The ROIs tab has a Create ROIs section with a Mode dropdown:
manual — leaves the layer alone for hand-drawing.
grid — square template ROIs covering the crop. Choose Units = pixels for an exact pixel width, or Units = microns to convert from a physical width using the pixel calibration registry. Micron mode prefills known calibration fields (rig, mode, scanner, zoom) from converted metadata; if a field is missing it is left unselected rather than guessed.
watershed — segments bright structures from the displayed mean-image crop. Tune Min pixels and Smoothing (sigma). Min pixels uses the same displayed crop pixels shown in the area (px) column.
response watershed — segments stimulus-locked pixel responses from photodiode-aligned epoch windows. Tune Response min pixels and Response smoothing. Fill response holes is on by default; Response closing adds an opt-in conservative binary close for tiny same-basin gaps.
Click Create ROIs to replace the contents of the rois Labels layer with the generated mask set.
Hide or remove ROIs¶
The ROIs tab also shows a per-ROI table:
area (px) shows how many displayed crop pixels belong to each ROI.
Hide a row to keep its mask but exclude it from response plots and saved analysis.
Merge Selected combines the checked rows into the first checked ROI label, then updates response plots from the combined mask.
Remove Selected drops the checked rows from the Labels layer outright.
For dense grids that cover the whole crop, prefer shared y-stripe P% background correction (in the Plot tab) over ROI y-stripe P% — the latter needs dim unlabeled local background pixels. It also stops before dF/F when local pixels are brighter than the ROI baseline, because that means the selected band is not valid additive background.
Persistence¶
ROI masks are saved in twopy’s own HDF5 format independently from napari. If a rois.h5 file sits beside the converted recording, twopy loads it automatically when you open the recording.
When you save from the app, rois.h5 also records the ROI mode and generator settings for the current masks. Generated modes save only the settings that apply to that mode, such as watershed Min pixels and Smoothing or grid size and micron-calibration fields. If you edit generated masks by hand before saving, the file marks that the saved masks changed after generation. Reload saved analysis reloads the masks, restores those ROIs-tab settings, and shows that edit marker. Older ROI files without this metadata still load their masks normally and leave the ROI mode at the default manual setting.