Skip to content

Commit

Permalink
New version of annotator
Browse files Browse the repository at this point in the history
  • Loading branch information
c-h-benedetti committed Oct 31, 2024
1 parent 6041f66 commit eddbf5e
Show file tree
Hide file tree
Showing 49 changed files with 817 additions and 54 deletions.
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/calibration/calibration-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/helper/annotation-helper.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/patches/activity-map-building.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/patches/physical-size.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/seg-ex/01-in.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/seg-ex/01-out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/seg-ex/02-in.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/seg-ex/02-out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/seg-ex/03-in.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/seg-ex/03-out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/seg-ex/04-in.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/seg-ex/04-out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/seg-ex/05-in.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/seg-ex/05-out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/seg-ex/06-in.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/seg-ex/06-out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/yolo/banner.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions docs/_static/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.wy-nav-content {
max-width: none;
}

.wy-table-responsive table td, .wy-table-responsive table th {
white-space: normal;
}

table caption {
caption-side: bottom;
}
3 changes: 3 additions & 0 deletions docs/analyze_microglia.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
=================
Analyze Microglia
=================
96 changes: 96 additions & 0 deletions docs/annotate_patches.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
===========================
Annotate your data for YOLO
===========================

- The goal of this widget is to help you annotate your data for the YOLO model.
- YOLO is a deep learning model that can detect objects in images.
- Detections are composed of bounding-boxes around objects and a class label.
- To train the model, you need to provide a dataset of annotated images.
- The widget "YOLO Annotator" will help you to create this dataset.

.. image:: _images/yolo/banner.jpg
:align: center
:width: 800px

1. Prepare your data
====================

- First of all, the data that you will annotate must be ready.
- Your images must all be the same size in pixels.
- You can use TIF, PNG, JPG, ... but no proprietary format (CZI, LIF, ...).
- You can use the "Tiles creator" widget to create patches from your images. A common size is 512x512 pixels.
- All the images that you want to annotate must be in the same folder.
- Before you start, you should have a folder structure like this:

.. code-block:: bash
📁 some-folder
├── 📁 my-experiment
│ ├── 14-25-23.336.tif
│ ├── 14-25-23.379.tif
│ ├── ...
│ └── 14-25-36.949.tif
2. Initialize the widget
========================

- Open the widget located in: Plugins > Microglia Analyzer > YOLO Annotator.
- Click the "Root folder" button and choose the folder named "some-folder" in the previous example. It is the folder containing the folder in which your images are located.
- In the "Inputs sub-folder" dropdown menu, choose the folder named "my-experiment" in the previous example. It is the folder containing your images.
- The first image of your experiment will be displayed.
- You can navigate through the images using the dropdown menu in the "Annotations management" section.


3. Create your classes
======================

- The first thing to do is to create new classes. Each one corresponds to a different type of object that you want to detect.
- Simply fill the text field in the "Classes management" section and click the "New class" button.
- You can add as many classes as you want.
- The classes that you add should appear in the layers stack of Napari (on the left side of the window).


4. Annotate your data
=====================

- To annotate an object, you have to draw a bounding-box around it. You are limited to rectangles. Do not use ellipses or polygons or anything else.
- You can choose the rectangle tool in the upper-left section of the Napari's window.
- Your boxes should contain the whole object and a few pixels around it.
- It is not a problem if the boxes overlap.
- If you failed a box, don't edit it: delete it and draw a new one.
- If you don't plan to annotate many images, you should really be careful not to forget any object on your images.
- When you are happy with the annotations you made, click the "Save annotations" button in the "Annotations management" section.
- In the "Classes management" section, a table should have appeared to show you global statistics about your annotations.
- A new folder with the "-labels" suffix should have appeared in the root folder. It contains the annotations you made.
- A new file with the "-classes.txt" suffix should have appeared in the root folder. It contains the classes you created.
- Your files architecture should now look like this:

.. code-block:: bash
📁 some-folder
├── 📁 my-experiment
│ ├── 14-25-23.336.tif
│ ├── 14-25-23.379.tif
│ ├── ...
│ └── 14-25-36.949.tif
├── 📁 my-experiment-labels
│ ├── 14-25-23.336.txt
│ ├── 14-25-23.379.txt
│ ├── ...
│ └── 14-25-36.949.txt
├── 📃 my-experiment-classes.txt
Notes
=====

- If you are working on RGB images, they will be converted to grayscale.
- If you already annotated some images, your annotations will be loaded when you open the widget.
- Whenever it is possible, try to have a balanced dataset. It means that you should have the same number of annotations for each class.
- In the ".txt" files generated for each image by the widget, the content is as follows:
- [integer]: the class index (starting from 0).
- [float]: the x-coordinate of the center of the bounding-box, in percentage of the image width.
- [float]: the y-coordinate of the center of the bounding-box, in percentage of the image height.
- [float]: the width of the bounding-box, in percentage of the image width.
- [float]: the height of the bounding-box, in percentage of the image height.
72 changes: 72 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#

