pydicomrt 0.4.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.
- pydicomrt-0.4.0/.gitignore +201 -0
- pydicomrt-0.4.0/LICENSE +21 -0
- pydicomrt-0.4.0/PKG-INFO +125 -0
- pydicomrt-0.4.0/README.md +110 -0
- pydicomrt-0.4.0/pyproject.toml +24 -0
- pydicomrt-0.4.0/src/pydicomrt/__init__.py +2 -0
- pydicomrt-0.4.0/src/pydicomrt/ct/ct_ds_iod.py +40 -0
- pydicomrt-0.4.0/src/pydicomrt/dose/__init__.py +0 -0
- pydicomrt-0.4.0/src/pydicomrt/dose/builder.py +156 -0
- pydicomrt-0.4.0/src/pydicomrt/dose/dose_ds_iod.py +42 -0
- pydicomrt-0.4.0/src/pydicomrt/reg/__init__.py +0 -0
- pydicomrt-0.4.0/src/pydicomrt/reg/builder.py +21 -0
- pydicomrt-0.4.0/src/pydicomrt/reg/check.py +30 -0
- pydicomrt-0.4.0/src/pydicomrt/reg/ds_reg_ds_iod.py +40 -0
- pydicomrt-0.4.0/src/pydicomrt/reg/parser.py +29 -0
- pydicomrt-0.4.0/src/pydicomrt/reg/s_reg_ds_iod.py +38 -0
- pydicomrt-0.4.0/src/pydicomrt/reg/sitk_reg_method.py +141 -0
- pydicomrt-0.4.0/src/pydicomrt/rs/__init__.py +46 -0
- pydicomrt-0.4.0/src/pydicomrt/rs/add_new_roi.py +50 -0
- pydicomrt-0.4.0/src/pydicomrt/rs/builder.py +130 -0
- pydicomrt-0.4.0/src/pydicomrt/rs/checker.py +79 -0
- pydicomrt-0.4.0/src/pydicomrt/rs/contour_process_method.py +218 -0
- pydicomrt-0.4.0/src/pydicomrt/rs/make_contour_sequence.py +147 -0
- pydicomrt-0.4.0/src/pydicomrt/rs/packer.py +165 -0
- pydicomrt-0.4.0/src/pydicomrt/rs/parser.py +76 -0
- pydicomrt-0.4.0/src/pydicomrt/rs/rs_ds_iod.py +63 -0
- pydicomrt-0.4.0/src/pydicomrt/rs/rs_to_volume.py +362 -0
- pydicomrt-0.4.0/src/pydicomrt/utils/__init__.py +12 -0
- pydicomrt-0.4.0/src/pydicomrt/utils/coordinate_transform.py +82 -0
- pydicomrt-0.4.0/src/pydicomrt/utils/image_series_loader.py +75 -0
- pydicomrt-0.4.0/src/pydicomrt/utils/sitk_transform.py +150 -0
- pydicomrt-0.4.0/src/pydicomrt/utils/validate_dcm_info.py +122 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
|
|
110
|
+
# pdm
|
|
111
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
112
|
+
#pdm.lock
|
|
113
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
114
|
+
# in version control.
|
|
115
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
116
|
+
.pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
121
|
+
__pypackages__/
|
|
122
|
+
|
|
123
|
+
# Celery stuff
|
|
124
|
+
celerybeat-schedule
|
|
125
|
+
celerybeat.pid
|
|
126
|
+
|
|
127
|
+
# SageMath parsed files
|
|
128
|
+
*.sage.py
|
|
129
|
+
|
|
130
|
+
# Environments
|
|
131
|
+
.env
|
|
132
|
+
.venv
|
|
133
|
+
env/
|
|
134
|
+
venv/
|
|
135
|
+
ENV/
|
|
136
|
+
env.bak/
|
|
137
|
+
venv.bak/
|
|
138
|
+
|
|
139
|
+
# Spyder project settings
|
|
140
|
+
.spyderproject
|
|
141
|
+
.spyproject
|
|
142
|
+
|
|
143
|
+
# Rope project settings
|
|
144
|
+
.ropeproject
|
|
145
|
+
|
|
146
|
+
# mkdocs documentation
|
|
147
|
+
/site
|
|
148
|
+
|
|
149
|
+
# mypy
|
|
150
|
+
.mypy_cache/
|
|
151
|
+
.dmypy.json
|
|
152
|
+
dmypy.json
|
|
153
|
+
|
|
154
|
+
# Pyre type checker
|
|
155
|
+
.pyre/
|
|
156
|
+
|
|
157
|
+
# pytype static type analyzer
|
|
158
|
+
.pytype/
|
|
159
|
+
|
|
160
|
+
# Cython debug symbols
|
|
161
|
+
cython_debug/
|
|
162
|
+
|
|
163
|
+
# PyCharm
|
|
164
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
165
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
166
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
167
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
168
|
+
#.idea/
|
|
169
|
+
|
|
170
|
+
# Abstra
|
|
171
|
+
# Abstra is an AI-powered process automation framework.
|
|
172
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
173
|
+
# Learn more at https://abstra.io/docs
|
|
174
|
+
.abstra/
|
|
175
|
+
|
|
176
|
+
# Visual Studio Code
|
|
177
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
178
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
179
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
180
|
+
# you could uncomment the following to ignore the enitre vscode folder
|
|
181
|
+
# .vscode/
|
|
182
|
+
|
|
183
|
+
# Ruff stuff:
|
|
184
|
+
.ruff_cache/
|
|
185
|
+
|
|
186
|
+
# PyPI configuration file
|
|
187
|
+
.pypirc
|
|
188
|
+
|
|
189
|
+
# Cursor
|
|
190
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
191
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
192
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
193
|
+
.cursorignore
|
|
194
|
+
.cursorindexingignore
|
|
195
|
+
|
|
196
|
+
# project
|
|
197
|
+
*.dcm
|
|
198
|
+
*.nii.gz
|
|
199
|
+
*.nii
|
|
200
|
+
tmp/
|
|
201
|
+
example/
|
pydicomrt-0.4.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 HigumaLu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
pydicomrt-0.4.0/PKG-INFO
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pydicomrt
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Author-email: Higumalu <higuma.lu@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Requires-Dist: numpy>=1.26.4
|
|
10
|
+
Requires-Dist: opencv-python>=4.10.0
|
|
11
|
+
Requires-Dist: pydicom>=2.0.0
|
|
12
|
+
Requires-Dist: scipy>=1.10.3
|
|
13
|
+
Requires-Dist: simpleitk>=2.5.0
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# pydicomRT
|
|
17
|
+
pydicomRT 是一個用於處理放射治療結構集(RTSTRUCT)DICOM文件的Python庫。它提供了創建、修改和驗證RTSTRUCT數據集的功能,以及在RTSTRUCT和體積掩碼之間進行轉換的工具。
|
|
18
|
+
|
|
19
|
+
## 功能特點
|
|
20
|
+
- 創建RTSTRUCT數據集
|
|
21
|
+
- 添加和管理感興趣區域(ROI)
|
|
22
|
+
- 將3D掩碼轉換為DICOM輪廓
|
|
23
|
+
- 將DICOM輪廓轉換為3D掩碼
|
|
24
|
+
- 驗證RTSTRUCT數據集的合規性
|
|
25
|
+
- 處理和排序DICOM圖像序列
|
|
26
|
+
- 坐標轉換工具
|
|
27
|
+
## 安裝
|
|
28
|
+
### 依賴項
|
|
29
|
+
- Python >= 3.8
|
|
30
|
+
- pydicom >= 2.0.0
|
|
31
|
+
- numpy == 1.26.4
|
|
32
|
+
- opencv-python >= 4.10.0
|
|
33
|
+
- scipy >= 1.10.3
|
|
34
|
+
### 使用pip安裝
|
|
35
|
+
```
|
|
36
|
+
pip install pydicomrt
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
從源碼安裝
|
|
40
|
+
```
|
|
41
|
+
git clone https://github.com/yourusername/pydicomRT.git
|
|
42
|
+
cd pydicomRT
|
|
43
|
+
pip install .
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 使用示例
|
|
48
|
+
### 創建RTSTRUCT數據集並添加ROI
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
|
|
52
|
+
import numpy as np
|
|
53
|
+
from pydicomrt.rs.make_contour_sequence import add_contour_sequence_from_mask3d
|
|
54
|
+
from pydicomrt.rs.add_new_roi import create_roi_into_rs_ds
|
|
55
|
+
from pydicomrt.rs.builder import create_rtstruct_dataset
|
|
56
|
+
from pydicomrt.utils.image_series_loader import load_sorted_image_series
|
|
57
|
+
|
|
58
|
+
# 加載圖像序列
|
|
59
|
+
ds_list = load_sorted_image_series("path/to/dicom/images")
|
|
60
|
+
|
|
61
|
+
# 創建空的RTSTRUCT數據集
|
|
62
|
+
rs_ds = create_rtstruct_dataset(ds_list)
|
|
63
|
+
|
|
64
|
+
# 創建ROI(感興趣區域)
|
|
65
|
+
rs_ds = create_roi_into_rs_ds(rs_ds, [0, 255, 0], 1, "CTV", "CTV")
|
|
66
|
+
|
|
67
|
+
# 創建3D掩碼
|
|
68
|
+
mask = np.zeros((len(ds_list), 512, 512))
|
|
69
|
+
mask[100:200, 100:400, 100:400] = 1
|
|
70
|
+
mask[120:180, 200:300, 200:300] = 0
|
|
71
|
+
|
|
72
|
+
# 將3D掩碼添加到RTSTRUCT數據集
|
|
73
|
+
rs_ds = add_contour_sequence_from_mask3d(rs_ds, ds_list, 1, mask)
|
|
74
|
+
|
|
75
|
+
# 保存RTSTRUCT數據集
|
|
76
|
+
rs_ds.save_as("path/to/output.dcm", write_like_original=False)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
### 從RTSTRUCT數據集中提取輪廓信息
|
|
81
|
+
```python
|
|
82
|
+
from pydicomrt.rs.parser import get_roi_number_to_name, get_contour_dict
|
|
83
|
+
|
|
84
|
+
# 獲取ROI映射
|
|
85
|
+
roi_map = get_roi_number_to_name(rs_ds)
|
|
86
|
+
print(roi_map) # 輸出: {1: 'CTV'}
|
|
87
|
+
|
|
88
|
+
# 獲取輪廓字典
|
|
89
|
+
ctr_dict = get_contour_dict(rs_ds)
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 驗證RTSTRUCT數據集
|
|
94
|
+
```python
|
|
95
|
+
from pydicomrt.rs.checker import check_rs_iod
|
|
96
|
+
|
|
97
|
+
# 檢查RTSTRUCT數據集是否符合IOD規範
|
|
98
|
+
result = check_rs_iod(rs_ds)
|
|
99
|
+
print(result) # 輸出: {'result': True, 'content': []}
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
## 模塊結構
|
|
105
|
+
- rs : 放射治療結構集相關功能
|
|
106
|
+
|
|
107
|
+
- builder : 創建RTSTRUCT數據集
|
|
108
|
+
- add_new_roi : 添加新的ROI
|
|
109
|
+
- make_contour_sequence : 創建輪廓序列
|
|
110
|
+
- parser : 解析RTSTRUCT數據集
|
|
111
|
+
- checker : 驗證RTSTRUCT數據集
|
|
112
|
+
- rs_to_volume : RTSTRUCT與體積數據轉換
|
|
113
|
+
- utils : 實用工具
|
|
114
|
+
|
|
115
|
+
- image_series_loader : 加載和排序DICOM圖像序列
|
|
116
|
+
- coordinate_transform : 坐標轉換工具
|
|
117
|
+
- validate_dcm_info : 驗證DICOM信息
|
|
118
|
+
## 貢獻
|
|
119
|
+
歡迎提交問題和拉取請求。
|
|
120
|
+
|
|
121
|
+
## 許可證
|
|
122
|
+
請參閱LICENSE文件。
|
|
123
|
+
|
|
124
|
+
## 作者
|
|
125
|
+
- Higumalu ( higuma.lu@gmail.com )
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# pydicomRT
|
|
2
|
+
pydicomRT 是一個用於處理放射治療結構集(RTSTRUCT)DICOM文件的Python庫。它提供了創建、修改和驗證RTSTRUCT數據集的功能,以及在RTSTRUCT和體積掩碼之間進行轉換的工具。
|
|
3
|
+
|
|
4
|
+
## 功能特點
|
|
5
|
+
- 創建RTSTRUCT數據集
|
|
6
|
+
- 添加和管理感興趣區域(ROI)
|
|
7
|
+
- 將3D掩碼轉換為DICOM輪廓
|
|
8
|
+
- 將DICOM輪廓轉換為3D掩碼
|
|
9
|
+
- 驗證RTSTRUCT數據集的合規性
|
|
10
|
+
- 處理和排序DICOM圖像序列
|
|
11
|
+
- 坐標轉換工具
|
|
12
|
+
## 安裝
|
|
13
|
+
### 依賴項
|
|
14
|
+
- Python >= 3.8
|
|
15
|
+
- pydicom >= 2.0.0
|
|
16
|
+
- numpy == 1.26.4
|
|
17
|
+
- opencv-python >= 4.10.0
|
|
18
|
+
- scipy >= 1.10.3
|
|
19
|
+
### 使用pip安裝
|
|
20
|
+
```
|
|
21
|
+
pip install pydicomrt
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
從源碼安裝
|
|
25
|
+
```
|
|
26
|
+
git clone https://github.com/yourusername/pydicomRT.git
|
|
27
|
+
cd pydicomRT
|
|
28
|
+
pip install .
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 使用示例
|
|
33
|
+
### 創建RTSTRUCT數據集並添加ROI
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
|
|
37
|
+
import numpy as np
|
|
38
|
+
from pydicomrt.rs.make_contour_sequence import add_contour_sequence_from_mask3d
|
|
39
|
+
from pydicomrt.rs.add_new_roi import create_roi_into_rs_ds
|
|
40
|
+
from pydicomrt.rs.builder import create_rtstruct_dataset
|
|
41
|
+
from pydicomrt.utils.image_series_loader import load_sorted_image_series
|
|
42
|
+
|
|
43
|
+
# 加載圖像序列
|
|
44
|
+
ds_list = load_sorted_image_series("path/to/dicom/images")
|
|
45
|
+
|
|
46
|
+
# 創建空的RTSTRUCT數據集
|
|
47
|
+
rs_ds = create_rtstruct_dataset(ds_list)
|
|
48
|
+
|
|
49
|
+
# 創建ROI(感興趣區域)
|
|
50
|
+
rs_ds = create_roi_into_rs_ds(rs_ds, [0, 255, 0], 1, "CTV", "CTV")
|
|
51
|
+
|
|
52
|
+
# 創建3D掩碼
|
|
53
|
+
mask = np.zeros((len(ds_list), 512, 512))
|
|
54
|
+
mask[100:200, 100:400, 100:400] = 1
|
|
55
|
+
mask[120:180, 200:300, 200:300] = 0
|
|
56
|
+
|
|
57
|
+
# 將3D掩碼添加到RTSTRUCT數據集
|
|
58
|
+
rs_ds = add_contour_sequence_from_mask3d(rs_ds, ds_list, 1, mask)
|
|
59
|
+
|
|
60
|
+
# 保存RTSTRUCT數據集
|
|
61
|
+
rs_ds.save_as("path/to/output.dcm", write_like_original=False)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
### 從RTSTRUCT數據集中提取輪廓信息
|
|
66
|
+
```python
|
|
67
|
+
from pydicomrt.rs.parser import get_roi_number_to_name, get_contour_dict
|
|
68
|
+
|
|
69
|
+
# 獲取ROI映射
|
|
70
|
+
roi_map = get_roi_number_to_name(rs_ds)
|
|
71
|
+
print(roi_map) # 輸出: {1: 'CTV'}
|
|
72
|
+
|
|
73
|
+
# 獲取輪廓字典
|
|
74
|
+
ctr_dict = get_contour_dict(rs_ds)
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 驗證RTSTRUCT數據集
|
|
79
|
+
```python
|
|
80
|
+
from pydicomrt.rs.checker import check_rs_iod
|
|
81
|
+
|
|
82
|
+
# 檢查RTSTRUCT數據集是否符合IOD規範
|
|
83
|
+
result = check_rs_iod(rs_ds)
|
|
84
|
+
print(result) # 輸出: {'result': True, 'content': []}
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
## 模塊結構
|
|
90
|
+
- rs : 放射治療結構集相關功能
|
|
91
|
+
|
|
92
|
+
- builder : 創建RTSTRUCT數據集
|
|
93
|
+
- add_new_roi : 添加新的ROI
|
|
94
|
+
- make_contour_sequence : 創建輪廓序列
|
|
95
|
+
- parser : 解析RTSTRUCT數據集
|
|
96
|
+
- checker : 驗證RTSTRUCT數據集
|
|
97
|
+
- rs_to_volume : RTSTRUCT與體積數據轉換
|
|
98
|
+
- utils : 實用工具
|
|
99
|
+
|
|
100
|
+
- image_series_loader : 加載和排序DICOM圖像序列
|
|
101
|
+
- coordinate_transform : 坐標轉換工具
|
|
102
|
+
- validate_dcm_info : 驗證DICOM信息
|
|
103
|
+
## 貢獻
|
|
104
|
+
歡迎提交問題和拉取請求。
|
|
105
|
+
|
|
106
|
+
## 許可證
|
|
107
|
+
請參閱LICENSE文件。
|
|
108
|
+
|
|
109
|
+
## 作者
|
|
110
|
+
- Higumalu ( higuma.lu@gmail.com )
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "pydicomrt"
|
|
3
|
+
version = "0.4.0"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Higumalu", email = "higuma.lu@gmail.com" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.8"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
dependencies = [
|
|
12
|
+
"pydicom>=2.0.0",
|
|
13
|
+
"numpy>=1.26.4",
|
|
14
|
+
"opencv-python>=4.10.0",
|
|
15
|
+
"scipy>=1.10.3",
|
|
16
|
+
"simpleitk>=2.5.0",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.scripts]
|
|
20
|
+
pydicomrt = "pydicomrt:main"
|
|
21
|
+
|
|
22
|
+
[build-system]
|
|
23
|
+
requires = ["hatchling"]
|
|
24
|
+
build-backend = "hatchling.build"
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from pydicom.uid import UID
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
CT_IMAGE_IOD = {
|
|
5
|
+
"PatientID": {},
|
|
6
|
+
"PatientName": {},
|
|
7
|
+
"PatientBirthDate": {},
|
|
8
|
+
"PatientSex": {},
|
|
9
|
+
"StudyInstanceUID": {},
|
|
10
|
+
"StudyID": {},
|
|
11
|
+
"StudyDate": {},
|
|
12
|
+
"StudyTime": {},
|
|
13
|
+
"AccessionNumber": {},
|
|
14
|
+
"SeriesInstanceUID": {"type": UID},
|
|
15
|
+
"SeriesNumber": {},
|
|
16
|
+
"Modality": {"value": "CT"},
|
|
17
|
+
"Manufacturer": {},
|
|
18
|
+
"FrameOfReferenceUID": {"type": UID},
|
|
19
|
+
"SOPClassUID": {"type": UID},
|
|
20
|
+
"SOPInstanceUID": {"type": UID},
|
|
21
|
+
"InstanceNumber": {},
|
|
22
|
+
|
|
23
|
+
"SliceThickness": {},
|
|
24
|
+
"ImagePositionPatient": {},
|
|
25
|
+
"ImageOrientationPatient": {},
|
|
26
|
+
"PixelSpacing": {},
|
|
27
|
+
|
|
28
|
+
"Rows": {},
|
|
29
|
+
"Columns": {},
|
|
30
|
+
|
|
31
|
+
"ImageType": {},
|
|
32
|
+
"BitsAllocated": {},
|
|
33
|
+
"BitsStored": {},
|
|
34
|
+
"HighBit": {},
|
|
35
|
+
"RescaleIntercept": {},
|
|
36
|
+
"RescaleSlope": {},
|
|
37
|
+
|
|
38
|
+
"PixelData": {},
|
|
39
|
+
|
|
40
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import numpy as np
|
|
3
|
+
import SimpleITK as sitk
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
from pydicom.tag import Tag
|
|
7
|
+
from pydicom.dataset import Dataset, FileDataset, FileMetaDataset
|
|
8
|
+
from pydicom.sequence import Sequence
|
|
9
|
+
from pydicom.uid import generate_uid
|
|
10
|
+
from pydicom.uid import ImplicitVRLittleEndian
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
DICOM_UID_PREFIX = os.getenv('DICOM_UID_PREFIX', "1.2.826.0.1.3680043.8.498.") # PYDICOM_ROOT_UID
|
|
14
|
+
|
|
15
|
+
def generate_base_dataset() -> FileDataset:
|
|
16
|
+
file_name = "bear_dose"
|
|
17
|
+
file_meta = get_file_meta()
|
|
18
|
+
ds = FileDataset(file_name, {}, file_meta=file_meta, preamble=b"\0" * 128)
|
|
19
|
+
add_required_elements_to_ds(ds)
|
|
20
|
+
add_sequence_lists_to_ds(ds)
|
|
21
|
+
return ds
|
|
22
|
+
|
|
23
|
+
def get_file_meta() -> FileMetaDataset:
|
|
24
|
+
file_meta = FileMetaDataset()
|
|
25
|
+
file_meta.FileMetaInformationGroupLength = 190
|
|
26
|
+
file_meta.FileMetaInformationVersion = b"\x00\x01"
|
|
27
|
+
file_meta.TransferSyntaxUID = ImplicitVRLittleEndian
|
|
28
|
+
file_meta.MediaStorageSOPClassUID = "1.2.840.10008.5.1.4.1.1.481.2"
|
|
29
|
+
file_meta.MediaStorageSOPInstanceUID = (
|
|
30
|
+
generate_uid(prefix=DICOM_UID_PREFIX)
|
|
31
|
+
)
|
|
32
|
+
file_meta.ImplementationClassUID = DICOM_UID_PREFIX + "1"
|
|
33
|
+
# TODO file_meta.ImplementationVersionName = ""
|
|
34
|
+
return file_meta
|
|
35
|
+
|
|
36
|
+
def add_required_elements_to_ds(ds: FileDataset):
|
|
37
|
+
dt = datetime.now()
|
|
38
|
+
# Append data elements required by the DICOM standarad
|
|
39
|
+
ds.SpecificCharacterSet = "ISO_IR 192"
|
|
40
|
+
ds.InstanceCreationDate = dt.strftime("%Y%m%d")
|
|
41
|
+
ds.InstanceCreationTime = dt.strftime("%H%M%S")
|
|
42
|
+
ds.Modality = "RTDOSE"
|
|
43
|
+
ds.Manufacturer = "higumalu"
|
|
44
|
+
ds.ManufacturerModelName = "modelv1"
|
|
45
|
+
ds.InstitutionName = "higumalu"
|
|
46
|
+
# Set the transfer syntax
|
|
47
|
+
ds.is_little_endian = True
|
|
48
|
+
ds.is_implicit_VR = True
|
|
49
|
+
# Set values already defined in the file meta
|
|
50
|
+
ds.SOPClassUID = ds.file_meta.MediaStorageSOPClassUID
|
|
51
|
+
ds.SOPInstanceUID = ds.file_meta.MediaStorageSOPInstanceUID
|
|
52
|
+
|
|
53
|
+
ds.ApprovalStatus = "UNAPPROVED"
|
|
54
|
+
|
|
55
|
+
def add_sequence_lists_to_ds(ds: FileDataset):
|
|
56
|
+
ds.ReferencedRTPlanSequence = Sequence()
|
|
57
|
+
|
|
58
|
+
# ---------------------------------------------------------------------------------------- #
|
|
59
|
+
|
|
60
|
+
def add_patient_information(ds: FileDataset, reference_ds: Dataset):
|
|
61
|
+
ds.PatientName = getattr(reference_ds, "PatientName", "Unknown")
|
|
62
|
+
ds.PatientID = getattr(reference_ds, "PatientID", "Unknown")
|
|
63
|
+
ds.PatientBirthDate = getattr(reference_ds, "PatientBirthDate", "")
|
|
64
|
+
ds.PatientSex = getattr(reference_ds, "PatientSex", "")
|
|
65
|
+
ds.PatientAge = getattr(reference_ds, "PatientAge", "")
|
|
66
|
+
ds.PatientSize = getattr(reference_ds, "PatientSize", "")
|
|
67
|
+
ds.PatientWeight = getattr(reference_ds, "PatientWeight", "")
|
|
68
|
+
return ds
|
|
69
|
+
|
|
70
|
+
def add_study_information(ds: FileDataset, reference_ds: Dataset):
|
|
71
|
+
dt = datetime.now()
|
|
72
|
+
ds.StudyInstanceUID = getattr(reference_ds, "StudyInstanceUID", generate_uid(prefix=DICOM_UID_PREFIX))
|
|
73
|
+
ds.StudyDate = getattr(reference_ds, "StudyDate", dt.strftime("%Y%m%d"))
|
|
74
|
+
ds.StudyTime = getattr(reference_ds, "StudyTime", dt.strftime("%H%M%S"))
|
|
75
|
+
ds.StudyID = getattr(reference_ds, "StudyID", "")
|
|
76
|
+
ds.AccessionNumber = getattr(reference_ds, "AccessionNumber", "")
|
|
77
|
+
ds.ReferringPhysicianName = getattr(reference_ds, "ReferringPhysicianName", "")
|
|
78
|
+
return ds
|
|
79
|
+
|
|
80
|
+
def add_series_information(ds: FileDataset, reference_ds: Dataset, series_number: int = 1):
|
|
81
|
+
dt = datetime.now()
|
|
82
|
+
ds.Modality = "RTDOSE"
|
|
83
|
+
ds.SeriesInstanceUID = generate_uid(prefix=DICOM_UID_PREFIX)
|
|
84
|
+
ds.SeriesDate = dt.strftime("%Y%m%d")
|
|
85
|
+
ds.SeriesTime = dt.strftime("%H%M%S")
|
|
86
|
+
ds.SeriesDescription = getattr(reference_ds, "SeriesDescription", "") + "_dose" + dt.strftime("%Y%m%d%H%M%S")
|
|
87
|
+
ds.SeriesNumber = getattr(reference_ds, "SeriesNumber", series_number)
|
|
88
|
+
ds.OperatorsName = getattr(reference_ds, "OperatorsName", "")
|
|
89
|
+
return ds
|
|
90
|
+
|
|
91
|
+
def add_frame_of_reference_information(ds: FileDataset, reference_ds: Dataset):
|
|
92
|
+
ds.FrameOfReferenceUID = getattr(reference_ds, "FrameOfReferenceUID", generate_uid(prefix=DICOM_UID_PREFIX))
|
|
93
|
+
ds.PositionReferenceIndicator = getattr(reference_ds, "PositionReferenceIndicator", "")
|
|
94
|
+
return ds
|
|
95
|
+
|
|
96
|
+
# ---------------------------------------------------------------------------------------- #
|
|
97
|
+
|
|
98
|
+
def cp_information_from_ds(
|
|
99
|
+
ds: FileDataset,
|
|
100
|
+
reference_ds: Dataset,
|
|
101
|
+
):
|
|
102
|
+
ds = add_patient_information(ds, reference_ds)
|
|
103
|
+
ds = add_study_information(ds, reference_ds)
|
|
104
|
+
ds = add_series_information(ds, reference_ds)
|
|
105
|
+
ds = add_frame_of_reference_information(ds, reference_ds)
|
|
106
|
+
return ds
|
|
107
|
+
|
|
108
|
+
# ---------------------------------------------------------------------------------------- #
|
|
109
|
+
|
|
110
|
+
def add_dose_grid_to_ds(
|
|
111
|
+
ds: FileDataset,
|
|
112
|
+
dose_sitk_image: sitk.Image,
|
|
113
|
+
):
|
|
114
|
+
scaling = 1e-7
|
|
115
|
+
array = sitk.GetArrayFromImage(dose_sitk_image)
|
|
116
|
+
size = list(dose_sitk_image.GetSize())
|
|
117
|
+
spacing = list(dose_sitk_image.GetSpacing())
|
|
118
|
+
direction = list(dose_sitk_image.GetDirection())
|
|
119
|
+
origin = list(dose_sitk_image.GetOrigin())
|
|
120
|
+
|
|
121
|
+
ds.SamplesPerPixel = 1
|
|
122
|
+
ds.PhotometricInterpretation = "MONOCHROME2"
|
|
123
|
+
ds.BitsAllocated = 32
|
|
124
|
+
ds.BitsStored = 32
|
|
125
|
+
ds.HighBit = 31
|
|
126
|
+
ds.PixelRepresentation = True
|
|
127
|
+
ds.DoseUnits = "GY"
|
|
128
|
+
ds.DoseType = "EFFECTIVE"
|
|
129
|
+
ds.DoseSummationType = "PLAN"
|
|
130
|
+
ds.NumberOfFrames = size[2]
|
|
131
|
+
ds.FrameIncrementPointer = Tag(0x3004, 0x000C)
|
|
132
|
+
|
|
133
|
+
ds.ImagePositionPatient = origin
|
|
134
|
+
ds.ImageOrientationPatient = direction
|
|
135
|
+
ds.PixelSpacing = spacing[0:2]
|
|
136
|
+
ds.SliceThickness = spacing[2]
|
|
137
|
+
ds.Columns = size[0]
|
|
138
|
+
ds.Rows = size[1]
|
|
139
|
+
ds.GridFrameOffsetVector = [ov * spacing[2] for ov in range(size[2])]
|
|
140
|
+
ds.DoseGridScaling = scaling
|
|
141
|
+
ds.PixelData = (array // scaling).astype(np.uint32).tobytes()
|
|
142
|
+
return ds
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
# -------------------------------- example --------------------------------------------------- #
|
|
146
|
+
|
|
147
|
+
if __name__ == "__main__":
|
|
148
|
+
import pydicom
|
|
149
|
+
import SimpleITK as sitk
|
|
150
|
+
dose_sitk_image = sitk.ReadImage("example/data/DF_001/RD_003/CT_001_dose.dcm")
|
|
151
|
+
ds = pydicom.dcmread("example/data/DF_001/RD_003/CT_001.dcm")
|
|
152
|
+
|
|
153
|
+
dose_ds = generate_base_dataset()
|
|
154
|
+
dose_ds = cp_information_from_ds(dose_ds, ds)
|
|
155
|
+
dose_ds = add_dose_grid_to_ds(dose_ds, dose_sitk_image)
|
|
156
|
+
dose_ds.save_as("example/data/DF_001/RD_003/dose.dcm")
|