seqseg 0.1.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.
Files changed (65) hide show
  1. seqseg-0.1.0/LICENSE +201 -0
  2. seqseg-0.1.0/PKG-INFO +174 -0
  3. seqseg-0.1.0/README.md +150 -0
  4. seqseg-0.1.0/pyproject.toml +51 -0
  5. seqseg-0.1.0/seqseg/__init__.py +0 -0
  6. seqseg-0.1.0/seqseg/analysis/compute_metrics.py +1184 -0
  7. seqseg-0.1.0/seqseg/analysis/dataset_size_study.py +57 -0
  8. seqseg-0.1.0/seqseg/analysis/eval_dice_assuming_cent.py +271 -0
  9. seqseg-0.1.0/seqseg/analysis/plotting/plot_error_centerline.py +163 -0
  10. seqseg-0.1.0/seqseg/analysis/plotting/plot_functions.py +202 -0
  11. seqseg-0.1.0/seqseg/analysis/plotting/plot_results.py +200 -0
  12. seqseg-0.1.0/seqseg/analysis/plotting/plot_results_time.py +200 -0
  13. seqseg-0.1.0/seqseg/analysis/plotting/plot_scaling.py +37 -0
  14. seqseg-0.1.0/seqseg/analysis/plotting/plot_tracing_results.py +181 -0
  15. seqseg-0.1.0/seqseg/analysis/plotting/plot_training.py +130 -0
  16. seqseg-0.1.0/seqseg/analysis/plotting/results.py +390 -0
  17. seqseg-0.1.0/seqseg/analysis/post_process_results.py +45 -0
  18. seqseg-0.1.0/seqseg/analysis/vis_data/visualize_vtp.py +169 -0
  19. seqseg-0.1.0/seqseg/analysis/vis_data/visualize_vtp_together.py +135 -0
  20. seqseg-0.1.0/seqseg/cent2path.py +78 -0
  21. seqseg-0.1.0/seqseg/centpath.py +164 -0
  22. seqseg-0.1.0/seqseg/config/aorta_tutorial.yaml +48 -0
  23. seqseg-0.1.0/seqseg/config/global.yaml +47 -0
  24. seqseg-0.1.0/seqseg/config/global_aorta.yaml +48 -0
  25. seqseg-0.1.0/seqseg/config/global_cereb.yaml +48 -0
  26. seqseg-0.1.0/seqseg/config/global_coro.yaml +48 -0
  27. seqseg-0.1.0/seqseg/config/global_debug.yaml +47 -0
  28. seqseg-0.1.0/seqseg/config/global_default.yaml +48 -0
  29. seqseg-0.1.0/seqseg/config/global_pulm.yaml +48 -0
  30. seqseg-0.1.0/seqseg/config/global_seg.yaml +48 -0
  31. seqseg-0.1.0/seqseg/config/global_test.yaml +48 -0
  32. seqseg-0.1.0/seqseg/modules/__init__.py +0 -0
  33. seqseg-0.1.0/seqseg/modules/assembly.py +899 -0
  34. seqseg-0.1.0/seqseg/modules/capping.py +215 -0
  35. seqseg-0.1.0/seqseg/modules/centerline.py +2036 -0
  36. seqseg-0.1.0/seqseg/modules/datasets.py +251 -0
  37. seqseg-0.1.0/seqseg/modules/evaluation.py +142 -0
  38. seqseg-0.1.0/seqseg/modules/initialization.py +323 -0
  39. seqseg-0.1.0/seqseg/modules/local_assembly.py +94 -0
  40. seqseg-0.1.0/seqseg/modules/nnunet.py +36 -0
  41. seqseg-0.1.0/seqseg/modules/params.py +10 -0
  42. seqseg-0.1.0/seqseg/modules/prediction.py +286 -0
  43. seqseg-0.1.0/seqseg/modules/sitk_functions.py +369 -0
  44. seqseg-0.1.0/seqseg/modules/sweep.py +63 -0
  45. seqseg-0.1.0/seqseg/modules/tracing.py +853 -0
  46. seqseg-0.1.0/seqseg/modules/tracing_functions.py +585 -0
  47. seqseg-0.1.0/seqseg/modules/vmtk_functions.py +276 -0
  48. seqseg-0.1.0/seqseg/modules/vtk_functions.py +977 -0
  49. seqseg-0.1.0/seqseg/parallel/old_auto_centerline.py +332 -0
  50. seqseg-0.1.0/seqseg/parallel/parallel_auto_centerline.py +626 -0
  51. seqseg-0.1.0/seqseg/parallel/parallel_auto_centerline2.py +632 -0
  52. seqseg-0.1.0/seqseg/parallel/parallel_auto_centerline3.py +687 -0
  53. seqseg-0.1.0/seqseg/parallel/parallel_auto_centerline4.py +728 -0
  54. seqseg-0.1.0/seqseg/seqseg.py +361 -0
  55. seqseg-0.1.0/seqseg/seqseg_plus.py +384 -0
  56. seqseg-0.1.0/seqseg/tests/test_nnunet2.py +64 -0
  57. seqseg-0.1.0/seqseg/tests/test_segmentation.py +18 -0
  58. seqseg-0.1.0/seqseg/tests/test_vtk.py +101 -0
  59. seqseg-0.1.0/seqseg.egg-info/PKG-INFO +174 -0
  60. seqseg-0.1.0/seqseg.egg-info/SOURCES.txt +63 -0
  61. seqseg-0.1.0/seqseg.egg-info/dependency_links.txt +1 -0
  62. seqseg-0.1.0/seqseg.egg-info/entry_points.txt +2 -0
  63. seqseg-0.1.0/seqseg.egg-info/requires.txt +4 -0
  64. seqseg-0.1.0/seqseg.egg-info/top_level.txt +1 -0
  65. seqseg-0.1.0/setup.cfg +4 -0