import os
import sys

mod_path = os.path.abspath('../src')
print(mod_path)
sys.path.insert(0, mod_path)


# -- Project information -----------------------------------------------------

project = 'Protoplasts swelling analyzer'
copyright = '2024, Clément H. Benedetti'
author = 'Clément H. BENEDETTI'

# The full version, including alpha/beta/rc tags
release = '1.0.0'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon',
'sphinx_tabs.tabs',
'myst_parser',
'sphinx_rtd_theme',
]


# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

html_css_files = ['custom.css']

html_favicon = 'icon.png'

autosummary_generate = True
Binary file added docs/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Microglia Analyzer
==================

.. toctree::
:maxdepth: 3
:caption: Contents:

user_guide
make_patches
annotate_patches
analyze_microglia
modules


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
Empty file added docs/make_doc.yml
Empty file.
62 changes: 62 additions & 0 deletions docs/make_patches.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.. _make_patches:

==============================
Patches from calibrated images
==============================


1. Detect the protoplasts
=========================

A single experiment is 20 GB of size in average. We would like not to waste processing time to launch the segmentation of traps that are actually empty.
To do so, we implemented a way to detect the presence of protoplasts (find their centroïd).

The first step of the algorithm consists in processing the "activity map" of this experiment. By this, we mean the areas where protoplasts are spinning on themselves.

This is achieved by summing the absolute difference between each contiguous pairs of frame.

Then, we apply a sequence of filters (Median blur, Laplacian of Gaussian, threshold et connected components labeling) to find a little spot of pixels per protoplast. We finish this step with a points-set containing one point on each protoplast.


.. image:: _images/patches/activity-map-building.png
:align: center




2. Create the patches
=====================

For a model to predict correctly objects, the patches you feed it must be similar to the ones it was trained with.

The model we trained requires patches that are exactly 128×128 pixels of size.
It sounds like a big constraint as it implies that your pixel size should always be the same.
Indeed, if we cut a patch of 128×128 pixels, those 128 pixels are 115.2 µm if the size of a pixel is 0.9 µm and they are only 76.8 µm if a pixel is 0.65 µm.

We addressed this problem by doing a two-step patches extraction.

Instead of cutting patches of 128×128 pixels in the main image, we cut patches of 130×130 µm, whatever size in pixels it is.
Once we have those patches, we re-sample them by scaling them so they can fit in a 128×128 pixels image.

.. table:: An object of 20µm of diameter with different pixel sizes
:align: center

+----------------------------------------------------+-------------------------------------------------------------+--------------------------------------------------------------+
| .. image:: _images/calibration/calibration-1.png | .. image:: _images/calibration/calibration-1-psize0_9.png | .. image:: _images/calibration/calibration-1-psize0_65.png |
| :height: 250px | :height: 250px | :height: 250px |
| :width: 250px | :width: 250px | :width: 250px |
| :align: center | :align: center | :align: center |
+----------------------------------------------------+-------------------------------------------------------------+--------------------------------------------------------------+
| The object is always 20µm of diameter | Pixel size = 0.9µm | Pixel size = 0.65µm |
+----------------------------------------------------+-------------------------------------------------------------+--------------------------------------------------------------+


.. image:: _images/patches/physical-size.png
:align: center
:width: 400px


3. Export the patches
=====================

The patches are exported in 128×128 pixels, on 32 bits, normalized between 0 and 1.
7 changes: 7 additions & 0 deletions docs/microglia_analyzer.custom-loss.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
microglia\_analyzer.custom\-loss module
=======================================

.. automodule:: microglia_analyzer.custom-loss
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/microglia_analyzer.microglia_analyzer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
microglia\_analyzer.microglia\_analyzer module
==============================================

.. automodule:: microglia_analyzer.microglia_analyzer
:members:
:undoc-members:
:show-inheritance:
27 changes: 27 additions & 0 deletions docs/microglia_analyzer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
microglia\_analyzer package
===========================

Subpackages
-----------

.. toctree::
:maxdepth: 4

microglia_analyzer.tiles

Submodules
----------

.. toctree::
:maxdepth: 4

microglia_analyzer.custom-loss
microglia_analyzer.microglia_analyzer

Module contents
---------------

.. automodule:: microglia_analyzer
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/microglia_analyzer.tiles.patch.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
microglia\_analyzer.tiles.patch module
======================================

.. automodule:: microglia_analyzer.tiles.patch
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/microglia_analyzer.tiles.plot.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
microglia\_analyzer.tiles.plot module
=====================================

.. automodule:: microglia_analyzer.tiles.plot
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/microglia_analyzer.tiles.recalibrate.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
microglia\_analyzer.tiles.recalibrate module
============================================

.. automodule:: microglia_analyzer.tiles.recalibrate
:members:
:undoc-members:
:show-inheritance:
Loading

0 comments on commit eddbf5e

Please sign in to comment.