dbdicom 0.2.0__py3-none-any.whl → 0.3.16__py3-none-any.whl
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.
- dbdicom/__init__.py +3 -25
- dbdicom/api.py +496 -0
- dbdicom/const.py +144 -0
- dbdicom/database.py +133 -0
- dbdicom/dataset.py +471 -0
- dbdicom/dbd.py +1290 -0
- dbdicom/external/__pycache__/__init__.cpython-311.pyc +0 -0
- dbdicom/external/dcm4che/__pycache__/__init__.cpython-311.pyc +0 -0
- dbdicom/external/dcm4che/bin/__pycache__/__init__.cpython-311.pyc +0 -0
- dbdicom/external/dcm4che/bin/emf2sf +57 -57
- dbdicom/register.py +402 -0
- dbdicom/{ds/types → sop_classes}/ct_image.py +2 -16
- dbdicom/{ds/types → sop_classes}/enhanced_mr_image.py +206 -160
- dbdicom/sop_classes/mr_image.py +338 -0
- dbdicom/sop_classes/parametric_map.py +381 -0
- dbdicom/sop_classes/secondary_capture.py +140 -0
- dbdicom/sop_classes/segmentation.py +311 -0
- dbdicom/{ds/types → sop_classes}/ultrasound_multiframe_image.py +1 -15
- dbdicom/{ds/types → sop_classes}/xray_angiographic_image.py +2 -17
- dbdicom/utils/arrays.py +142 -0
- dbdicom/utils/files.py +0 -20
- dbdicom/utils/image.py +43 -466
- dbdicom/utils/pydicom_dataset.py +386 -0
- dbdicom-0.3.16.dist-info/METADATA +26 -0
- dbdicom-0.3.16.dist-info/RECORD +54 -0
- {dbdicom-0.2.0.dist-info → dbdicom-0.3.16.dist-info}/WHEEL +1 -1
- dbdicom/create.py +0 -450
- dbdicom/ds/__init__.py +0 -10
- dbdicom/ds/create.py +0 -63
- dbdicom/ds/dataset.py +0 -841
- dbdicom/ds/dictionaries.py +0 -620
- dbdicom/ds/types/mr_image.py +0 -267
- dbdicom/ds/types/parametric_map.py +0 -226
- dbdicom/external/__pycache__/__init__.cpython-310.pyc +0 -0
- dbdicom/external/__pycache__/__init__.cpython-37.pyc +0 -0
- dbdicom/external/dcm4che/__pycache__/__init__.cpython-310.pyc +0 -0
- dbdicom/external/dcm4che/__pycache__/__init__.cpython-37.pyc +0 -0
- dbdicom/external/dcm4che/bin/__pycache__/__init__.cpython-310.pyc +0 -0
- dbdicom/external/dcm4che/bin/__pycache__/__init__.cpython-37.pyc +0 -0
- dbdicom/external/dcm4che/lib/linux-x86/libclib_jiio.so +0 -0
- dbdicom/external/dcm4che/lib/linux-x86-64/libclib_jiio.so +0 -0
- dbdicom/external/dcm4che/lib/linux-x86-64/libopencv_java.so +0 -0
- dbdicom/external/dcm4che/lib/solaris-sparc/libclib_jiio.so +0 -0
- dbdicom/external/dcm4che/lib/solaris-sparc/libclib_jiio_vis.so +0 -0
- dbdicom/external/dcm4che/lib/solaris-sparc/libclib_jiio_vis2.so +0 -0
- dbdicom/external/dcm4che/lib/solaris-sparcv9/libclib_jiio.so +0 -0
- dbdicom/external/dcm4che/lib/solaris-sparcv9/libclib_jiio_vis.so +0 -0
- dbdicom/external/dcm4che/lib/solaris-sparcv9/libclib_jiio_vis2.so +0 -0
- dbdicom/external/dcm4che/lib/solaris-x86/libclib_jiio.so +0 -0
- dbdicom/external/dcm4che/lib/solaris-x86-64/libclib_jiio.so +0 -0
- dbdicom/manager.py +0 -2077
- dbdicom/message.py +0 -119
- dbdicom/record.py +0 -1526
- dbdicom/types/database.py +0 -107
- dbdicom/types/instance.py +0 -184
- dbdicom/types/patient.py +0 -40
- dbdicom/types/series.py +0 -816
- dbdicom/types/study.py +0 -58
- dbdicom/utils/variables.py +0 -155
- dbdicom/utils/vreg.py +0 -2626
- dbdicom/wrappers/__init__.py +0 -7
- dbdicom/wrappers/dipy.py +0 -462
- dbdicom/wrappers/elastix.py +0 -855
- dbdicom/wrappers/numpy.py +0 -119
- dbdicom/wrappers/scipy.py +0 -1413
- dbdicom/wrappers/skimage.py +0 -1030
- dbdicom/wrappers/sklearn.py +0 -151
- dbdicom/wrappers/vreg.py +0 -273
- dbdicom-0.2.0.dist-info/METADATA +0 -276
- dbdicom-0.2.0.dist-info/RECORD +0 -81
- {dbdicom-0.2.0.dist-info → dbdicom-0.3.16.dist-info/licenses}/LICENSE +0 -0
- {dbdicom-0.2.0.dist-info → dbdicom-0.3.16.dist-info}/top_level.txt +0 -0
dbdicom/create.py
DELETED
|
@@ -1,450 +0,0 @@
|
|
|
1
|
-
# Importing annotations to handle or sign in import type hints
|
|
2
|
-
from __future__ import annotations
|
|
3
|
-
|
|
4
|
-
import numpy as np
|
|
5
|
-
from dbdicom.manager import Manager
|
|
6
|
-
from dbdicom.types.database import Database
|
|
7
|
-
from dbdicom.types.patient import Patient
|
|
8
|
-
from dbdicom.types.study import Study
|
|
9
|
-
from dbdicom.types.series import Series
|
|
10
|
-
from dbdicom.types.instance import Instance
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def create(manager, uid='Database', type=None, key=None, **kwargs):
|
|
14
|
-
|
|
15
|
-
if uid is None:
|
|
16
|
-
return
|
|
17
|
-
if uid == 'Database':
|
|
18
|
-
return Database(create, manager, **kwargs)
|
|
19
|
-
|
|
20
|
-
# This case is included for convenience but should be avoided
|
|
21
|
-
# at all costs because the lookup of type at creation is very expensive.
|
|
22
|
-
# Considering removing and make type a requirement
|
|
23
|
-
if type is None:
|
|
24
|
-
type = manager.type(uid)
|
|
25
|
-
|
|
26
|
-
if type == 'Patient':
|
|
27
|
-
return Patient(create, manager, uid, key=key, **kwargs)
|
|
28
|
-
if type == 'Study':
|
|
29
|
-
return Study(create, manager, uid, key=key, **kwargs)
|
|
30
|
-
if type == 'Series':
|
|
31
|
-
return Series(create, manager, uid, key=key, **kwargs)
|
|
32
|
-
if type == 'Instance':
|
|
33
|
-
return Instance(create, manager, uid, key=key, **kwargs)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def database(path:str=None, **kwargs) -> Database:
|
|
37
|
-
"""create a new database in memory or open an existing one on disk.
|
|
38
|
-
|
|
39
|
-
Args:
|
|
40
|
-
path (str, optional): path to an existing database. In case none is provided, this will create a new empty database.
|
|
41
|
-
kwargs: any valid DICOM (tag, value) pair can be provided as keyword argument. These attributes will be assigned to the database and inherited by all DICOM objects later saved in the database.
|
|
42
|
-
|
|
43
|
-
Returns:
|
|
44
|
-
Database: Instance of the Database class.
|
|
45
|
-
|
|
46
|
-
Note:
|
|
47
|
-
If no path is provided, a new database is created in memory. Any changes or additions to that database will only exist in memory until the new database is saved with .save().
|
|
48
|
-
|
|
49
|
-
See Also:
|
|
50
|
-
:func:`~patient`
|
|
51
|
-
:func:`~study`
|
|
52
|
-
:func:`~series`
|
|
53
|
-
|
|
54
|
-
Example:
|
|
55
|
-
|
|
56
|
-
Create a new database in memory and print the contents:
|
|
57
|
-
|
|
58
|
-
>>> database = db.database()
|
|
59
|
-
>>> database.print()
|
|
60
|
-
---------- DATABASE --------------
|
|
61
|
-
Location: In memory
|
|
62
|
-
----------------------------------
|
|
63
|
-
|
|
64
|
-
Open an existing DICOM database and check the contents (in this example we are using an edited version of a RIDER dataset case):
|
|
65
|
-
|
|
66
|
-
>>> database = db.database('path\\to\\RIDER\\case')
|
|
67
|
-
>>> database.print()
|
|
68
|
-
---------- DATABASE --------------
|
|
69
|
-
Location: path\to\DICOM\database
|
|
70
|
-
Study BRAIN^RESEARCH [19040321]
|
|
71
|
-
Series 014 [sag 3d gre +c]
|
|
72
|
-
Nr of instances: 176
|
|
73
|
-
Study BRAIN^RESEARCH [19040321]
|
|
74
|
-
Series 017 [sag 3d flair +c]
|
|
75
|
-
Nr of instances: 210
|
|
76
|
-
Study BRAIN^RESEARCH [19040321]
|
|
77
|
-
Series 005 [ax tensor]
|
|
78
|
-
Nr of instances: 468
|
|
79
|
-
Series 006 [ax 5 flip]
|
|
80
|
-
Nr of instances: 16
|
|
81
|
-
Series 007 [ax 10 flip]
|
|
82
|
-
Nr of instances: 16
|
|
83
|
-
Series 008 [ax 15 flip]
|
|
84
|
-
Nr of instances: 16
|
|
85
|
-
Series 009 [ax 20 flip]
|
|
86
|
-
Nr of instances: 16
|
|
87
|
-
Series 010 [ax 25 flip]
|
|
88
|
-
Nr of instances: 16
|
|
89
|
-
Series 011 [ax 30 flip]
|
|
90
|
-
Nr of instances: 16
|
|
91
|
-
Series 012 [perfusion]
|
|
92
|
-
Nr of instances: 1040
|
|
93
|
-
Study BRAIN^RESEARCH [19040323]
|
|
94
|
-
Series 017 [sag 3d flair +c]
|
|
95
|
-
Nr of instances: 160
|
|
96
|
-
Series 018 [sag 3d flair +c_Copy]
|
|
97
|
-
Nr of instances: 160
|
|
98
|
-
Series 019 [MergedSeries]
|
|
99
|
-
Nr of instances: 320
|
|
100
|
-
Study BRAIN^RESEARCH [19040323]
|
|
101
|
-
Series 005 [ax tensor]
|
|
102
|
-
Nr of instances: 468
|
|
103
|
-
Series 006 [ax 5 flip]
|
|
104
|
-
Nr of instances: 16
|
|
105
|
-
Series 007 [ax 10 flip]
|
|
106
|
-
Nr of instances: 16
|
|
107
|
-
Series 008 [ax 15 flip]
|
|
108
|
-
Nr of instances: 16
|
|
109
|
-
Series 009 [ax 20 flip]
|
|
110
|
-
Nr of instances: 16
|
|
111
|
-
Series 010 [ax 25 flip]
|
|
112
|
-
Nr of instances: 16
|
|
113
|
-
Series 011 [ax 30 flip]
|
|
114
|
-
Nr of instances: 16
|
|
115
|
-
Series 012 [perfusion]
|
|
116
|
-
Nr of instances: 1040
|
|
117
|
-
Study BRAIN^RESEARCH [19040323]
|
|
118
|
-
Series 015 [sag 3d gre +c]
|
|
119
|
-
Nr of instances: 176
|
|
120
|
-
----------------------------------
|
|
121
|
-
"""
|
|
122
|
-
if path is None:
|
|
123
|
-
mgr = Manager()
|
|
124
|
-
else:
|
|
125
|
-
mgr = Manager(path, **kwargs)
|
|
126
|
-
mgr.open(path)
|
|
127
|
-
return Database(create, mgr, **kwargs)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
def patient(in_database:Database=None, **kwargs)->Patient:
|
|
131
|
-
"""Create an empty DICOM patient record.
|
|
132
|
-
|
|
133
|
-
Args:
|
|
134
|
-
in_database (Database, optional): If provided, the patient is created in this database. Defaults to None.
|
|
135
|
-
kwargs: Any valid DICOM (tag, value) pair to set properties of the new patient
|
|
136
|
-
|
|
137
|
-
Returns:
|
|
138
|
-
Study: DICOM patient with defaults for all attributes.
|
|
139
|
-
|
|
140
|
-
See Also:
|
|
141
|
-
:func:`~database`
|
|
142
|
-
:func:`~study`
|
|
143
|
-
:func:`~series`
|
|
144
|
-
|
|
145
|
-
Example:
|
|
146
|
-
Create an empty patient in memory:
|
|
147
|
-
|
|
148
|
-
>>> patient = db.patient()
|
|
149
|
-
>>> patient.print()
|
|
150
|
-
---------- PATIENT -------------
|
|
151
|
-
Patient New Patient
|
|
152
|
-
--------------------------------
|
|
153
|
-
|
|
154
|
-
Note since no patient object is provided, a default database is created automatically.
|
|
155
|
-
|
|
156
|
-
>>> patient.database().print()
|
|
157
|
-
---------- DATABASE --------------
|
|
158
|
-
Location: In memory
|
|
159
|
-
Patient New Patient
|
|
160
|
-
----------------------------------
|
|
161
|
-
"""
|
|
162
|
-
if in_database is None:
|
|
163
|
-
db = database()
|
|
164
|
-
else:
|
|
165
|
-
db = in_database
|
|
166
|
-
patient = db.new_patient(**kwargs)
|
|
167
|
-
if in_database is None:
|
|
168
|
-
db.save()
|
|
169
|
-
return patient
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
def study(in_patient:Patient=None, in_database:Database=None, **kwargs)->Study:
|
|
173
|
-
"""Create an empty DICOM study record.
|
|
174
|
-
|
|
175
|
-
Args:
|
|
176
|
-
in_patient (Patient, optional): If provided, the study is created in this Patient. Defaults to None.
|
|
177
|
-
in_database (Database, optional): If provided, the study is created in this database. Defaults to None.
|
|
178
|
-
kwargs: Any valid DICOM (tag, value) pair to set properties of the new study
|
|
179
|
-
|
|
180
|
-
Returns:
|
|
181
|
-
Study: DICOM study with defaults for all attributes.
|
|
182
|
-
|
|
183
|
-
See Also:
|
|
184
|
-
:func:`~database`
|
|
185
|
-
:func:`~patient`
|
|
186
|
-
:func:`~series`
|
|
187
|
-
|
|
188
|
-
Example:
|
|
189
|
-
Create an empty study in memory:
|
|
190
|
-
|
|
191
|
-
>>> study = db.study()
|
|
192
|
-
>>> study.print()
|
|
193
|
-
---------- STUDY ---------------
|
|
194
|
-
Study New Study [None]
|
|
195
|
-
--------------------------------
|
|
196
|
-
|
|
197
|
-
Note since no patient object is provided, a default hierarchy is created automatically:
|
|
198
|
-
|
|
199
|
-
>>> study.database().print()
|
|
200
|
-
---------- DATABASE --------------
|
|
201
|
-
Location: In memory
|
|
202
|
-
Patient New Patient
|
|
203
|
-
Study New Study [None]
|
|
204
|
-
----------------------------------
|
|
205
|
-
"""
|
|
206
|
-
|
|
207
|
-
if in_patient is not None:
|
|
208
|
-
study = in_patient.new_study(**kwargs)
|
|
209
|
-
else:
|
|
210
|
-
if in_database is None:
|
|
211
|
-
db = database()
|
|
212
|
-
else:
|
|
213
|
-
db = in_database
|
|
214
|
-
patient = db.new_patient()
|
|
215
|
-
study = patient.new_study(**kwargs)
|
|
216
|
-
if in_database is None:
|
|
217
|
-
db.save()
|
|
218
|
-
return study
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
def series(dtype='mri', in_study:Study=None, in_database:Database=None, **kwargs)->Series:
|
|
222
|
-
"""Create an empty DICOM series.
|
|
223
|
-
|
|
224
|
-
Args:
|
|
225
|
-
dtype (str, optional): The type of the series to create. Defaults to 'mri'.
|
|
226
|
-
in_study (Study, optional): If provided, the series is created in this study. Defaults to None.
|
|
227
|
-
in_database (Database, optional): If provided, the series is created in this database. Defaults to None.
|
|
228
|
-
kwargs: Any valid DICOM (tag, value) pair to set properties of the new patient
|
|
229
|
-
|
|
230
|
-
Returns:
|
|
231
|
-
Series: DICOM series with defaults for all attributes.
|
|
232
|
-
|
|
233
|
-
Raises:
|
|
234
|
-
ValueError: if a dtype is requested that is currently not yet implemented
|
|
235
|
-
|
|
236
|
-
See Also:
|
|
237
|
-
:func:`~database`
|
|
238
|
-
:func:`~patient`
|
|
239
|
-
:func:`~study`
|
|
240
|
-
:func:`~as_series`
|
|
241
|
-
:func:`~zeros`
|
|
242
|
-
|
|
243
|
-
Example:
|
|
244
|
-
Create an empty series in memory.
|
|
245
|
-
|
|
246
|
-
>>> series = db.series()
|
|
247
|
-
>>> series.print()
|
|
248
|
-
---------- SERIES --------------
|
|
249
|
-
Series 001 [New Series]
|
|
250
|
-
Nr of instances: 0
|
|
251
|
-
--------------------------------
|
|
252
|
-
|
|
253
|
-
Note since no patient and study records are provided, a default hierarchy is created automatically:
|
|
254
|
-
|
|
255
|
-
>>> series.database().print()
|
|
256
|
-
---------- DATABASE --------------
|
|
257
|
-
Location: In memory
|
|
258
|
-
Patient New Patient
|
|
259
|
-
Study New Study [None]
|
|
260
|
-
Series 001 [New Series]
|
|
261
|
-
Nr of instances: 0
|
|
262
|
-
----------------------------------
|
|
263
|
-
"""
|
|
264
|
-
if dtype not in ['mri', 'MRImage']:
|
|
265
|
-
message = 'dbdicom can only create images of type MRImage at this stage'
|
|
266
|
-
raise ValueError(message)
|
|
267
|
-
|
|
268
|
-
if in_study is not None:
|
|
269
|
-
series = in_study.new_series()
|
|
270
|
-
else:
|
|
271
|
-
if in_database is None:
|
|
272
|
-
_database = database()
|
|
273
|
-
else:
|
|
274
|
-
_database = in_database
|
|
275
|
-
patient = _database.new_patient()
|
|
276
|
-
study = patient.new_study()
|
|
277
|
-
series = study.new_series(**kwargs)
|
|
278
|
-
if in_database is None:
|
|
279
|
-
_database.save()
|
|
280
|
-
return series
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
def database_hollywood()->Database:
|
|
285
|
-
"""Create an empty toy database for demonstration purposes.
|
|
286
|
-
|
|
287
|
-
Returns:
|
|
288
|
-
Database: Database with two patients, two studies per patient and two empty series per study.
|
|
289
|
-
|
|
290
|
-
See Also:
|
|
291
|
-
:func:`~database`
|
|
292
|
-
|
|
293
|
-
Example:
|
|
294
|
-
>>> database = db.database_hollywood()
|
|
295
|
-
>>> database.print()
|
|
296
|
-
---------- DATABASE --------------
|
|
297
|
-
Location: In memory
|
|
298
|
-
Patient James Bond
|
|
299
|
-
Study MRI [19821201]
|
|
300
|
-
Series 001 [Localizer]
|
|
301
|
-
Nr of instances: 0
|
|
302
|
-
Series 002 [T2w]
|
|
303
|
-
Nr of instances: 0
|
|
304
|
-
Study Xray [19821205]
|
|
305
|
-
Series 001 [Chest]
|
|
306
|
-
Nr of instances: 0
|
|
307
|
-
Series 002 [Head]
|
|
308
|
-
Nr of instances: 0
|
|
309
|
-
Patient Scarface
|
|
310
|
-
Study MRI [19850105]
|
|
311
|
-
Series 001 [Localizer]
|
|
312
|
-
Nr of instances: 0
|
|
313
|
-
Series 002 [T2w]
|
|
314
|
-
Nr of instances: 0
|
|
315
|
-
Study Xray [19850106]
|
|
316
|
-
Series 001 [Chest]
|
|
317
|
-
Nr of instances: 0
|
|
318
|
-
Series 002 [Head]
|
|
319
|
-
Nr of instances: 0
|
|
320
|
-
---------------------------------
|
|
321
|
-
"""
|
|
322
|
-
hollywood = database()
|
|
323
|
-
|
|
324
|
-
james_bond = hollywood.new_patient(PatientName='James Bond')
|
|
325
|
-
james_bond_mri = james_bond.new_study(StudyDescription='MRI', StudyDate='19821201')
|
|
326
|
-
james_bond_mri_localizer = james_bond_mri.new_series(SeriesDescription='Localizer')
|
|
327
|
-
james_bond_mri_T2w = james_bond_mri.new_series(SeriesDescription='T2w')
|
|
328
|
-
james_bond_xray = james_bond.new_study(StudyDescription='Xray', StudyDate='19821205')
|
|
329
|
-
james_bond_xray_chest = james_bond_xray.new_series(SeriesDescription='Chest')
|
|
330
|
-
james_bond_xray_head = james_bond_xray.new_series(SeriesDescription='Head')
|
|
331
|
-
|
|
332
|
-
scarface = hollywood.new_patient(PatientName='Scarface')
|
|
333
|
-
scarface_mri = scarface.new_study(StudyDescription='MRI', StudyDate='19850105')
|
|
334
|
-
scarface_mri_localizer = scarface_mri.new_series(SeriesDescription='Localizer')
|
|
335
|
-
scarface_mri_T2w = scarface_mri.new_series(SeriesDescription='T2w')
|
|
336
|
-
scarface_xray = scarface.new_study(StudyDescription='Xray', StudyDate='19850106')
|
|
337
|
-
scarface_xray_chest = scarface_xray.new_series(SeriesDescription='Chest')
|
|
338
|
-
scarface_xray_head = scarface_xray.new_series(SeriesDescription='Head')
|
|
339
|
-
|
|
340
|
-
return hollywood
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
def as_series(array:np.ndarray, coords:dict=None, dtype='mri', in_study:Study=None, in_database:Database=None, **kwargs)->Series:
|
|
346
|
-
"""Create a DICOM series from a numpy array.
|
|
347
|
-
|
|
348
|
-
Args:
|
|
349
|
-
array (np.ndarray): numpy.ndarray with image data
|
|
350
|
-
coords (dict, optional): Dictionary with coordinate labels and values. For 3- or 4-dimensional arrays this is optional but for arrays with more than 4 dimensions this is required. The coordinate values can be one-dimensions for regularly gridded data, or n-dimensional for irregularly gridded data.
|
|
351
|
-
dtype (str, optional): The type of the series to create. Defaults to 'mri'.
|
|
352
|
-
in_study (Study, optional): If provided, the series is created in this study. Defaults to None.
|
|
353
|
-
in_database (Database, optional): If provided, the series is created in this database. Defaults to None.
|
|
354
|
-
kwargs: Any valid DICOM (tag, value) pair to set properties of the new patient
|
|
355
|
-
|
|
356
|
-
Returns:
|
|
357
|
-
Series: DICOM series containing the provided array as image data and defaults for all other parameters.
|
|
358
|
-
|
|
359
|
-
Raises:
|
|
360
|
-
ValueError: if a dtype is requested that is currently not yet implemented
|
|
361
|
-
ValueError: If the coords do not match up with the shape of the array.
|
|
362
|
-
|
|
363
|
-
See Also:
|
|
364
|
-
:func:`~series`
|
|
365
|
-
:func:`~zeros`
|
|
366
|
-
|
|
367
|
-
Example:
|
|
368
|
-
Create a series containing a 4-dimensional array. Since the default format is single-frame MRImage, this produces 6 separate files.
|
|
369
|
-
|
|
370
|
-
>>> array = np.zeros((128, 128, 3, 2))
|
|
371
|
-
>>> zeros = db.as_series(array)
|
|
372
|
-
>>> zeros.print()
|
|
373
|
-
---------- SERIES --------------
|
|
374
|
-
Series 001 [New Series]
|
|
375
|
-
Nr of instances: 6
|
|
376
|
-
MRImage 000001
|
|
377
|
-
MRImage 000002
|
|
378
|
-
MRImage 000003
|
|
379
|
-
MRImage 000004
|
|
380
|
-
MRImage 000005
|
|
381
|
-
MRImage 000006
|
|
382
|
-
--------------------------------
|
|
383
|
-
|
|
384
|
-
Since no coordinates are provided, these are assumed to be SliceLocation and AcquisitionTime with default values:
|
|
385
|
-
|
|
386
|
-
>>> print(zeros.SliceLocation)
|
|
387
|
-
[0.0, 1.0, 2.0]
|
|
388
|
-
>>> print(zeros.AcquisitionTime)
|
|
389
|
-
[0.0, 1.0]
|
|
390
|
-
|
|
391
|
-
To override these defaults, set coordinates explicitly using a dictionary. For instance, for an MRI series of images acquired at a single slice location for 3 flip angles and 2 repetition times, the coordinates of the series are:
|
|
392
|
-
|
|
393
|
-
>>> coords = {
|
|
394
|
-
... 'FlipAngle': [2, 15, 30],
|
|
395
|
-
... 'RepetitionTime': [2.5, 5.0],
|
|
396
|
-
... }
|
|
397
|
-
|
|
398
|
-
Now create another series, providing coordinates, and list the unique values of flip angle and repetition time:
|
|
399
|
-
>>> zeros = db.as_series(array, coords)
|
|
400
|
-
>>> print(zeros.FlipAngle)
|
|
401
|
-
[2.0, 15.0, 30.0]
|
|
402
|
-
>>> print(zeros.RepetitionTime)
|
|
403
|
-
[2.5, 5.0]
|
|
404
|
-
"""
|
|
405
|
-
sery = series(dtype=dtype, in_study=in_study, in_database=in_database, **kwargs)
|
|
406
|
-
sery.mute()
|
|
407
|
-
sery.set_array(array, coords=coords, pixels_first=True)
|
|
408
|
-
sery.unmute()
|
|
409
|
-
return sery
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
def zeros(shape:tuple, coords:dict=None, **kwargs) -> Series:
|
|
413
|
-
"""Create a DICOM series populated with zeros.
|
|
414
|
-
|
|
415
|
-
This is a convenience wrapper providing a numpy-like interface for :func:`~as_series`.
|
|
416
|
-
|
|
417
|
-
Args:
|
|
418
|
-
shape (tuple): shape of the array
|
|
419
|
-
kwargs: see :func:`~series`
|
|
420
|
-
|
|
421
|
-
Returns:
|
|
422
|
-
Series: DICOM series with zero values
|
|
423
|
-
|
|
424
|
-
See Also:
|
|
425
|
-
:func:`~series`
|
|
426
|
-
:func:`~as_series`
|
|
427
|
-
|
|
428
|
-
Example:
|
|
429
|
-
Create a series containing a 4-dimensional array of zeros:
|
|
430
|
-
|
|
431
|
-
>>> zeros = db.zeros((128, 128, 2, 3))
|
|
432
|
-
>>> zeros.print()
|
|
433
|
-
---------- SERIES --------------
|
|
434
|
-
Series 001 [New Series]
|
|
435
|
-
Nr of instances: 6
|
|
436
|
-
MRImage 000001
|
|
437
|
-
MRImage 000002
|
|
438
|
-
MRImage 000003
|
|
439
|
-
MRImage 000004
|
|
440
|
-
MRImage 000005
|
|
441
|
-
MRImage 000006
|
|
442
|
-
--------------------------------
|
|
443
|
-
|
|
444
|
-
This is effectively shorthand for:
|
|
445
|
-
|
|
446
|
-
>>> array = np.zeros((128, 128, 2, 3))
|
|
447
|
-
>>> zeros = db.as_series(array)
|
|
448
|
-
"""
|
|
449
|
-
array = np.zeros(shape, dtype=np.float32)
|
|
450
|
-
return as_series(array, coords=coords, **kwargs)
|
dbdicom/ds/__init__.py
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"""subpackage ds
|
|
2
|
-
|
|
3
|
-
Can ultimately be extracted as a separate package ds,
|
|
4
|
-
extending pydicom Dataset with extra functionality"""
|
|
5
|
-
|
|
6
|
-
from dbdicom.ds.types.mr_image import MRImage
|
|
7
|
-
from dbdicom.ds.types.enhanced_mr_image import EnhancedMRImage
|
|
8
|
-
from dbdicom.ds.types.ultrasound_multiframe_image import UltrasoundMultiFrameImage
|
|
9
|
-
from dbdicom.ds.types.xray_angiographic_image import XrayAngiographicImage
|
|
10
|
-
from dbdicom.ds.create import read_dataset, new_dataset
|
dbdicom/ds/create.py
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import pydicom
|
|
2
|
-
|
|
3
|
-
from pydicom.dataset import Dataset
|
|
4
|
-
from dbdicom.ds.dataset import DbDataset
|
|
5
|
-
from dbdicom.ds.types.xray_angiographic_image import XrayAngiographicImage
|
|
6
|
-
from dbdicom.ds.types.ct_image import CTImage
|
|
7
|
-
from dbdicom.ds.types.mr_image import MRImage
|
|
8
|
-
from dbdicom.ds.types.enhanced_mr_image import EnhancedMRImage
|
|
9
|
-
from dbdicom.ds.types.ultrasound_multiframe_image import UltrasoundMultiFrameImage
|
|
10
|
-
|
|
11
|
-
def SOPClass(SOPClassUID):
|
|
12
|
-
|
|
13
|
-
if SOPClassUID == '1.2.840.10008.5.1.4.1.1.4':
|
|
14
|
-
return 'MRImage'
|
|
15
|
-
elif SOPClassUID == '1.2.840.10008.5.1.4.1.1.4.1':
|
|
16
|
-
return 'EnhancedMRImage'
|
|
17
|
-
elif SOPClassUID == '1.2.840.10008.5.1.4.1.1.2':
|
|
18
|
-
return 'CTImage'
|
|
19
|
-
elif SOPClassUID == '1.2.840.10008.5.1.4.1.1.12.2':
|
|
20
|
-
return 'XrayAngiographicImage'
|
|
21
|
-
elif SOPClassUID == '1.2.840.10008.5.1.4.1.1.3.1':
|
|
22
|
-
return 'UltrasoundMultiFrameImage'
|
|
23
|
-
else:
|
|
24
|
-
return 'Instance'
|
|
25
|
-
|
|
26
|
-
def read_dataset(file, dialog=None):
|
|
27
|
-
|
|
28
|
-
try:
|
|
29
|
-
ds = pydicom.dcmread(file)
|
|
30
|
-
# ds = pydicom.dcmread(file, force=True) # more robust but hides corrupted data
|
|
31
|
-
except Exception as message:
|
|
32
|
-
if dialog is not None:
|
|
33
|
-
dialog.information(message)
|
|
34
|
-
raise FileNotFoundError(message)
|
|
35
|
-
|
|
36
|
-
type = SOPClass(ds.SOPClassUID)
|
|
37
|
-
if type == 'MRImage':
|
|
38
|
-
return MRImage(ds)
|
|
39
|
-
elif type == 'EnhancedMRImage':
|
|
40
|
-
return EnhancedMRImage(ds)
|
|
41
|
-
elif type == 'CTImage':
|
|
42
|
-
return CTImage(ds)
|
|
43
|
-
elif type == 'XrayAngiographicImage':
|
|
44
|
-
return XrayAngiographicImage(ds)
|
|
45
|
-
elif type == 'UltrasoundMultiFrameImage':
|
|
46
|
-
return UltrasoundMultiFrameImage(ds)
|
|
47
|
-
else:
|
|
48
|
-
return DbDataset(ds)
|
|
49
|
-
|
|
50
|
-
def new_dataset(type= 'MRImage'):
|
|
51
|
-
|
|
52
|
-
if type == 'MRImage':
|
|
53
|
-
return MRImage()
|
|
54
|
-
elif type == 'EnhancedMRImage':
|
|
55
|
-
return EnhancedMRImage()
|
|
56
|
-
elif type == 'CTImage':
|
|
57
|
-
return CTImage()
|
|
58
|
-
elif type == 'XrayAngiographicImage':
|
|
59
|
-
return XrayAngiographicImage()
|
|
60
|
-
elif type == 'UltrasoundMultiFrameImage':
|
|
61
|
-
return UltrasoundMultiFrameImage()
|
|
62
|
-
else:
|
|
63
|
-
return Dataset()
|