py-ctcmetrics 0.1.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- py_ctcmetrics-0.1.4/LICENSE.txt +24 -0
- py_ctcmetrics-0.1.4/PKG-INFO +16 -0
- py_ctcmetrics-0.1.4/README.md +401 -0
- py_ctcmetrics-0.1.4/ctc_metrics/__init__.py +2 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/__init__.py +24 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/biological/__init__.py +0 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/biological/bc.py +169 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/biological/bio.py +41 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/biological/cca.py +75 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/biological/ct.py +65 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/biological/op_clb.py +19 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/biological/tf.py +107 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/clearmot/__init__.py +0 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/clearmot/mota.py +67 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/hota/__init__.py +0 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/hota/chota.py +125 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/hota/hota.py +63 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/identity_metrics/__init__.py +0 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/identity_metrics/idf1.py +117 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/others/__init__.py +0 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/others/faf.py +34 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/others/mt_ml.py +39 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/technical/__init__.py +0 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/technical/det.py +37 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/technical/lnk.py +37 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/technical/op_csb.py +19 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/technical/op_ctb.py +19 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/technical/seg.py +27 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/technical/tra.py +48 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/validation/__init__.py +0 -0
- py_ctcmetrics-0.1.4/ctc_metrics/metrics/validation/valid.py +238 -0
- py_ctcmetrics-0.1.4/ctc_metrics/scripts/__init__.py +0 -0
- py_ctcmetrics-0.1.4/ctc_metrics/scripts/evaluate.py +410 -0
- py_ctcmetrics-0.1.4/ctc_metrics/scripts/noise.py +692 -0
- py_ctcmetrics-0.1.4/ctc_metrics/scripts/validate.py +96 -0
- py_ctcmetrics-0.1.4/ctc_metrics/scripts/visualize.py +322 -0
- py_ctcmetrics-0.1.4/ctc_metrics/utils/__init__.py +0 -0
- py_ctcmetrics-0.1.4/ctc_metrics/utils/filesystem.py +106 -0
- py_ctcmetrics-0.1.4/ctc_metrics/utils/handle_results.py +55 -0
- py_ctcmetrics-0.1.4/ctc_metrics/utils/representations.py +456 -0
- py_ctcmetrics-0.1.4/py_ctcmetrics.egg-info/PKG-INFO +16 -0
- py_ctcmetrics-0.1.4/py_ctcmetrics.egg-info/SOURCES.txt +50 -0
- py_ctcmetrics-0.1.4/py_ctcmetrics.egg-info/dependency_links.txt +1 -0
- py_ctcmetrics-0.1.4/py_ctcmetrics.egg-info/entry_points.txt +5 -0
- py_ctcmetrics-0.1.4/py_ctcmetrics.egg-info/requires.txt +7 -0
- py_ctcmetrics-0.1.4/py_ctcmetrics.egg-info/top_level.txt +2 -0
- py_ctcmetrics-0.1.4/setup.cfg +4 -0
- py_ctcmetrics-0.1.4/setup.py +29 -0
- py_ctcmetrics-0.1.4/test/__init__.py +0 -0
- py_ctcmetrics-0.1.4/test/test_metrics.py +72 -0
- py_ctcmetrics-0.1.4/test/test_validate.py +7 -0
- py_ctcmetrics-0.1.4/test/utils.py +17 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Copyright (c) 2023 - 2023, Timo Kaiser
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
5
|
+
are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
8
|
+
list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
15
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
16
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
17
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
18
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
19
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
20
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
21
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
22
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
23
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
24
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: py-ctcmetrics
|
|
3
|
+
Version: 0.1.4
|
|
4
|
+
Summary: Metrics for Cell Tracking Challenges
|
|
5
|
+
Author: Timo Kaiser
|
|
6
|
+
Author-email: kaiser@tnt.uni-hannover.de
|
|
7
|
+
License-File: LICENSE.txt
|
|
8
|
+
Requires-Dist: numpy
|
|
9
|
+
Requires-Dist: opencv-python
|
|
10
|
+
Requires-Dist: scikit-learn
|
|
11
|
+
Requires-Dist: scipy
|
|
12
|
+
Requires-Dist: tifffile
|
|
13
|
+
Requires-Dist: imagecodecs
|
|
14
|
+
Requires-Dist: pandas
|
|
15
|
+
|
|
16
|
+
Metrics for Cell Tracking Challenges
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
[](https://opensource.org/licenses/BSD-2-Clause)
|
|
2
|
+
[](https://github.com/TimoK93/ctc-metrics/actions/workflows/pylint.yml)
|
|
3
|
+
[](https://github.com/TimoK93/ctc-metrics/actions/workflows/python-package.yml)
|
|
4
|
+
[](https://github.com/CellTrackingChallenge/py-ctcmetrics/actions/workflows/publish.yml)
|
|
5
|
+
|
|
6
|
+
# Py-CTCMetrics
|
|
7
|
+
A python implementation of the metrics used in the paper
|
|
8
|
+
[CHOTA: A Higher Order Accuracy Metric for Cell Tracking](...) by
|
|
9
|
+
*Kaiser et al.*. The code is
|
|
10
|
+
designed to evaluate tracking results in the format of the
|
|
11
|
+
[Cell-Tracking-Challenge](https://celltrackingchallenge.net/) but can also be used
|
|
12
|
+
for custom results.
|
|
13
|
+
The repository contains the metrics of the
|
|
14
|
+
[Cell-Tracking-Challenge](https://celltrackingchallenge.net/),
|
|
15
|
+
the [MOTChallenge](https://motchallenge.net/), and the
|
|
16
|
+
[CHOTA](...) metric.
|
|
17
|
+
|
|
18
|
+
Detailed descriptions of the metrics can be found in the [paper](...).
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Features at a Glance
|
|
23
|
+
|
|
24
|
+
- **Validation**: Check if the tracking results are correctly formatted.
|
|
25
|
+
- **Evaluation**: Evaluate the tracking results with respect to the ground truth using CTC, MotChallenge, and CHOTA metrics.
|
|
26
|
+
- **Visualization**: Visualize the tracking results.
|
|
27
|
+
- **Video Creation**: Create a video of the visualized tracking results for presentation purposes.
|
|
28
|
+
- **Noise Evaluation**: Evaluate the impact of specific errors on the evaluation metrics.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Requirements
|
|
33
|
+
|
|
34
|
+
We tested the code with **Python 3.10**. Additional packages that will be
|
|
35
|
+
installed automatically are listed in the [requirements.txt](requirements.txt).
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
The package can be installed via pip:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install git+https://github.com/CellTrackingChallenge/py-ctcmetrics.git
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
or from the source code:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
git clone https://github.com/CellTrackingChallenge/py-ctcmetrics
|
|
51
|
+
cd py-ctcmetrics
|
|
52
|
+
pip install .
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Usage
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
The package supports validation, evaluation, and visualization of tracking
|
|
61
|
+
results. The following examples are shown for an example directory that is
|
|
62
|
+
structured in the CTC-format as follows:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
ctc
|
|
66
|
+
├── train
|
|
67
|
+
│ ├── challenge_x
|
|
68
|
+
│ │ ├── 01_GT
|
|
69
|
+
│ │ ├── 01_RES
|
|
70
|
+
│ │ ├── 02_GT
|
|
71
|
+
│ │ ├── 02_RES
|
|
72
|
+
│ ├── challenge_y
|
|
73
|
+
│ │ ├── 01_GT
|
|
74
|
+
│ │ ├── 01_RES
|
|
75
|
+
│ │ ├── 02_GT
|
|
76
|
+
│ │ ├── 02_RES
|
|
77
|
+
```
|
|
78
|
+
The directory ```ctc``` contains the training data. The subdirectories
|
|
79
|
+
```challenge_x``` and ```challenge_y``` contain the data for the different
|
|
80
|
+
challenges. Each challenge directory contains subdirectories for the sequences
|
|
81
|
+
```01_GT```, ```01_RES```, ```02_GT```, and ```02_RES```. The directories
|
|
82
|
+
```01_GT``` and ```01_RES``` contain the ground truth and the tracking results
|
|
83
|
+
for the sequence ```01```. The same applies to the directories ```02_GT``` and
|
|
84
|
+
```02_RES```.
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
### Validation
|
|
88
|
+
|
|
89
|
+
Produced tracking results can be invalid due to various reasons. To check if
|
|
90
|
+
the tracking results are correctly formatted according to the CTC-format, the
|
|
91
|
+
```ctc_validate``` command can be used. The command checks if the tracking
|
|
92
|
+
results are correctly formatted. There is no ground truth needed for this
|
|
93
|
+
validation.
|
|
94
|
+
|
|
95
|
+
To validate if ```challenge_x/01``` is correctly formatted, run the
|
|
96
|
+
command
|
|
97
|
+
```bash
|
|
98
|
+
ctc_validate --res "/ctc/train/challenge_x/01_RES"
|
|
99
|
+
```
|
|
100
|
+
Moreover, you can recursively validate the tracking results for all
|
|
101
|
+
challenges/sequences in a directory by adding the flag ```-r```:
|
|
102
|
+
```bash
|
|
103
|
+
ctc_validate --res "/ctc/train" -r
|
|
104
|
+
```
|
|
105
|
+
In this example, all four sequences will be validated.
|
|
106
|
+
|
|
107
|
+
### Evaluation
|
|
108
|
+
|
|
109
|
+
To evaluate results against the ground truth, similar commands can be used.
|
|
110
|
+
For example, to evaluate the sequence ```challenge_x/01```, run the command
|
|
111
|
+
```bash
|
|
112
|
+
ctc_evaluate --gt "/ctc/train/challenge_x/01_GT" --res "/ctc/train/challenge_x/01_RES"
|
|
113
|
+
```
|
|
114
|
+
or recursively for all sequences in a directory:
|
|
115
|
+
```bash
|
|
116
|
+
ctc_evaluate --gt "/ctc/train" --res "/ctc/train" -r
|
|
117
|
+
```
|
|
118
|
+
The ```gt``` argument specifies the path to the ground truth directory, and the
|
|
119
|
+
```res``` argument specifies the path to the results directory. The flag ```-r```
|
|
120
|
+
recursively evaluates all sequences in the directory.
|
|
121
|
+
|
|
122
|
+
Per default, the code is executed using multiple processes with one process per
|
|
123
|
+
available CPU core. Multiprocessing decreases the execution time but also
|
|
124
|
+
increases
|
|
125
|
+
the memory consumption. If you need to set the maximal number of processes,
|
|
126
|
+
the number of processes can be specified with the argument
|
|
127
|
+
```--num-threads``` or ```-n```:
|
|
128
|
+
```bash
|
|
129
|
+
ctc_evaluate --gt "/ctc/train" --res "/ctc/train" -r -n 4
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
The evaluation results are printed to the console. If you want to save the
|
|
133
|
+
results to a csv file, you can use the argument ```--csv-file``` :
|
|
134
|
+
```bash
|
|
135
|
+
ctc_evaluate --gt "/ctc/train" --res "/ctc/train" -r --csv-file "/ctc/results.csv"
|
|
136
|
+
```
|
|
137
|
+
**Note:** The csv file will be overwritten if it already exists!
|
|
138
|
+
|
|
139
|
+
The following table shows the available arguments:
|
|
140
|
+
|
|
141
|
+
| Argument | Description | Default |
|
|
142
|
+
|---------------|------------------------------------------------------| --- |
|
|
143
|
+
| --gt | Path to the ground truth directory. | None |
|
|
144
|
+
| --res | Path to the results directory. | None |
|
|
145
|
+
| --recursive | Recursively evaluate all sequences in the directory. | False |
|
|
146
|
+
| --csv-file | Path to a csv file to save the results. | None |
|
|
147
|
+
| --num-threads | Number of threads to use for evaluation. | 1 |
|
|
148
|
+
|
|
149
|
+
Per default, all given metrics are evaluated. You can also select the metrics
|
|
150
|
+
you are interested in to avoid the calculation of metrics that are not in your
|
|
151
|
+
interest. Additional arguments to select a subset of specific metrics are:
|
|
152
|
+
|
|
153
|
+
| Argument | Description |
|
|
154
|
+
| --- |-----------------------------------------------------------------|
|
|
155
|
+
| --valid | Check if the result has valid format |
|
|
156
|
+
| --det | The DET detection metric |
|
|
157
|
+
| --seg | The SEG segmentation metric |
|
|
158
|
+
| --tra | The TRA tracking metric |
|
|
159
|
+
| --lnk | The LNK linking metric |
|
|
160
|
+
| --ct | The CT (complete tracks) metric |
|
|
161
|
+
| --tf | The TF (track fraction) metric |
|
|
162
|
+
| --bc | The BC(i) (branching correctness) metric |
|
|
163
|
+
| --cca | The CCA (cell cycle accuracy) metric |
|
|
164
|
+
| --mota | The MOTA (Multiple Object Tracking Accuracy) metric |
|
|
165
|
+
| --hota | The HOTA (Higher Order Tracking Accuracy) metric |
|
|
166
|
+
| --idf1 | The IDF1 (ID F1) metric |
|
|
167
|
+
| --chota | The CHOTA (Cell-specific Higher Order Tracking Accuracy) metric |
|
|
168
|
+
| --mtml | The MT (Mostly Tracked) and ML (Mostly Lost) metrics |
|
|
169
|
+
| --faf | The FAF (False Alarm per Frame) metric |
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
To use the evaluation protocol in your python code, the code can be imported
|
|
173
|
+
as follows:
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
from ctc_metrics import evaluate_sequence, validate_sequence
|
|
177
|
+
|
|
178
|
+
# Validate the sequence
|
|
179
|
+
res = validate_sequence("/ctc/train/challenge_x/01_RES")
|
|
180
|
+
print(res["Valid"])
|
|
181
|
+
|
|
182
|
+
# Evaluate the sequence
|
|
183
|
+
res = evaluate_sequence("/ctc/train/challenge_x/01_GT", "/ctc/train/challenge_x/01_RES")
|
|
184
|
+
print(res["DET"])
|
|
185
|
+
print(res["SEG"])
|
|
186
|
+
print(res["TRA"])
|
|
187
|
+
...
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Visualization
|
|
192
|
+
|
|
193
|
+
<p align="center">
|
|
194
|
+
<img src="assets/visualization.jpg" />
|
|
195
|
+
</p>
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
You can visualize your tracking results with the following command:
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
ctc_visualize --img "/ctc/train/challenge_x/01" --res "/ctc/train/challenge_x/01_RES"
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
The command will show the visualizations of the tracking results. You can
|
|
205
|
+
control the visualization with specific keys:
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
| Key | Description |
|
|
209
|
+
|-------|---------------------------------------------------------------------|
|
|
210
|
+
| q | Quits the Application |
|
|
211
|
+
| w | Start or Pause the auto visualization |
|
|
212
|
+
| d | Move to the next frame |
|
|
213
|
+
| a | Move to the previous frame |
|
|
214
|
+
| l | Toggle the show labels option |
|
|
215
|
+
| p | Toggle the show parents option |
|
|
216
|
+
| s | Save the current frame to the visualization directory as .jpg image |
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
There are additional arguments that can be used to specify the visualization.
|
|
220
|
+
The following table shows the available arguments:
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
| Argument | Description | Default |
|
|
224
|
+
|-------------------|------------------------------------------------------------------------------------------|---------|
|
|
225
|
+
| --img | The directory to the images **(required)** | |
|
|
226
|
+
| --res | The directory to the result masks **(required)** | |
|
|
227
|
+
| --viz | The directory to save the visualization | None |
|
|
228
|
+
| --video-name | The path to the video if a video should be created | None |
|
|
229
|
+
| --border-width | The width of the border. Either an integer or a string that describes the challenge name | None |
|
|
230
|
+
| --show-no-labels | Print no instance labels to the output as default | False |
|
|
231
|
+
| --show-no-parents | Print no parent labels to the output as default | False |
|
|
232
|
+
| --ids-to-show | The IDs of the instances to show. If defined, all others will be ignored. | None |
|
|
233
|
+
| --start-frame | The frame to start the visualization | 0 |
|
|
234
|
+
| --framerate | The framerate of the video | 10 |
|
|
235
|
+
| --opacity | The opacity of the instance colors | 0.5 |
|
|
236
|
+
|
|
237
|
+
**Note:** The argument `--video-name` describes a path to a video file. The file
|
|
238
|
+
extension needs to be `.mp4`. If a video name is selected be created,
|
|
239
|
+
the visualization is not shown on the screen. Please use the arguments to
|
|
240
|
+
specify your visualization settings such as the opacity, border width etc.
|
|
241
|
+
|
|
242
|
+
### Impact of Errors and Noise on the Evaluation Metrics
|
|
243
|
+
|
|
244
|
+
The evaluation metrics are sensitive to errors in the tracking results. To
|
|
245
|
+
investigate the impact of detection and association errors on your dataset with
|
|
246
|
+
respect to the evaluation metrics, the repository provides a script to
|
|
247
|
+
automatically run the evaluation with different noise levels. The script uses
|
|
248
|
+
the ground truth of the data as oracle tracking result. Then, noise is
|
|
249
|
+
added to the oracle tracking results and the evaluation metrics are calculated
|
|
250
|
+
for the noisy tracking results. The scripts independently evaluates the
|
|
251
|
+
influence of randomly inserted false positives, false negatives, ID switches,
|
|
252
|
+
and removals of correct result-to-reference matches.
|
|
253
|
+
The results are stored into a predefined csv file. The script can be used as
|
|
254
|
+
follows:
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
ctc_noise --gt "/ctc/train/challenge_x/01_GT" --csv-file "/ctc/noise_experiments.csv"
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Similar to the validation and evaluation scripts, the script can be used
|
|
261
|
+
recursively for all sequences in a directory by adding the flag ```-r```.
|
|
262
|
+
Moreover, the number of threads can be specified with the argument
|
|
263
|
+
```--num-threads``` or ```-n```. Since metrics are sometimes prone to randomness
|
|
264
|
+
in the distribution of the errors, the script can be run multiple times with
|
|
265
|
+
different seeds to get a more robust evaluation. The number of seeds can be
|
|
266
|
+
specified with the argument ```--repeat```.
|
|
267
|
+
|
|
268
|
+
The following table shows the available arguments:
|
|
269
|
+
|
|
270
|
+
| Argument | Description | Default |
|
|
271
|
+
|---------------|--------------------------------------------------------------------| --- |
|
|
272
|
+
| --gt | Path to the ground truth directory. | None |
|
|
273
|
+
| --csv-file | Path to a csv file to save the results. | None |
|
|
274
|
+
| --recursive | Recursively evaluate all sequences in the directory. | False |
|
|
275
|
+
| --num-threads | Number of threads to use for evaluation. | 1 |
|
|
276
|
+
| --repeats | Number of repeats to run the evaluation. | 1 |
|
|
277
|
+
| -- num-false-pos | Number of false positive instances to add to the tracking results. | 500 |
|
|
278
|
+
| -- num-false-neg | Number of false negative instances to add to the tracking results. | 500 |
|
|
279
|
+
| -- num-idsw | Number of ID switches to add to the tracking results. | 500 |
|
|
280
|
+
| -- num-matches | Number of matches to add to the tracking results. | 500 |
|
|
281
|
+
| -- save-after | Save the intermediate results after a specific number of runs. | 100 |
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Notes
|
|
287
|
+
|
|
288
|
+
- If you only have segmentation results and want to evaluate the *SEG* metric,
|
|
289
|
+
it is important that you pass the *--seg* flag to the evaluation command.
|
|
290
|
+
Otherwise, the code could flag your input as invalid, because the
|
|
291
|
+
*res_track.txt* file is missing or inconsistent.
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## Contributing
|
|
296
|
+
|
|
297
|
+
Contributions are welcome! For bug reports or requests please
|
|
298
|
+
[submit an issue](www.github.com/TimoK93/ctc-metrics/issues). For new features
|
|
299
|
+
please [submit a pull request](www.github.com/TimoK93/ctc-metrics/pulls).
|
|
300
|
+
|
|
301
|
+
If you want to contribute, please check your code with pylint and the
|
|
302
|
+
pre-commit hooks before submitting a pull request:
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
pip install pre-commit, pylint
|
|
306
|
+
pre-commit run --all-files
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
## Acknowledgement and Citations
|
|
312
|
+
|
|
313
|
+
The code was developed by Timo Kaiser on behalf of the [Institute of Information
|
|
314
|
+
Processing](https://www.tnt.uni-hannover.de/) at the Leibniz University Hanover in conjunction with the
|
|
315
|
+
organizers of the [Cell-Tracking-Challenge](https://celltrackingchallenge.net/).
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
If you use this code or the CHOTA metric in your research, please cite the following paper:
|
|
319
|
+
```bibtex
|
|
320
|
+
@inproceedings{kaiser2024chota,
|
|
321
|
+
author = {Kaiser, Timo and Ulman, Vladimír and Rosenhahn, Bodo},
|
|
322
|
+
title = {CHOTA: A Higher Order Accuracy Metric for Cell Tracking},
|
|
323
|
+
booktitle = {European Conference on Computer Vision Workshops (ECCVW)},
|
|
324
|
+
year = {2024},
|
|
325
|
+
organization={Springer}
|
|
326
|
+
}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
If you use CTC-Metrics (BC, CT, CCA, TF, SEG, TRA, DET, LNK) in your research, please cite the following paper:
|
|
330
|
+
```bibtex
|
|
331
|
+
@article{thecelltrackingchallenge,
|
|
332
|
+
author = {Maška, Martin and Ulman, Vladimír and Delgado-Rodriguez, Pablo and Gómez de Mariscal, Estibaliz and Necasova, Tereza and Guerrero Peña, Fidel Alejandro and Ing Ren, Tsang and Meyerowitz, Elliot and Scherr, Tim and Löffler, Katharina and Mikut, Ralf and Guo, Tianqi and Wang, Yin and Allebach, Jan and Bao, Rina and Al-Shakarji, Noor and Rahmon, Gani and Toubal, Imad Eddine and Palaniappan, K. and Ortiz-de-Solorzano, Carlos},
|
|
333
|
+
year = {2023},
|
|
334
|
+
month = {05},
|
|
335
|
+
pages = {1-11},
|
|
336
|
+
title = {The Cell Tracking Challenge: 10 years of objective benchmarking},
|
|
337
|
+
volume = {20},
|
|
338
|
+
journal = {Nature Methods},
|
|
339
|
+
doi = {10.1038/s41592-023-01879-y}
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
and
|
|
343
|
+
```bibtex
|
|
344
|
+
@article{matula2015cell,
|
|
345
|
+
title={Cell tracking accuracy measurement based on comparison of acyclic oriented graphs},
|
|
346
|
+
author={Matula, Pavel and Ma{\v{s}}ka, Martin and Sorokin, Dmitry V and Matula, Petr and Ortiz-de-Sol{\'o}rzano, Carlos and Kozubek, Michal},
|
|
347
|
+
journal={PloS one},
|
|
348
|
+
volume={10},
|
|
349
|
+
number={12},
|
|
350
|
+
pages={e0144959},
|
|
351
|
+
year={2015},
|
|
352
|
+
publisher={Public Library of Science San Francisco, CA USA}
|
|
353
|
+
}
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
If you use the HOTA metric in your research, please cite the following paper:
|
|
357
|
+
```bibtex
|
|
358
|
+
@article{luiten2021hota,
|
|
359
|
+
title={Hota: A higher order metric for evaluating multi-object tracking},
|
|
360
|
+
author={Luiten, Jonathon and Osep, Aljosa and Dendorfer, Patrick and Torr, Philip and Geiger, Andreas and Leal-Taix{\'e}, Laura and Leibe, Bastian},
|
|
361
|
+
journal={International journal of computer vision},
|
|
362
|
+
volume={129},
|
|
363
|
+
pages={548--578},
|
|
364
|
+
year={2021},
|
|
365
|
+
publisher={Springer}
|
|
366
|
+
}
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
If you use the IDF1 metric in your research, please cite the following paper:
|
|
370
|
+
```bibtex
|
|
371
|
+
@inproceedings{ristani2016performance,
|
|
372
|
+
title={Performance measures and a data set for multi-target, multi-camera tracking},
|
|
373
|
+
author={Ristani, Ergys and Solera, Francesco and Zou, Roger and Cucchiara, Rita and Tomasi, Carlo},
|
|
374
|
+
booktitle={European conference on computer vision},
|
|
375
|
+
pages={17--35},
|
|
376
|
+
year={2016},
|
|
377
|
+
organization={Springer}
|
|
378
|
+
}
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
If you use the MOTA metric in your research, please cite the following paper:
|
|
382
|
+
```bibtex
|
|
383
|
+
@article{bernardin2008evaluating,
|
|
384
|
+
title={Evaluating multiple object tracking performance: the clear mot metrics},
|
|
385
|
+
author={Bernardin, Keni and Stiefelhagen, Rainer},
|
|
386
|
+
journal={EURASIP Journal on Image and Video Processing},
|
|
387
|
+
volume={2008},
|
|
388
|
+
pages={1--10},
|
|
389
|
+
year={2008},
|
|
390
|
+
publisher={Springer}
|
|
391
|
+
}
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
---
|
|
395
|
+
|
|
396
|
+
## License
|
|
397
|
+
|
|
398
|
+
This project is licensed under the BSD 2-Clause License - see the
|
|
399
|
+
[LICENSE](LICENSE.txt) file for details.
|
|
400
|
+
|
|
401
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from ctc_metrics.metrics.validation.valid import valid
|
|
2
|
+
from ctc_metrics.metrics.biological.bc import bc
|
|
3
|
+
from ctc_metrics.metrics.biological.ct import ct
|
|
4
|
+
from ctc_metrics.metrics.biological.cca import cca
|
|
5
|
+
from ctc_metrics.metrics.biological.tf import tf
|
|
6
|
+
from ctc_metrics.metrics.technical.seg import seg
|
|
7
|
+
from ctc_metrics.metrics.technical.tra import tra
|
|
8
|
+
from ctc_metrics.metrics.technical.det import det
|
|
9
|
+
from ctc_metrics.metrics.clearmot.mota import mota
|
|
10
|
+
from ctc_metrics.metrics.hota.hota import hota
|
|
11
|
+
from ctc_metrics.metrics.hota.chota import chota
|
|
12
|
+
from ctc_metrics.metrics.identity_metrics.idf1 import idf1
|
|
13
|
+
from ctc_metrics.metrics.others.mt_ml import mtml
|
|
14
|
+
from ctc_metrics.metrics.others.faf import faf
|
|
15
|
+
from ctc_metrics.metrics.technical.op_ctb import op_ctb
|
|
16
|
+
from ctc_metrics.metrics.technical.op_csb import op_csb
|
|
17
|
+
from ctc_metrics.metrics.biological.bio import bio
|
|
18
|
+
from ctc_metrics.metrics.biological.op_clb import op_clb
|
|
19
|
+
from ctc_metrics.metrics.technical.lnk import lnk
|
|
20
|
+
|
|
21
|
+
ALL_METRICS = [
|
|
22
|
+
"Valid", "CHOTA", "BC", "CT", "CCA", "TF", "SEG", "TRA", "DET", "MOTA",
|
|
23
|
+
"HOTA", "IDF1", "MTML", "FAF", "LNK", "OP_CTB", "OP_CSB", "BIO", "OP_CLB"
|
|
24
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def get_ids_that_ends_with_split(
|
|
5
|
+
tracks: np.ndarray
|
|
6
|
+
):
|
|
7
|
+
"""
|
|
8
|
+
Extracts the ids of tracks that end with a cell split.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
tracks: The tracks to check. A numpy nd array with columns:
|
|
12
|
+
- label
|
|
13
|
+
- birth frame
|
|
14
|
+
- end frame
|
|
15
|
+
- parent
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
The ids of tracks that end with a cell split stored in a numpy.ndarray.
|
|
19
|
+
"""
|
|
20
|
+
parents, counts = np.unique(tracks[:, 3], return_counts=True)
|
|
21
|
+
counts = counts[parents > 0]
|
|
22
|
+
parents = parents[parents > 0]
|
|
23
|
+
ends_with_split = parents[counts > 1]
|
|
24
|
+
return ends_with_split
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def calculate_f1_score(
|
|
28
|
+
tp: int,
|
|
29
|
+
fp: int,
|
|
30
|
+
fn: int
|
|
31
|
+
):
|
|
32
|
+
"""
|
|
33
|
+
Calculates the f1 score.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
tp: The number of true positives.
|
|
37
|
+
fp: The number of false positives.
|
|
38
|
+
fn: The number of false negatives.
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
The f1 score.
|
|
42
|
+
"""
|
|
43
|
+
precision = tp / max((tp + fp), 1)
|
|
44
|
+
recall = tp / max((tp + fn), 1)
|
|
45
|
+
f1_score = 2 * (precision * recall) / max((precision + recall), 0.0001)
|
|
46
|
+
return f1_score
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def is_matching(
|
|
50
|
+
id_comp: int,
|
|
51
|
+
id_ref: int,
|
|
52
|
+
mapped_ref: list,
|
|
53
|
+
mapped_comp: list,
|
|
54
|
+
ref_children: np.ndarray,
|
|
55
|
+
comp_children: np.ndarray,
|
|
56
|
+
tr: int,
|
|
57
|
+
tc: int
|
|
58
|
+
):
|
|
59
|
+
"""
|
|
60
|
+
Checks if the reference and the computed track match.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
id_comp: The computed track id.
|
|
64
|
+
id_ref: The reference track id.
|
|
65
|
+
mapped_ref: The matched labels of the ground truth masks.
|
|
66
|
+
mapped_comp: The matched labels of the result masks.
|
|
67
|
+
ref_children: The children ids of the reference track.
|
|
68
|
+
comp_children: The children ids of the computed track.
|
|
69
|
+
tr: The frame of the reference track end.
|
|
70
|
+
tc: The frame of the computed track end.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
True if the reference and the computed track match, False otherwise.
|
|
74
|
+
"""
|
|
75
|
+
# Check if the number of children is the same
|
|
76
|
+
if len(ref_children) != len(comp_children):
|
|
77
|
+
return False
|
|
78
|
+
# Compare parents
|
|
79
|
+
t1, t2 = min(tr, tc), max(tr, tc)
|
|
80
|
+
mr, mc = mapped_ref[t1], mapped_comp[t1]
|
|
81
|
+
if np.sum(mc == id_comp) < 1 or np.sum(mr == id_ref) != 1:
|
|
82
|
+
return False
|
|
83
|
+
ind = np.argwhere(mr == id_ref).squeeze()
|
|
84
|
+
if mc[ind] != id_comp:
|
|
85
|
+
return False
|
|
86
|
+
# Compare children
|
|
87
|
+
mr, mc = np.asarray(mapped_ref[t2 + 1]), np.asarray(mapped_comp[t2 + 1])
|
|
88
|
+
if not np.all(np.isin(comp_children, mc)):
|
|
89
|
+
return False
|
|
90
|
+
if not np.all(np.isin(mr[np.isin(mc, comp_children)], ref_children)):
|
|
91
|
+
return False
|
|
92
|
+
return True
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def bc(
|
|
96
|
+
comp_tracks: np.ndarray,
|
|
97
|
+
ref_tracks: np.ndarray,
|
|
98
|
+
mapped_ref: list,
|
|
99
|
+
mapped_comp: list,
|
|
100
|
+
i: int
|
|
101
|
+
):
|
|
102
|
+
"""
|
|
103
|
+
Computes the branching correctness metric. As described in the paper,
|
|
104
|
+
"An objective comparison of cell-tracking algorithms."
|
|
105
|
+
- Vladimir Ulman et al., Nature methods 2017
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
comp_tracks: The result tracks. A (n,4) numpy ndarray with columns:
|
|
109
|
+
- label
|
|
110
|
+
- birth frame
|
|
111
|
+
- end frame
|
|
112
|
+
- parent
|
|
113
|
+
ref_tracks: The ground truth tracks. A (n,4) numpy ndarray with columns:
|
|
114
|
+
- label
|
|
115
|
+
- birth frame
|
|
116
|
+
- end frame
|
|
117
|
+
- parent
|
|
118
|
+
mapped_ref: The matched labels of the ground truth masks. A list of
|
|
119
|
+
length equal to the number of frames. Each element is a list with
|
|
120
|
+
the matched labels of the ground truth masks in the respective
|
|
121
|
+
frame. The elements are in the same order as the corresponding
|
|
122
|
+
elements in mapped_comp.
|
|
123
|
+
mapped_comp: The matched labels of the result masks. A list of length
|
|
124
|
+
equal to the number of frames. Each element is a list with the
|
|
125
|
+
matched labels of the result masks in the respective frame. The
|
|
126
|
+
elements are in the same order as the corresponding elements in
|
|
127
|
+
mapped_ref.
|
|
128
|
+
i: The maximal allowed error in frames.
|
|
129
|
+
|
|
130
|
+
Returns:
|
|
131
|
+
The branching correctness metric.
|
|
132
|
+
"""
|
|
133
|
+
|
|
134
|
+
# Extract relevant tracks with children in reference
|
|
135
|
+
ends_with_split_ref = get_ids_that_ends_with_split(ref_tracks)
|
|
136
|
+
t_ref = np.array([ref_tracks[ref_tracks[:, 0] == ref][0, 2]
|
|
137
|
+
for ref in ends_with_split_ref])
|
|
138
|
+
if len(ends_with_split_ref) == 0:
|
|
139
|
+
return None
|
|
140
|
+
# Extract relevant tracks with children in computed result
|
|
141
|
+
ends_with_split_comp = get_ids_that_ends_with_split(comp_tracks)
|
|
142
|
+
t_comp = np.asarray([comp_tracks[comp_tracks[:, 0] == comp][0, 2]
|
|
143
|
+
for comp in ends_with_split_comp])
|
|
144
|
+
if len(ends_with_split_comp) == 0:
|
|
145
|
+
return 0
|
|
146
|
+
# Find all matches between reference and computed branching events (mitosis)
|
|
147
|
+
matches = []
|
|
148
|
+
for comp, tc in zip(ends_with_split_comp, t_comp):
|
|
149
|
+
# Find potential matches
|
|
150
|
+
pot_matches = np.abs(t_ref - tc) <= i
|
|
151
|
+
if len(pot_matches) == 0:
|
|
152
|
+
continue
|
|
153
|
+
comp_children = comp_tracks[comp_tracks[:, 3] == comp][:, 0]
|
|
154
|
+
# Evaluate potential matches
|
|
155
|
+
for ref, tr in zip(
|
|
156
|
+
ends_with_split_ref[pot_matches],
|
|
157
|
+
t_ref[pot_matches]
|
|
158
|
+
):
|
|
159
|
+
ref_children = ref_tracks[ref_tracks[:, 3] == ref][:, 0]
|
|
160
|
+
if is_matching(
|
|
161
|
+
comp, ref, mapped_ref, mapped_comp, ref_children,
|
|
162
|
+
comp_children, tr, tc
|
|
163
|
+
):
|
|
164
|
+
matches.append((ref, comp))
|
|
165
|
+
# Calculate BC(i)
|
|
166
|
+
return calculate_f1_score(
|
|
167
|
+
len(matches),
|
|
168
|
+
len(ends_with_split_comp) - len(matches),
|
|
169
|
+
len(ends_with_split_ref) - len(matches))
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
def bio(
|
|
3
|
+
ct: float,
|
|
4
|
+
tf: float,
|
|
5
|
+
bc: float,
|
|
6
|
+
cca: float,
|
|
7
|
+
):
|
|
8
|
+
"""
|
|
9
|
+
Computes the BIO. As described by
|
|
10
|
+
[celltrackingchallenge](http://celltrackingchallenge.net/).
|
|
11
|
+
It is the average of the CT, TF, BC, and CCA metrics. If a metric is not
|
|
12
|
+
available, it is not considered in the average.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
ct: The complete tracking metric.
|
|
16
|
+
tf: The track fractions metric.
|
|
17
|
+
bc: The branching correctness metric.
|
|
18
|
+
cca: The cell cycle accuracy metric.
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
The BIO metric.
|
|
22
|
+
"""
|
|
23
|
+
total_metrics = 0
|
|
24
|
+
if ct is not None:
|
|
25
|
+
total_metrics += 1
|
|
26
|
+
else:
|
|
27
|
+
ct = 0
|
|
28
|
+
if tf is not None:
|
|
29
|
+
total_metrics += 1
|
|
30
|
+
else:
|
|
31
|
+
tf = 0
|
|
32
|
+
if bc is not None:
|
|
33
|
+
total_metrics += 1
|
|
34
|
+
else:
|
|
35
|
+
bc = 0
|
|
36
|
+
if cca is not None:
|
|
37
|
+
total_metrics += 1
|
|
38
|
+
else:
|
|
39
|
+
cca = 0
|
|
40
|
+
bio_score = (ct + tf + bc + cca) / total_metrics
|
|
41
|
+
return bio_score
|