seqseg-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
seqseg-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,174 @@
1
+ Metadata-Version: 2.4
2
+ Name: seqseg
3
+ Version: 0.1.0
4
+ Summary: A simple deep learning-based medical image blood vessel tracking and segmentation tool.
5
+ Author: Shadden Lab, UC Berkeley
6
+ Author-email: Numi Sveinsson Cepero <numi@berkeley.com>
7
+ License: Apache-2.0
8
+ Project-URL: homepage, https://github.com/numisveinsson/SeqSeg
9
+ Project-URL: repository, https://github.com/numisveinsson/SeqSeg
10
+ Keywords: segmentation,deep learning,medical imaging,nnunet,medical image analysis,medical image segmentation,nnU-Net,blood vessel segmentation,vascular segmentation,vascular tracking
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
16
+ Requires-Python: >=3.8
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: vtk
20
+ Requires-Dist: SimpleITK
21
+ Requires-Dist: PyYAML
22
+ Requires-Dist: nnunetv2
23
+ Dynamic: license-file
24
+
25
+ ![example workflow](https://github.com/numisveinsson/SeqSeg/actions/workflows/python-app.yml/badge.svg)
26
+
27
+ # SeqSeg: Automatic Tracking and Segmentation of Blood Vessels in CT and MR Images
28
+
29
+ See paper [here](https://rdcu.be/dU0wy) for detailed explanations and citation.
30
+
31
+ Below is an example showing the algorithm tracking and segmenting an abdominal aorta in 3D MR image scan:
32
+
33
+ ![](seqseg/assets/mr_model_tracing_fast_shorter.gif)
34
+
35
+ ## How it works
36
+ SeqSeg is a method for automatic tracking and segmentation of blood vessels in medical images. The algorithm uses a neural network to segment the vasculature locally and uses a tracking algorithm to take steps along the direction of the vessel and down bifurcation detected.
37
+
38
+ Here is the workflow of the algorithm:
39
+
40
+ ![](assets/seqseg.png)
41
+
42
+ where the neural network was trained on local subvolume patches of the image:
43
+
44
+ ![](assets/seqseg_training.png)
45
+
46
+ ## Set Up
47
+ SeqSeg relies on [nnU-Net](https://github.com/MIC-DKFZ/nnUNet) for segmentation of the local medical image volumes. You will need model weights to run the algorithm - either use pretrained weights (available) or train a model yourself. After training a nnU-Net model, the weights will be saved in a `nnUNet_results` folder.
48
+
49
+ Main package dependencies:
50
+
51
+ Basic:
52
+ - Python 3.11
53
+
54
+ Machine Learning (Note: must be installed according to nnU-Net instructions):
55
+ - nnU-Net, nnunetv2=2.5.1
56
+ - Pytorch, torch=2.3.1
57
+
58
+ Image and Data Processing:
59
+ - SITK, simpleitk=2.2.1
60
+ - VTK, vtk=9.1.0
61
+ - PyYaml, pyyaml=6.0.1
62
+ - Matplotlib (optional)
63
+ - Pyyaml (optional)
64
+
65
+ and if using VMTK (not required):
66
+ - VMTK
67
+
68
+ Example setup using conda:
69
+ ```bash
70
+ conda create -n seqseg python=3.11
71
+ conda activate seqseg
72
+ conda install ..
73
+ ```
74
+ Example setup using pip (first create a virtual environment, see [here](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/)):
75
+ ```bash
76
+ python3 -m venv seqseg
77
+ source seqseg/bin/activate
78
+ pip install python==3.11
79
+ pip install ...
80
+ ```
81
+ Note: The code is tested with Python 3.11 and nnU-Net 2.5.1. If you are using a different version, please check the compatibility of the packages.
82
+
83
+ ## Testing
84
+
85
+ Current workflow:
86
+ 1. Create conda or virtual environment and install ''Image and Data Processing'' dependencies.
87
+ 2. Test this environment using the test script tests/test.sh
88
+ 3. Install nnunet and pytorch using the instructions [here](https://github.com/MIC-DKFZ/nnUNet/blob/master/documentation/installation_instructions.md).
89
+ 4. Try the full installation according to details below
90
+
91
+ ## Running
92
+
93
+ See [here](https://github.com/numisveinsson/SeqSeg/blob/main/tutorial/tutorial.md) for tutorial on how to run the code.
94
+
95
+ ### Set weights directory
96
+ ```bash
97
+ export nnUNet_results="/path/to/model/weights/nnUnet/nnUNet_results"
98
+ ```
99
+
100
+ ### Activate environment (eg. conda)
101
+ ```bash
102
+ conda activate seqseg
103
+ ```
104
+
105
+ ### Run
106
+ ```bash
107
+ python3 seqseg.py --data_dir data --test_name 3d_fullres --train_dataset Dataset001_AORTAS --config_name global.yml --fold all --img_ext .nii.gz --outdir output --scale 1 --start 0 --stop -1 --max_n_steps 1000 --unit cm
108
+ ```
109
+
110
+ ### Details
111
+
112
+ `seqseg`: Main script to run.
113
+
114
+ Arguments:
115
+
116
+ -`data_dir`: This argument specifies the name of the folder containing the testing data (and test.json if applicable).
117
+
118
+ -`test_name`: This argument specifies the name of the nnUNet test to use. The default value is '3d_fullres'. Other possible values could be '2d', etc.
119
+
120
+ -`train_dataset`: This argument specifies the name of the dataset used to train the nnUNet model. For example, 'Dataset010_SEQCOROASOCACT'.
121
+
122
+ -'config_name': This argument specifies the name of the config file to use. The default value is 'global.yml'.
123
+
124
+ -`fold`: This argument specifies which fold to use for the nnUNet model. The default value is 'all'.
125
+
126
+ -`img_ext`: This argument specifies the image extension. For example, '.nii.gz'.
127
+
128
+ -`outdir`: This argument specifies the output directory where the results will be saved.
129
+
130
+ -`scale`: This argument specifies whether to scale image data. This is needed if the units for the nnUNet model and testing data are different. The default value is 1.
131
+
132
+ -`start`: This argument specifies where to start in the list of testing samples. The default value is 0.
133
+
134
+ -`stop`: This argument specifies where to stop in the list of testing samples. The default value is -1, which means to process all samples until the end of the list.
135
+
136
+ -`max_n_steps`: This argument specifies the maximum number of steps to run the algorithm. The default value is 1000.
137
+
138
+ -`unit`: This argument specifies the unit of the image data. The default value is 'cm'.
139
+
140
+ Data directory: Assumes the following structure:
141
+ - Directory
142
+ - images
143
+ - centerlines (if applicable)
144
+ - truths (if applicable)
145
+ - test.json (if applicable)
146
+
147
+ SeqSeg requires a seed point for initialization. This can be given by either:
148
+ - test.json file: located in data directory (see sample under data)
149
+ - centerline: if centerlines are given, we initialize using the first points of the centerline
150
+ - cardiac mesh: then the aortic valve must be labeled as Region 8 and LV 7
151
+
152
+ ## Config file
153
+ `config/global.yml`: File contains config parameters, default is set but can be changed depending on task
154
+
155
+ We recommend duplicating the file and changing the name to avoid overwriting the default values.
156
+ If so, the config file must be passed as an argument when running the script: `config_name`
157
+
158
+ ## Citation
159
+ When using SeqSeg, please cite the following [paper](https://rdcu.be/dU0wy):
160
+
161
+ ```
162
+ @Article{SveinssonCepero2024,
163
+ author={Sveinsson Cepero, Numi
164
+ and Shadden, Shawn C.},
165
+ title={SeqSeg: Learning Local Segments for Automatic Vascular Model Construction},
166
+ journal={Annals of Biomedical Engineering},
167
+ year={2024},
168
+ month={Sep},
169
+ day={18},
170
+ issn={1573-9686},
171
+ doi={10.1007/s10439-024-03611-z},
172
+ url={https://doi.org/10.1007/s10439-024-03611-z},
173
+ }
174
+ ```
seqseg-0.1.0/README.md ADDED
@@ -0,0 +1,150 @@
1
+ ![example workflow](https://github.com/numisveinsson/SeqSeg/actions/workflows/python-app.yml/badge.svg)
2
+
3
+ # SeqSeg: Automatic Tracking and Segmentation of Blood Vessels in CT and MR Images
4
+
5
+ See paper [here](https://rdcu.be/dU0wy) for detailed explanations and citation.
6
+
7
+ Below is an example showing the algorithm tracking and segmenting an abdominal aorta in 3D MR image scan:
8
+
9
+ ![](seqseg/assets/mr_model_tracing_fast_shorter.gif)
10
+
11
+ ## How it works
12
+ SeqSeg is a method for automatic tracking and segmentation of blood vessels in medical images. The algorithm uses a neural network to segment the vasculature locally and uses a tracking algorithm to take steps along the direction of the vessel and down bifurcation detected.
13
+
14
+ Here is the workflow of the algorithm:
15
+
16
+ ![](assets/seqseg.png)
17
+
18
+ where the neural network was trained on local subvolume patches of the image:
19
+
20
+ ![](assets/seqseg_training.png)
21
+
22
+ ## Set Up
23
+ SeqSeg relies on [nnU-Net](https://github.com/MIC-DKFZ/nnUNet) for segmentation of the local medical image volumes. You will need model weights to run the algorithm - either use pretrained weights (available) or train a model yourself. After training a nnU-Net model, the weights will be saved in a `nnUNet_results` folder.
24
+
25
+ Main package dependencies:
26
+
27
+ Basic:
28
+ - Python 3.11
29
+
30
+ Machine Learning (Note: must be installed according to nnU-Net instructions):
31
+ - nnU-Net, nnunetv2=2.5.1
32
+ - Pytorch, torch=2.3.1
33
+
34
+ Image and Data Processing:
35
+ - SITK, simpleitk=2.2.1
36
+ - VTK, vtk=9.1.0
37
+ - PyYaml, pyyaml=6.0.1
38
+ - Matplotlib (optional)
39
+ - Pyyaml (optional)
40
+
41
+ and if using VMTK (not required):
42
+ - VMTK
43
+
44
+ Example setup using conda:
45
+ ```bash
46
+ conda create -n seqseg python=3.11
47
+ conda activate seqseg
48
+ conda install ..
49
+ ```
50
+ Example setup using pip (first create a virtual environment, see [here](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/)):
51
+ ```bash
52
+ python3 -m venv seqseg
53
+ source seqseg/bin/activate
54
+ pip install python==3.11
55
+ pip install ...
56
+ ```
57
+ Note: The code is tested with Python 3.11 and nnU-Net 2.5.1. If you are using a different version, please check the compatibility of the packages.
58
+
59
+ ## Testing
60
+
61
+ Current workflow:
62
+ 1. Create conda or virtual environment and install ''Image and Data Processing'' dependencies.
63
+ 2. Test this environment using the test script tests/test.sh
64
+ 3. Install nnunet and pytorch using the instructions [here](https://github.com/MIC-DKFZ/nnUNet/blob/master/documentation/installation_instructions.md).
65
+ 4. Try the full installation according to details below
66
+
67
+ ## Running
68
+
69
+ See [here](https://github.com/numisveinsson/SeqSeg/blob/main/tutorial/tutorial.md) for tutorial on how to run the code.
70
+
71
+ ### Set weights directory
72
+ ```bash
73
+ export nnUNet_results="/path/to/model/weights/nnUnet/nnUNet_results"
74
+ ```
75
+
76
+ ### Activate environment (eg. conda)
77
+ ```bash
78
+ conda activate seqseg
79
+ ```
80
+
81
+ ### Run
82
+ ```bash
83
+ python3 seqseg.py --data_dir data --test_name 3d_fullres --train_dataset Dataset001_AORTAS --config_name global.yml --fold all --img_ext .nii.gz --outdir output --scale 1 --start 0 --stop -1 --max_n_steps 1000 --unit cm
84
+ ```
85
+
86
+ ### Details
87
+
88
+ `seqseg`: Main script to run.
89
+
90
+ Arguments:
91
+
92
+ -`data_dir`: This argument specifies the name of the folder containing the testing data (and test.json if applicable).
93
+
94
+ -`test_name`: This argument specifies the name of the nnUNet test to use. The default value is '3d_fullres'. Other possible values could be '2d', etc.
95
+
96
+ -`train_dataset`: This argument specifies the name of the dataset used to train the nnUNet model. For example, 'Dataset010_SEQCOROASOCACT'.
97
+
98
+ -'config_name': This argument specifies the name of the config file to use. The default value is 'global.yml'.
99
+
100
+ -`fold`: This argument specifies which fold to use for the nnUNet model. The default value is 'all'.
101
+
102
+ -`img_ext`: This argument specifies the image extension. For example, '.nii.gz'.
103
+
104
+ -`outdir`: This argument specifies the output directory where the results will be saved.
105
+
106
+ -`scale`: This argument specifies whether to scale image data. This is needed if the units for the nnUNet model and testing data are different. The default value is 1.
107
+
108
+ -`start`: This argument specifies where to start in the list of testing samples. The default value is 0.
109
+
110
+ -`stop`: This argument specifies where to stop in the list of testing samples. The default value is -1, which means to process all samples until the end of the list.
111
+
112
+ -`max_n_steps`: This argument specifies the maximum number of steps to run the algorithm. The default value is 1000.
113
+
114
+ -`unit`: This argument specifies the unit of the image data. The default value is 'cm'.
115
+
116
+ Data directory: Assumes the following structure:
117
+ - Directory
118
+ - images
119
+ - centerlines (if applicable)
120
+ - truths (if applicable)
121
+ - test.json (if applicable)
122
+
123
+ SeqSeg requires a seed point for initialization. This can be given by either:
124
+ - test.json file: located in data directory (see sample under data)
125
+ - centerline: if centerlines are given, we initialize using the first points of the centerline
126
+ - cardiac mesh: then the aortic valve must be labeled as Region 8 and LV 7
127
+
128
+ ## Config file
129
+ `config/global.yml`: File contains config parameters, default is set but can be changed depending on task
130
+
131
+ We recommend duplicating the file and changing the name to avoid overwriting the default values.
132
+ If so, the config file must be passed as an argument when running the script: `config_name`
133
+
134
+ ## Citation
135
+ When using SeqSeg, please cite the following [paper](https://rdcu.be/dU0wy):
136
+
137
+ ```
138
+ @Article{SveinssonCepero2024,
139
+ author={Sveinsson Cepero, Numi
140
+ and Shadden, Shawn C.},
141
+ title={SeqSeg: Learning Local Segments for Automatic Vascular Model Construction},
142
+ journal={Annals of Biomedical Engineering},
143
+ year={2024},
144
+ month={Sep},
145
+ day={18},
146
+ issn={1573-9686},
147
+ doi={10.1007/s10439-024-03611-z},
148
+ url={https://doi.org/10.1007/s10439-024-03611-z},
149
+ }
150
+ ```
@@ -0,0 +1,51 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "seqseg"
7
+ version = "0.1.0"
8
+ description = "A simple deep learning-based medical image blood vessel tracking and segmentation tool."
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = {text = "Apache-2.0"}
12
+ authors = [
13
+ {name = "Numi Sveinsson Cepero", email = "numi@berkeley.com"},
14
+ {name = "Shadden Lab, UC Berkeley"}
15
+ ]
16
+ keywords = [
17
+ "segmentation",
18
+ "deep learning",
19
+ "medical imaging",
20
+ "nnunet",
21
+ "medical image analysis",
22
+ "medical image segmentation",
23
+ "nnU-Net",
24
+ "blood vessel segmentation",
25
+ "vascular segmentation",
26
+ "vascular tracking"
27
+ ]
28
+ classifiers = [
29
+ "Programming Language :: Python :: 3",
30
+ "License :: OSI Approved :: MIT License",
31
+ "Operating System :: OS Independent",
32
+ "Intended Audience :: Science/Research",
33
+ "Topic :: Scientific/Engineering :: Medical Science Apps."
34
+ ]
35
+
36
+ dependencies = [
37
+ "vtk",
38
+ "SimpleITK",
39
+ "PyYAML",
40
+ "nnunetv2",
41
+ ]
42
+
43
+ [project.scripts]
44
+ seqseg = "seqseg.seqseg:main"
45
+
46
+ [project.urls]
47
+ homepage = "https://github.com/numisveinsson/SeqSeg"
48
+ repository = "https://github.com/numisveinsson/SeqSeg"
49
+
50
+ [tool.setuptools]
51
+ package-data = { "seqseg" = ["config/*.yaml"] }
File without changes