neuralib-parser 0.7.0__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.
- neuralib_parser-0.7.0/LICENSE +28 -0
- neuralib_parser-0.7.0/PKG-INFO +138 -0
- neuralib_parser-0.7.0/README.md +95 -0
- neuralib_parser-0.7.0/pyproject.toml +53 -0
- neuralib_parser-0.7.0/setup.cfg +4 -0
- neuralib_parser-0.7.0/src/neuralib/cellpose/__init__.py +1 -0
- neuralib_parser-0.7.0/src/neuralib/cellpose/core.py +190 -0
- neuralib_parser-0.7.0/src/neuralib/deeplabcut/__init__.py +1 -0
- neuralib_parser-0.7.0/src/neuralib/deeplabcut/core.py +267 -0
- neuralib_parser-0.7.0/src/neuralib/facemap/__init__.py +1 -0
- neuralib_parser-0.7.0/src/neuralib/facemap/core.py +313 -0
- neuralib_parser-0.7.0/src/neuralib/facemap/plot.py +91 -0
- neuralib_parser-0.7.0/src/neuralib/facemap/util.py +51 -0
- neuralib_parser-0.7.0/src/neuralib/morpho/__init__.py +0 -0
- neuralib_parser-0.7.0/src/neuralib/morpho/swc.py +408 -0
- neuralib_parser-0.7.0/src/neuralib/scan/__init__.py +0 -0
- neuralib_parser-0.7.0/src/neuralib/scan/core.py +156 -0
- neuralib_parser-0.7.0/src/neuralib/scan/czi.py +209 -0
- neuralib_parser-0.7.0/src/neuralib/scan/lsm.py +155 -0
- neuralib_parser-0.7.0/src/neuralib/scanbox/__init__.py +1 -0
- neuralib_parser-0.7.0/src/neuralib/scanbox/core.py +286 -0
- neuralib_parser-0.7.0/src/neuralib/scanbox/view.py +180 -0
- neuralib_parser-0.7.0/src/neuralib/stardist/__init__.py +1 -0
- neuralib_parser-0.7.0/src/neuralib/stardist/base.py +161 -0
- neuralib_parser-0.7.0/src/neuralib/stardist/core.py +214 -0
- neuralib_parser-0.7.0/src/neuralib/stardist/run_2d.py +103 -0
- neuralib_parser-0.7.0/src/neuralib/suite2p/__init__.py +3 -0
- neuralib_parser-0.7.0/src/neuralib/suite2p/core.py +561 -0
- neuralib_parser-0.7.0/src/neuralib/suite2p/plot.py +83 -0
- neuralib_parser-0.7.0/src/neuralib/suite2p/signals.py +265 -0
- neuralib_parser-0.7.0/src/neuralib_parser.egg-info/PKG-INFO +138 -0
- neuralib_parser-0.7.0/src/neuralib_parser.egg-info/SOURCES.txt +42 -0
- neuralib_parser-0.7.0/src/neuralib_parser.egg-info/dependency_links.txt +1 -0
- neuralib_parser-0.7.0/src/neuralib_parser.egg-info/requires.txt +26 -0
- neuralib_parser-0.7.0/src/neuralib_parser.egg-info/top_level.txt +1 -0
- neuralib_parser-0.7.0/test/test_cellpose.py +28 -0
- neuralib_parser-0.7.0/test/test_czi.py +54 -0
- neuralib_parser-0.7.0/test/test_dlc.py +44 -0
- neuralib_parser-0.7.0/test/test_facemap.py +69 -0
- neuralib_parser-0.7.0/test/test_lsm.py +25 -0
- neuralib_parser-0.7.0/test/test_sbx.py +6 -0
- neuralib_parser-0.7.0/test/test_stardist.py +51 -0
- neuralib_parser-0.7.0/test/test_suite2p.py +34 -0
- neuralib_parser-0.7.0/test/test_swc.py +54 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023, YT.WEI
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: neuralib-parser
|
|
3
|
+
Version: 0.7.0
|
|
4
|
+
Summary: Parsers for output from open-source packages or specific devices
|
|
5
|
+
Author-email: Yu-Ting Wei <ytsimon2004@gmail.com>, Ta-Shun Su <antoniost29@gmail.com>
|
|
6
|
+
License: BSD-3-Clause
|
|
7
|
+
Project-URL: Homepage, https://github.com/ytsimon2004/neuralib2
|
|
8
|
+
Project-URL: Documentation, https://neuralib2.readthedocs.io/en/latest/index.html
|
|
9
|
+
Project-URL: Repository, https://github.com/ytsimon2004/neuralib2
|
|
10
|
+
Project-URL: Issues, https://github.com/ytsimon2004/neuralib2/issues
|
|
11
|
+
Keywords: Parser,Segmentation,Morphology
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
15
|
+
Classifier: Natural Language :: English
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering
|
|
18
|
+
Classifier: Intended Audience :: Science/Research
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: <3.13,>=3.11
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: neuralib-utils[all]>=0.7.0
|
|
24
|
+
Requires-Dist: numpy
|
|
25
|
+
Provides-Extra: stardist
|
|
26
|
+
Requires-Dist: stardist; extra == "stardist"
|
|
27
|
+
Requires-Dist: roifile; extra == "stardist"
|
|
28
|
+
Requires-Dist: tensorflow; extra == "stardist"
|
|
29
|
+
Requires-Dist: numpy<2.0; extra == "stardist" and extra == "stardist"
|
|
30
|
+
Requires-Dist: napari; extra == "stardist"
|
|
31
|
+
Provides-Extra: suite2p
|
|
32
|
+
Requires-Dist: neuralib-imaging>=0.7.0; extra == "suite2p"
|
|
33
|
+
Provides-Extra: czi
|
|
34
|
+
Requires-Dist: aicspylibczi; extra == "czi"
|
|
35
|
+
Requires-Dist: xmltodict; extra == "czi"
|
|
36
|
+
Provides-Extra: sbx
|
|
37
|
+
Requires-Dist: sbxreader; extra == "sbx"
|
|
38
|
+
Provides-Extra: all
|
|
39
|
+
Requires-Dist: neuralib-parser[suite2p]; extra == "all"
|
|
40
|
+
Requires-Dist: neuralib-parser[sbx]; extra == "all"
|
|
41
|
+
Requires-Dist: tifffile; extra == "all"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# neuralib-parser
|
|
45
|
+
|
|
46
|
+
Data parsers for neuroscience research tools and file formats, providing unified interfaces for segmentation,
|
|
47
|
+
morphology, imaging, tracking, and confocal microscopy data.
|
|
48
|
+
|
|
49
|
+
## Overview
|
|
50
|
+
|
|
51
|
+
`neuralib-parser` provides Python parsers and data structures for output from open-source packages and specific imaging
|
|
52
|
+
devices. It includes:
|
|
53
|
+
|
|
54
|
+
- **Segmentation**: Cellpose, StarDist cell segmentation
|
|
55
|
+
- **Morphology**: SWC neuron morphology files
|
|
56
|
+
- **Imaging**: Suite2p, Scanbox data formats
|
|
57
|
+
- **Tracking**: DeepLabCut, Facemap behavioral tracking
|
|
58
|
+
- **Confocal Scans**: Zeiss CZI, LSM file formats
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
## Installation
|
|
62
|
+
|
|
63
|
+
### From PyPI
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install neuralib-parser
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### With Optional Dependencies
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# StarDist support (requires numpy<2.0)
|
|
73
|
+
pip install neuralib-parser[stardist]
|
|
74
|
+
|
|
75
|
+
# Suite2p integration
|
|
76
|
+
pip install neuralib-parser[suite2p]
|
|
77
|
+
|
|
78
|
+
# Zeiss CZI format support
|
|
79
|
+
pip install neuralib-parser[czi]
|
|
80
|
+
|
|
81
|
+
# Scanbox reader
|
|
82
|
+
pip install neuralib-parser[sbx]
|
|
83
|
+
|
|
84
|
+
# All features (excludes stardist due to numpy<2.0 constraint)
|
|
85
|
+
pip install neuralib-parser[all]
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### From Source (uv recommended)
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
git clone https://github.com/ytsimon2004/neuralib2.git
|
|
92
|
+
cd neuralib2/packages/neuralib-parser
|
|
93
|
+
uv pip install -e . # Basic installation
|
|
94
|
+
uv pip install -e ".[all]" # With optional features
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Requirements
|
|
98
|
+
|
|
99
|
+
- Python 3.11 or 3.12
|
|
100
|
+
- Core dependencies: `neuralib-utils`, `numpy`
|
|
101
|
+
- See `pyproject.toml` for optional dependencies
|
|
102
|
+
|
|
103
|
+
## Documentation
|
|
104
|
+
|
|
105
|
+
- **Main Documentation**: [https://neuralib2.readthedocs.io/](https://neuralib2.readthedocs.io/en/latest/index.html)
|
|
106
|
+
- **GitHub Repository**: [https://github.com/ytsimon2004/neuralib2](https://github.com/ytsimon2004/neuralib2)
|
|
107
|
+
- **Issue Tracker**: [https://github.com/ytsimon2004/neuralib2/issues](https://github.com/ytsimon2004/neuralib2/issues)
|
|
108
|
+
|
|
109
|
+
## Important Notes
|
|
110
|
+
|
|
111
|
+
### StarDist and NumPy 2.0
|
|
112
|
+
|
|
113
|
+
StarDist requires `numpy<2.0` due to upstream compatibility. The `stardist` extra explicitly pins this constraint:
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
BSD 3-Clause License. See LICENSE file for details.
|
|
118
|
+
|
|
119
|
+
## Contributing
|
|
120
|
+
|
|
121
|
+
Contributions are welcome! Please:
|
|
122
|
+
|
|
123
|
+
1. Fork the repository
|
|
124
|
+
2. Create a feature branch
|
|
125
|
+
3. Submit a pull request with clear description
|
|
126
|
+
|
|
127
|
+
For bug reports and feature requests, use the [GitHub issue tracker](https://github.com/ytsimon2004/neuralib2/issues).
|
|
128
|
+
|
|
129
|
+
## Acknowledgments
|
|
130
|
+
|
|
131
|
+
This package provides interfaces to:
|
|
132
|
+
|
|
133
|
+
- [Suite2p](https://github.com/MouseLand/suite2p) - Calcium imaging data analysis
|
|
134
|
+
- [Scanbox](http://scanbox.org/) - Two-photon imaging system
|
|
135
|
+
- [StarDist](https://github.com/stardist/stardist) - Cell segmentation
|
|
136
|
+
- [Cellpose](https://github.com/MouseLand/cellpose) - Cell segmentation
|
|
137
|
+
- [DeepLabCut](https://github.com/DeepLabCut/DeepLabCut) - Pose estimation
|
|
138
|
+
- [Facemap](https://github.com/MouseLand/facemap) - Behavioral video analysis
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# neuralib-parser
|
|
2
|
+
|
|
3
|
+
Data parsers for neuroscience research tools and file formats, providing unified interfaces for segmentation,
|
|
4
|
+
morphology, imaging, tracking, and confocal microscopy data.
|
|
5
|
+
|
|
6
|
+
## Overview
|
|
7
|
+
|
|
8
|
+
`neuralib-parser` provides Python parsers and data structures for output from open-source packages and specific imaging
|
|
9
|
+
devices. It includes:
|
|
10
|
+
|
|
11
|
+
- **Segmentation**: Cellpose, StarDist cell segmentation
|
|
12
|
+
- **Morphology**: SWC neuron morphology files
|
|
13
|
+
- **Imaging**: Suite2p, Scanbox data formats
|
|
14
|
+
- **Tracking**: DeepLabCut, Facemap behavioral tracking
|
|
15
|
+
- **Confocal Scans**: Zeiss CZI, LSM file formats
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
### From PyPI
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install neuralib-parser
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### With Optional Dependencies
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# StarDist support (requires numpy<2.0)
|
|
30
|
+
pip install neuralib-parser[stardist]
|
|
31
|
+
|
|
32
|
+
# Suite2p integration
|
|
33
|
+
pip install neuralib-parser[suite2p]
|
|
34
|
+
|
|
35
|
+
# Zeiss CZI format support
|
|
36
|
+
pip install neuralib-parser[czi]
|
|
37
|
+
|
|
38
|
+
# Scanbox reader
|
|
39
|
+
pip install neuralib-parser[sbx]
|
|
40
|
+
|
|
41
|
+
# All features (excludes stardist due to numpy<2.0 constraint)
|
|
42
|
+
pip install neuralib-parser[all]
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### From Source (uv recommended)
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
git clone https://github.com/ytsimon2004/neuralib2.git
|
|
49
|
+
cd neuralib2/packages/neuralib-parser
|
|
50
|
+
uv pip install -e . # Basic installation
|
|
51
|
+
uv pip install -e ".[all]" # With optional features
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Requirements
|
|
55
|
+
|
|
56
|
+
- Python 3.11 or 3.12
|
|
57
|
+
- Core dependencies: `neuralib-utils`, `numpy`
|
|
58
|
+
- See `pyproject.toml` for optional dependencies
|
|
59
|
+
|
|
60
|
+
## Documentation
|
|
61
|
+
|
|
62
|
+
- **Main Documentation**: [https://neuralib2.readthedocs.io/](https://neuralib2.readthedocs.io/en/latest/index.html)
|
|
63
|
+
- **GitHub Repository**: [https://github.com/ytsimon2004/neuralib2](https://github.com/ytsimon2004/neuralib2)
|
|
64
|
+
- **Issue Tracker**: [https://github.com/ytsimon2004/neuralib2/issues](https://github.com/ytsimon2004/neuralib2/issues)
|
|
65
|
+
|
|
66
|
+
## Important Notes
|
|
67
|
+
|
|
68
|
+
### StarDist and NumPy 2.0
|
|
69
|
+
|
|
70
|
+
StarDist requires `numpy<2.0` due to upstream compatibility. The `stardist` extra explicitly pins this constraint:
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
BSD 3-Clause License. See LICENSE file for details.
|
|
75
|
+
|
|
76
|
+
## Contributing
|
|
77
|
+
|
|
78
|
+
Contributions are welcome! Please:
|
|
79
|
+
|
|
80
|
+
1. Fork the repository
|
|
81
|
+
2. Create a feature branch
|
|
82
|
+
3. Submit a pull request with clear description
|
|
83
|
+
|
|
84
|
+
For bug reports and feature requests, use the [GitHub issue tracker](https://github.com/ytsimon2004/neuralib2/issues).
|
|
85
|
+
|
|
86
|
+
## Acknowledgments
|
|
87
|
+
|
|
88
|
+
This package provides interfaces to:
|
|
89
|
+
|
|
90
|
+
- [Suite2p](https://github.com/MouseLand/suite2p) - Calcium imaging data analysis
|
|
91
|
+
- [Scanbox](http://scanbox.org/) - Two-photon imaging system
|
|
92
|
+
- [StarDist](https://github.com/stardist/stardist) - Cell segmentation
|
|
93
|
+
- [Cellpose](https://github.com/MouseLand/cellpose) - Cell segmentation
|
|
94
|
+
- [DeepLabCut](https://github.com/DeepLabCut/DeepLabCut) - Pose estimation
|
|
95
|
+
- [Facemap](https://github.com/MouseLand/facemap) - Behavioral video analysis
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "neuralib-parser"
|
|
3
|
+
version = "0.7.0"
|
|
4
|
+
requires-python = ">=3.11,<3.13"
|
|
5
|
+
description = "Parsers for output from open-source packages or specific devices"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Yu-Ting Wei", email = "ytsimon2004@gmail.com" },
|
|
8
|
+
{ name = "Ta-Shun Su", email = "antoniost29@gmail.com" }
|
|
9
|
+
]
|
|
10
|
+
license = { text = "BSD-3-Clause" }
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
keywords = ["Parser", "Segmentation", "Morphology"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3.11",
|
|
15
|
+
"Programming Language :: Python :: 3.12",
|
|
16
|
+
"License :: OSI Approved :: BSD License",
|
|
17
|
+
"Natural Language :: English",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Topic :: Scientific/Engineering",
|
|
20
|
+
'Intended Audience :: Science/Research',
|
|
21
|
+
"Typing :: Typed",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
dependencies = [
|
|
25
|
+
"neuralib-utils[all]>=0.7.0",
|
|
26
|
+
"numpy",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
|
|
31
|
+
stardist = ["stardist", "roifile", "tensorflow", "numpy<2.0; extra == 'stardist'", "napari"]
|
|
32
|
+
suite2p = ["neuralib-imaging>=0.7.0"]
|
|
33
|
+
czi = ["aicspylibczi", "xmltodict"]
|
|
34
|
+
sbx = ["sbxreader"]
|
|
35
|
+
|
|
36
|
+
all = [
|
|
37
|
+
"neuralib-parser[suite2p]",
|
|
38
|
+
"neuralib-parser[sbx]",
|
|
39
|
+
"tifffile"
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[project.urls]
|
|
43
|
+
Homepage = "https://github.com/ytsimon2004/neuralib2"
|
|
44
|
+
Documentation = "https://neuralib2.readthedocs.io/en/latest/index.html"
|
|
45
|
+
Repository = "https://github.com/ytsimon2004/neuralib2"
|
|
46
|
+
Issues = "https://github.com/ytsimon2004/neuralib2/issues"
|
|
47
|
+
|
|
48
|
+
[build-system]
|
|
49
|
+
build-backend = "setuptools.build_meta"
|
|
50
|
+
requires = ["setuptools>=61.0"]
|
|
51
|
+
|
|
52
|
+
[tool.setuptools.packages.find]
|
|
53
|
+
where = ["src"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .core import *
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
from typing import Self
|
|
7
|
+
|
|
8
|
+
from neuralib.typing import PathLike
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
'read_cellpose',
|
|
12
|
+
'cellpose_point_roi_helper',
|
|
13
|
+
'CellposeSegmentation'
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def read_cellpose(file: PathLike) -> CellposeSegmentation:
|
|
18
|
+
"""
|
|
19
|
+
Read a cellpose segmentation result file
|
|
20
|
+
|
|
21
|
+
:param file: cellpose segmentation result ``.npy`` file
|
|
22
|
+
:return: :class:`CellposeSegmentation`
|
|
23
|
+
"""
|
|
24
|
+
return CellposeSegmentation.load(file)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def cellpose_point_roi_helper(file: PathLike, output: PathLike) -> None:
|
|
28
|
+
"""
|
|
29
|
+
Read a cellpose segmentation result and convert the segmentation result to point coordinates
|
|
30
|
+
|
|
31
|
+
:param file: cellpose segmentation result ``.npy`` file
|
|
32
|
+
:param output: ``*.roi`` output file path
|
|
33
|
+
"""
|
|
34
|
+
CellposeSegmentation.load(file).to_roi(output)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class CellposeSegmentation:
|
|
38
|
+
"""`Cellpose <https://github.com/MouseLand/cellpose>`_ segmentation results
|
|
39
|
+
|
|
40
|
+
`Dimension parameters`:
|
|
41
|
+
|
|
42
|
+
N = Number of segmented cells
|
|
43
|
+
|
|
44
|
+
W = Image width
|
|
45
|
+
|
|
46
|
+
H = Image height
|
|
47
|
+
|
|
48
|
+
.. seealso::
|
|
49
|
+
|
|
50
|
+
`Cellpose Native Doc <https://cellpose.readthedocs.io/en/latest/outputs.html#seg-npy-output>`_
|
|
51
|
+
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
def __init__(self, outlines, masks, chan_choose, ismanual, flows, diameter, filename):
|
|
55
|
+
self._outlines = outlines
|
|
56
|
+
self._masks = masks
|
|
57
|
+
self._chan_choose = chan_choose
|
|
58
|
+
self._is_manual = ismanual
|
|
59
|
+
self._flows = flows
|
|
60
|
+
self._diameter = diameter
|
|
61
|
+
|
|
62
|
+
self._filename = filename
|
|
63
|
+
|
|
64
|
+
@classmethod
|
|
65
|
+
def load(cls, file: PathLike) -> Self:
|
|
66
|
+
"""
|
|
67
|
+
Load a cellpose segmentation result
|
|
68
|
+
|
|
69
|
+
:param file: cellpose segmentation result ``.npy`` file
|
|
70
|
+
:return: :class:`CellposeSegmentation`
|
|
71
|
+
"""
|
|
72
|
+
dat = np.load(file, allow_pickle=True).item()
|
|
73
|
+
return cls(**dat)
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def n_segmentation(self) -> int:
|
|
77
|
+
"""number of segmented cells"""
|
|
78
|
+
return len(self._is_manual)
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def width(self):
|
|
82
|
+
"""image width"""
|
|
83
|
+
return self._outlines.shape[1]
|
|
84
|
+
|
|
85
|
+
@property
|
|
86
|
+
def height(self):
|
|
87
|
+
"""image height"""
|
|
88
|
+
return self._outlines.shape[0]
|
|
89
|
+
|
|
90
|
+
@property
|
|
91
|
+
def filename(self) -> Path:
|
|
92
|
+
"""filepath of image"""
|
|
93
|
+
return Path(self._filename)
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def outlines(self) -> np.ndarray:
|
|
97
|
+
"""outlines of ROIs (0 = NO outline; 1,2,… = outline labels). `Array[uint16, [H, W]]`"""
|
|
98
|
+
return self._outlines
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
def masks(self) -> np.ndarray:
|
|
102
|
+
"""each pixel in the image is assigned to an ROI (0 = NO ROI; 1,2,… = ROI labels). `Array[uint16, [H, W]]` """
|
|
103
|
+
return self._masks
|
|
104
|
+
|
|
105
|
+
@property
|
|
106
|
+
def chan_choose(self) -> list[int]:
|
|
107
|
+
"""channels that you chose in GUI (0=gray/none, 1=red, 2=green, 3=blue)"""
|
|
108
|
+
return self._chan_choose
|
|
109
|
+
|
|
110
|
+
@property
|
|
111
|
+
def flows(self) -> list[np.ndarray]:
|
|
112
|
+
"""
|
|
113
|
+
flows[0] is XY flow in RGB
|
|
114
|
+
|
|
115
|
+
flows[1] is the cell probability in range 0-255 instead of -10.0 to 10.0
|
|
116
|
+
|
|
117
|
+
flows[2] is Z flow in range 0-255 (if it exists, otherwise zeros),
|
|
118
|
+
|
|
119
|
+
flows[3] is [dY, dX, cellprob] (or [dZ, dY, dX, cellprob] for 3D), flows[4] is pixel destinations (for internal use)
|
|
120
|
+
"""
|
|
121
|
+
return self._flows
|
|
122
|
+
|
|
123
|
+
@property
|
|
124
|
+
def diameter(self) -> float:
|
|
125
|
+
"""cell body diameter"""
|
|
126
|
+
return self._diameter
|
|
127
|
+
|
|
128
|
+
@property
|
|
129
|
+
def is_manual(self) -> np.ndarray:
|
|
130
|
+
"""whether or not mask k was manually drawn or computed by the cellpose algorithm. `Array[bool, N]`"""
|
|
131
|
+
return self._is_manual
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def nan_masks(self) -> np.ndarray:
|
|
135
|
+
"""value 0 in :attr:`CellposeSegmentation.masks` to nan"""
|
|
136
|
+
masks = self.masks.copy().astype(np.float_)
|
|
137
|
+
masks[masks == 0] = np.nan
|
|
138
|
+
|
|
139
|
+
return masks
|
|
140
|
+
|
|
141
|
+
@property
|
|
142
|
+
def nan_outlines(self) -> np.ndarray:
|
|
143
|
+
"""value 0 in :attr:`CellposeSegmentation.outlines` to nan"""
|
|
144
|
+
outlines = self.outlines.copy().astype(np.float_)
|
|
145
|
+
outlines[outlines == 0] = np.nan
|
|
146
|
+
|
|
147
|
+
return outlines
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def points(self) -> np.ndarray:
|
|
151
|
+
"""Calculate center of each segmented area in XY pixel. `Array[int, [N, 2]]`"""
|
|
152
|
+
centers = self._calculate_centers()
|
|
153
|
+
return np.round(centers).astype(int)
|
|
154
|
+
|
|
155
|
+
# noinspection PyTypeChecker
|
|
156
|
+
def to_roi(self, output_file: PathLike):
|
|
157
|
+
"""
|
|
158
|
+
Covert segmented roi to point roi, and save it as ``.roi`` for imageJ.
|
|
159
|
+
|
|
160
|
+
:param output_file: ``*.roi`` output file path
|
|
161
|
+
"""
|
|
162
|
+
from roifile import ImagejRoi, ROI_TYPE, ROI_OPTIONS
|
|
163
|
+
|
|
164
|
+
if Path(output_file).suffix != '.roi':
|
|
165
|
+
raise ValueError('output file must have .roi extension')
|
|
166
|
+
|
|
167
|
+
points = np.fliplr(self.points) # XY rotate in .roi format
|
|
168
|
+
roi = ImagejRoi(
|
|
169
|
+
roitype=ROI_TYPE.POINT,
|
|
170
|
+
options=ROI_OPTIONS.PROMPT_BEFORE_DELETING | ROI_OPTIONS.SUB_PIXEL_RESOLUTION,
|
|
171
|
+
n_coordinates=self.points.shape[0],
|
|
172
|
+
integer_coordinates=points,
|
|
173
|
+
subpixel_coordinates=points
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
roi.tofile(output_file)
|
|
177
|
+
|
|
178
|
+
def _calculate_centers(self):
|
|
179
|
+
"""calculate center of each segmented area in XY pixel"""
|
|
180
|
+
labels = np.unique(self.masks)
|
|
181
|
+
labels = labels[labels != 0] # remove background
|
|
182
|
+
|
|
183
|
+
n_neurons = len(labels)
|
|
184
|
+
centers = np.zeros((n_neurons, 2))
|
|
185
|
+
for i, label in enumerate(labels):
|
|
186
|
+
segment_coords = np.argwhere(self.masks == label)
|
|
187
|
+
center = segment_coords.mean(axis=0)
|
|
188
|
+
centers[i] = center
|
|
189
|
+
|
|
190
|
+
return centers
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .core import *
|