Metadata-Version: 2.4
Name: microglia-analyzer
Version: 2.1.0
Summary: A Napari plugin allowing to detect and segment microglia on fluorescent images.
Author-email: "Clément H. BENEDETTI" <clement.benedetti@mri.cnrs.fr>
License: 
        The MIT License (MIT)
        
        Copyright (c) 2024 Clément H. BENEDETTI
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in
        all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
        THE SOFTWARE.
        
Project-URL: Bug Tracker, https://github.com/MontpellierRessourcesImagerie/microglia-analyzer/issues
Project-URL: Documentation, https://github.com/MontpellierRessourcesImagerie/microglia-analyzer#README.md
Project-URL: Source Code, https://github.com/MontpellierRessourcesImagerie/microglia-analyzer
Project-URL: User Support, https://github.com/MontpellierRessourcesImagerie/microglia-analyzer/issues
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Framework :: napari
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Image Processing
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: qtpy
Requires-Dist: scikit-image
Requires-Dist: opencv-python-headless
Requires-Dist: pint
Requires-Dist: tifffile
Requires-Dist: torch
Requires-Dist: tensorflow
Requires-Dist: skan
Requires-Dist: ultralytics
Requires-Dist: yolov5
Provides-Extra: testing
Requires-Dist: tox; extra == "testing"
Requires-Dist: pytest; extra == "testing"
Requires-Dist: pytest-cov; extra == "testing"
Requires-Dist: pytest-qt; extra == "testing"
Requires-Dist: napari; extra == "testing"
Requires-Dist: pyqt6; extra == "testing"
Requires-Dist: qtpy; extra == "testing"
Requires-Dist: sphinx_rtd_theme; extra == "testing"
Requires-Dist: myst_parser; extra == "testing"
Requires-Dist: sphinx_tabs; extra == "testing"
Dynamic: license-file

# Microglia Analyzer

![GitHub License](https://img.shields.io/github/license/MontpellierRessourcesImagerie/microglia-analyzer)
![Python Version](https://img.shields.io/badge/Python-3.9|3.10|3.11-blue?logo=python)
![Unit tests](https://img.shields.io/github/actions/workflow/status/MontpellierRessourcesImagerie/microglia-analyzer/test_and_deploy.yml?logo=pytest&label=tests)

# What is it?

A Napari plugin that allows for the segmentation and classification of microglia on 2D fluorescent images.
Z-stacks and time series are not handled.

- Segments the microglia with a UNet2D model.
- Creates classified bounding-boxes with a YOLOv5.
- Attributes a class to each cell.
- Extracts graph information about the cells.
    
We end up with a ".csv" (separated with tabulations instead of commas) file containing all these metrics.

- 🐛 Found a bug?: https://github.com/MontpellierRessourcesImagerie/microglia-analyzer/issues
- 🔍 Need some help?: mri-cia@mri.cnrs.fr

# 01. How to install/upgrade it?

## Install

| Action      | Command                                                                                               |
|-------------|-------------------------------------------------------------------------------------------------------|
| **Install** | `pip install git+https://github.com/MontpellierRessourcesImagerie/microglia-analyzer.git napari[all]` |
| **Upgrade** | `pip install --upgrade git+https://github.com/MontpellierRessourcesImagerie/microglia-analyzer.git`   |


# 02. How to use it?

For more details, check the [detailed documentation](https://montpellierressourcesimagerie.github.io/microglia-analyzer).

# A. Open the widget

- First of all, you need all your images to be converted to TIFF, and placed in the same folder.
- Once Napari is opened, you can visit your plugins list. It should contain a `Microglia Analyzer` entry.
    - `Tiles Creator` allows you to create patches to annotate if you ever want to retrain the UNet or the YOLOv5.
    - `Annotations Helper` allows you to define and create classified bounding-boxes exported under the YOLOv5 format as well as masks. This widget is meant to help you create some ground-truth data.
    - `Microglia Analyzer` contains the whole analysis workflow.

# B. Load your images

- Click the `📁 Sources folder` button and navigate to the folder containing your TIFF images before pressing OK.
- In the drop-down menu below, you can choose the image on which you want to run the analysis.
- In the "Calibration" field, you just have to provide the size of your pixels in physical unit and confirm. Your image may look small after this step, so you may want to press the button with a little picture of home in the lower-left corner of Napari's window.

# C. Segment your microglia

- Press the `🔍 Segment` button and wait for the labeled microglia to show up.
- The first time, this step may take a little longer as the plugin must download the deep-learning model from MRI's server.
- You can adjust the area of the smallest tolerated object either before or after the segmentation, both ways work.
- At this point, each individual microglia should be represented by its own color.
- We focused the segmentation on the "graph" produced by microglia, so the soma won't look thicker than any other part of the microglia.

# D. Classify your microglia

- Click the `Classify` button.
- Once again, a model has to be downloaded from MRI's server.
- By the end of this step, you should have a colored bounding-box around each tolerated microglia.
- The color indicates which class it belongs to (amoeboid, intermediate ou homeostatic).
- The color code should show up in the array below the classification button.
- If you wish, you can adjust the prediction threshold ("how sure the model is about what it sees")

# E. Measure your microglia

- If you click on the `📊 Measure` button, the skeleton of each microglia should appear.
- The measures are generated and stored in a `.tsv` file located in the `controls` sub-folder (auto-generated in your images' folder)

# F. Analyze the whole folder

- Once you got to that point, each parameter is correctly set (as you just used them for an image), so you click the `▶ Run batch` to apply them to the whole folder.
- The button should now indicate `■ Kill batch (i/N)`. You can click it to interrupt the execution. `i` is the rank of the current image, and `N` is the number of images detected in the folder.
- By the end of the run, the button should be normal again, and a `results.tsv` file should be located in the `controls` folder.

