A simple plugin to help with analyzing cells in napari
This napari plugin was generated with Cookiecutter using @napari's cookiecutter-napari-plugin template.
You can install mmv_h4cells via pip:
pip install mmv_h4cells
To install latest development version :
pip install git+https://github.com/MMV-Lab/mmv_h4cells.git
This plugin was developed for semi-automatic cell analysis to determine cell sizes of individual cells.
The core functionality includes the option to include or exclude individual (cell) instances in the evaluation via the include/exclude button. After a decision has been made, the plugin automatically centers on the next instance and a new decision can be made. In addition, you can include multiple cells at the same time using the "select multiple" function. It is also possible to analyze entire ROIs at once.
To get started, an instance segmentation must be loaded. This can be done simply via drag & drop. A raw image of the original data is optional, but certainly helps when deciding whether to include or exclude. Once the layers have been loaded into napari, the plugin can be started. If you have only interrupted the evaluation and exported the previous results, you can now import them again (the segmentation must be reloaded into napari).
The analysis can be started by clicking on the "Start analysis" button. The next instance ID to be evaluated is shown next to "Start analysis at". To change the region of interest to be evaluated, a different ID can be entered there and the plugin will center on this within the next 2 decisions. Decisions are made by clicking the Include/Exclude button. If an instance is not completely recognized correctly, you can use the paint function of napari to correct this manually and then include the instance as usual using the button. The undo function can be used to undo the last decision and the "Draw own cell" button allows you to add unrecognized cells manually. This must be done cell by cell and confirmed each time using the button. The plugin does not allow other existing instances to be painted over. If this happens by mistake, a warning is displayed, oberlapping pixels are highlighted and users can either cancel via the cancel button within the warning or close the warning and correct this manually.
When an instance is included, the respective instance is written to a segmentation layer, which can be exported using the export function. Exporting under a name creates three items next to each other:
name.csv: the ID, the size [px] and the centroid of every included cell, followed by the mean, the standard deviation and the threshold of the sizes.name.tiff: the segmentation of the included cells (OME-TIFF).name.zarr: a folder that holds everything needed to continue the analysis later, for example to pause it: the segmentation without the excluded cells, the included and the excluded cells, the metrics and the history for the undo function.
To import a session, select the .csv; the .zarr folder is found by its name. To enable a smooth re-import, the .csv and the .zarr folder must have the same name stem, so please either do not rename them or rename them in the same way. If the folder is not found next to the .csv, you are asked to select it. Do not move or change the files inside the .zarr folder.
For a better overview, the included/excluded/remaining instances can be viewed using the buttons at the bottom.
We also support the option of including several cells at once. To do so, the respective IDs must be entered at the bottom next to "Include" and then selected using the "Select multiple". This works by entering comma-separated IDs, so 1,5,100,17 would be a valid entry.
Entire ROIs can also be analyzed. To do this, simply enter the corner pixels in the "Range x" and "Range y" fields. All cells > the threshold are included; if, for example, cells that lie exactly at the edge of the ROI and are partially cut off are to be excluded, a corresponding threshold must be set.
Note: Exported ROIs cannot be re-imported.
k- Includeg- Excludej- Change visibility of all label layers for better inspectionh- Undo
This is a tool for analyzing cells. However, we do not catch every possible error and in order for the tool to run stable, it is important to avoid some operations:
- Do not create new layers during the analysis.
The plugin does not print debug messages by default. To see them, for example in the napari console, enable them for the plugin:
import logging
logging.getLogger("mmv_h4cells").addHandler(logging.StreamHandler())
logging.getLogger("mmv_h4cells").setLevel(logging.DEBUG)Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.
_session.py: the cells and the decisions about them (include, exclude, undo, overlap, metrics). It knows nothing about Qt or napari and is tested without a viewer (_tests/test_session.py)._widget.py: the napari widget. It shows what the session does and takes care of the buttons, messages and layers._navigation.py: which cell is shown next._reader.py,_writer.py,_roi.py: reading and writing sessions, and the export of a region.
Distributed under the terms of the BSD-3 license, "mmv_h4cells" is free and open source software
If you encounter any problems, please file an issue along with a detailed description.