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.
Files changed (72) hide show
  1. dbdicom/__init__.py +3 -25
  2. dbdicom/api.py +496 -0
  3. dbdicom/const.py +144 -0
  4. dbdicom/database.py +133 -0
  5. dbdicom/dataset.py +471 -0
  6. dbdicom/dbd.py +1290 -0
  7. dbdicom/external/__pycache__/__init__.cpython-311.pyc +0 -0
  8. dbdicom/external/dcm4che/__pycache__/__init__.cpython-311.pyc +0 -0
  9. dbdicom/external/dcm4che/bin/__pycache__/__init__.cpython-311.pyc +0 -0
  10. dbdicom/external/dcm4che/bin/emf2sf +57 -57
  11. dbdicom/register.py +402 -0
  12. dbdicom/{ds/types → sop_classes}/ct_image.py +2 -16
  13. dbdicom/{ds/types → sop_classes}/enhanced_mr_image.py +206 -160
  14. dbdicom/sop_classes/mr_image.py +338 -0
  15. dbdicom/sop_classes/parametric_map.py +381 -0
  16. dbdicom/sop_classes/secondary_capture.py +140 -0
  17. dbdicom/sop_classes/segmentation.py +311 -0
  18. dbdicom/{ds/types → sop_classes}/ultrasound_multiframe_image.py +1 -15
  19. dbdicom/{ds/types → sop_classes}/xray_angiographic_image.py +2 -17
  20. dbdicom/utils/arrays.py +142 -0
  21. dbdicom/utils/files.py +0 -20
  22. dbdicom/utils/image.py +43 -466
  23. dbdicom/utils/pydicom_dataset.py +386 -0
  24. dbdicom-0.3.16.dist-info/METADATA +26 -0
  25. dbdicom-0.3.16.dist-info/RECORD +54 -0
  26. {dbdicom-0.2.0.dist-info → dbdicom-0.3.16.dist-info}/WHEEL +1 -1
  27. dbdicom/create.py +0 -450
  28. dbdicom/ds/__init__.py +0 -10
  29. dbdicom/ds/create.py +0 -63
  30. dbdicom/ds/dataset.py +0 -841
  31. dbdicom/ds/dictionaries.py +0 -620
  32. dbdicom/ds/types/mr_image.py +0 -267
  33. dbdicom/ds/types/parametric_map.py +0 -226
  34. dbdicom/external/__pycache__/__init__.cpython-310.pyc +0 -0
  35. dbdicom/external/__pycache__/__init__.cpython-37.pyc +0 -0
  36. dbdicom/external/dcm4che/__pycache__/__init__.cpython-310.pyc +0 -0
  37. dbdicom/external/dcm4che/__pycache__/__init__.cpython-37.pyc +0 -0
  38. dbdicom/external/dcm4che/bin/__pycache__/__init__.cpython-310.pyc +0 -0
  39. dbdicom/external/dcm4che/bin/__pycache__/__init__.cpython-37.pyc +0 -0
  40. dbdicom/external/dcm4che/lib/linux-x86/libclib_jiio.so +0 -0
  41. dbdicom/external/dcm4che/lib/linux-x86-64/libclib_jiio.so +0 -0
  42. dbdicom/external/dcm4che/lib/linux-x86-64/libopencv_java.so +0 -0
  43. dbdicom/external/dcm4che/lib/solaris-sparc/libclib_jiio.so +0 -0
  44. dbdicom/external/dcm4che/lib/solaris-sparc/libclib_jiio_vis.so +0 -0
  45. dbdicom/external/dcm4che/lib/solaris-sparc/libclib_jiio_vis2.so +0 -0
  46. dbdicom/external/dcm4che/lib/solaris-sparcv9/libclib_jiio.so +0 -0
  47. dbdicom/external/dcm4che/lib/solaris-sparcv9/libclib_jiio_vis.so +0 -0
  48. dbdicom/external/dcm4che/lib/solaris-sparcv9/libclib_jiio_vis2.so +0 -0
  49. dbdicom/external/dcm4che/lib/solaris-x86/libclib_jiio.so +0 -0
  50. dbdicom/external/dcm4che/lib/solaris-x86-64/libclib_jiio.so +0 -0
  51. dbdicom/manager.py +0 -2077
  52. dbdicom/message.py +0 -119
  53. dbdicom/record.py +0 -1526
  54. dbdicom/types/database.py +0 -107
  55. dbdicom/types/instance.py +0 -184
  56. dbdicom/types/patient.py +0 -40
  57. dbdicom/types/series.py +0 -816
  58. dbdicom/types/study.py +0 -58
  59. dbdicom/utils/variables.py +0 -155
  60. dbdicom/utils/vreg.py +0 -2626
  61. dbdicom/wrappers/__init__.py +0 -7
  62. dbdicom/wrappers/dipy.py +0 -462
  63. dbdicom/wrappers/elastix.py +0 -855
  64. dbdicom/wrappers/numpy.py +0 -119
  65. dbdicom/wrappers/scipy.py +0 -1413
  66. dbdicom/wrappers/skimage.py +0 -1030
  67. dbdicom/wrappers/sklearn.py +0 -151
  68. dbdicom/wrappers/vreg.py +0 -273
  69. dbdicom-0.2.0.dist-info/METADATA +0 -276
  70. dbdicom-0.2.0.dist-info/RECORD +0 -81
  71. {dbdicom-0.2.0.dist-info → dbdicom-0.3.16.dist-info/licenses}/LICENSE +0 -0
  72. {dbdicom-0.2.0.dist-info → dbdicom-0.3.16.dist-info}/top_level.txt +0 -0
dbdicom/types/database.py DELETED
@@ -1,107 +0,0 @@
1
- # Importing annotations to handle or sign in import type hints
2
- from __future__ import annotations
3
-
4
- from dbdicom.record import Record
5
- from dbdicom.utils.files import gif2numpy
6
-
7
- class Database(Record):
8
-
9
- name = 'Database'
10
-
11
- def loc(self):
12
- return self.manager._dbloc()
13
- # df = self.manager.register
14
- # return df.removed==False
15
-
16
- def _set_key(self):
17
- #if not self.manager.register.empty:
18
- if not self.manager._empty():
19
- self._key = self.manager._keys(0)
20
- #self._key = self.manager.register.index[0]
21
- else:
22
- self._key = None
23
-
24
- def close(self):
25
- return self.manager.close()
26
-
27
- def set_path(self,path):
28
- # Used in example of clear
29
- self.manager.path=path
30
-
31
- def parent(self):
32
- return
33
-
34
- def children(self, **kwargs):
35
- return self.patients(**kwargs)
36
-
37
- def new_child(self, dataset=None, **kwargs):
38
- attr = {**kwargs, **self.attributes}
39
- return self.new_patient(**attr)
40
-
41
- def new_sibling(self, suffix=None, **kwargs):
42
- msg = 'You cannot create a sibling from a database \n'
43
- msg += 'You can start a new database with db.database()'
44
- raise RuntimeError(msg)
45
-
46
- def save(self, path=None):
47
- #self.manager.save('Database')
48
- self.manager.save()
49
- self.write(path)
50
-
51
- def restore(self, path=None):
52
- self.manager.restore()
53
- self.write(path)
54
-
55
- def open(self, path):
56
- self.manager.open(path)
57
-
58
- def close(self):
59
- return self.manager.close()
60
-
61
- def scan(self):
62
- self.manager.scan()
63
-
64
- def import_dicom(self, files):
65
- uids = self.manager.import_datasets(files)
66
- return uids is not None
67
-
68
- def import_nifti(self, files):
69
- self.manager.import_datasets_from_nifti(files)
70
-
71
- def import_gif(self, files):
72
- study = self.new_patient().new_study()
73
- for file in files:
74
- array = gif2numpy(file)
75
- series = study.new_series()
76
- series.set_array(array)
77
- return study
78
-
79
- def _copy_from(self, record):
80
- uids = self.manager.copy_to_database(record.uid, **self.attributes)
81
- if isinstance(uids, list):
82
- return [self.record('Patient', uid, **self.attributes) for uid in uids]
83
- else:
84
- return self.record('Patient', uids, **self.attributes)
85
-
86
- def zeros(*args, **kwargs): # OBSOLETE - remove
87
- return zeros(*args, **kwargs)
88
-
89
- # def export_as_dicom(self, path):
90
- # for child in self.children():
91
- # child.export_as_dicom(path)
92
-
93
- # def export_as_png(self, path):
94
- # for child in self.children():
95
- # child.export_as_png(path)
96
-
97
- # def export_as_csv(self, path):
98
- # for child in self.children():
99
- # child.export_as_csv(path)
100
-
101
-
102
- def zeros(database, shape, dtype='mri'): # OBSOLETE - remove
103
- study = database.new_study()
104
- return study.zeros(shape, dtype=dtype)
105
-
106
-
107
-
dbdicom/types/instance.py DELETED
@@ -1,184 +0,0 @@
1
- # Importing annotations to handle or sign in import type hints
2
- from __future__ import annotations
3
-
4
- import timeit
5
- import os
6
- import numpy as np
7
- import nibabel as nib
8
- import pandas as pd
9
- import matplotlib.pyplot as plt
10
-
11
-
12
- from dbdicom.record import Record
13
- from dbdicom.ds.create import new_dataset
14
- import dbdicom.utils.image as image
15
-
16
-
17
- class Instance(Record):
18
-
19
- name = 'SOPInstanceUID'
20
-
21
- def keys(self):
22
- return [self.key()]
23
-
24
- def parent(self):
25
- #uid = self.manager.register.at[self.key(), 'SeriesInstanceUID']
26
- uid = self.manager._at(self.key(), 'SeriesInstanceUID')
27
- return self.record('Series', uid, key=self.key())
28
-
29
- def children(self, **kwargs):
30
- return
31
-
32
- def new_child(self, **kwargs):
33
- return
34
-
35
- def _copy_from(self, record, **kwargs):
36
- return
37
-
38
- def copy_to_series(self, series):
39
- uid = self.manager.copy_instance_to_series(self.key(), series.keys(), series)
40
- return self.record('Instance', uid)
41
-
42
- def array(self):
43
- return self.get_pixel_array()
44
-
45
- def get_pixel_array(self):
46
- ds = self.get_dataset()
47
- return ds.get_pixel_array()
48
-
49
- def set_array(self, array):
50
- self.set_pixel_array(array)
51
-
52
- def set_pixel_array(self, array):
53
- ds = self.get_dataset()
54
- if ds is None:
55
- ds = new_dataset('MRImage')
56
- ds.set_pixel_array(array)
57
- in_memory = self.key() in self.manager.dataset
58
- self.set_dataset(ds)
59
- # This bit added ad-hoc because set_dataset() places the datset in memory
60
- # So if the instance is not in memory, it needs to be written and removed again
61
- if not in_memory:
62
- self.clear()
63
-
64
- def set_dataset(self, dataset):
65
- self._key = self.manager.set_instance_dataset(self.uid, dataset, self.key())
66
-
67
- def map_to(self, target):
68
- return map_to(self, target)
69
-
70
- def map_mask_to(self, target):
71
- return map_mask_to(self, target)
72
-
73
-
74
- def export_as_png(self, path):
75
- """Export image in png format."""
76
- pixelArray = np.transpose(self.array())
77
- centre, width = self.window
78
- minValue = centre - width/2
79
- maxValue = centre + width/2
80
- #cmap = plt.get_cmap(colourTable)
81
- cmap = self.colormap
82
- if cmap is None:
83
- cmap='gray'
84
- #plt.imshow(pixelArray, cmap=cmap)
85
- plt.imshow(pixelArray, cmap=cmap, vmin=minValue, vmax=maxValue)
86
- #plt.imshow(pixelArray, cmap=colourTable)
87
- #plt.clim(int(minValue), int(maxValue))
88
- cBar = plt.colorbar()
89
- cBar.minorticks_on()
90
- filename = self.label()
91
- filename = os.path.join(path, filename + '.png')
92
- plt.savefig(fname=filename)
93
- plt.close()
94
-
95
-
96
- def export_as_csv(self, path):
97
- """Export 2D pixel Array in csv format"""
98
- table = np.transpose(self.array())
99
- cols = ['Column' + str(x) for x in range(table.shape[0])]
100
- rows = ['Row' + str(y) for y in range(table.shape[1])]
101
- filepath = self.label()
102
- filepath = os.path.join(path, filepath + '.csv')
103
- df = pd.DataFrame(table, index=rows, columns=cols)
104
- df.to_csv(filepath)
105
-
106
-
107
- def export_as_nifti(self, path, affine=None):
108
- """Export series as a single Nifty file"""
109
- ds = self.get_dataset()
110
- if affine is None:
111
- affine = ds.get_values('affine_matrix')
112
- array = self.array()
113
- dicomHeader = nib.nifti1.Nifti1DicomExtension(2, ds)
114
- niftiObj = nib.Nifti1Image(array, image.affine_to_RAH(affine))
115
- niftiObj.header.extensions.append(dicomHeader)
116
- filepath = self.label()
117
- filepath = os.path.join(path, filepath + '.nii')
118
- nib.save(niftiObj, filepath)
119
-
120
-
121
- def BGRA_array(self):
122
- return image.BGRA(
123
- self.get_pixel_array(),
124
- self.lut,
125
- width = self.WindowWidth,
126
- center = self.WindowCenter,
127
- )
128
-
129
-
130
- def map_to(source, target):
131
- """Map non-zero image pixels onto a target image.
132
-
133
- Overwrite pixel values in the target"""
134
-
135
- dss = source.get_dataset()
136
- dst = target.get_dataset()
137
-
138
- # Create a coordinate array for all pixels in the source
139
- coords = np.empty((dss.Rows*dss.Columns, 3), dtype=np.uint16)
140
- for x in range(dss.Columns):
141
- for y in range(dss.Rows):
142
- coords[x*dss.Columns+y,:] = [x,y,0]
143
-
144
- # Apply coordinate transformation from source to target
145
- affineSource = dss.get_affine_matrix()
146
- affineTarget = dst.get_affine_matrix()
147
- sourceToTarget = np.linalg.inv(affineTarget).dot(affineSource)
148
- coords_target = nib.affines.apply_affine(sourceToTarget, coords)
149
-
150
- # Interpolate (nearest neighbour) and extract inslice coordinates
151
- coords_target = np.round(coords_target, 3).astype(int)
152
- xt = tuple([c[0] for c in coords_target if c[2] == 0])
153
- yt = tuple([c[1] for c in coords_target if c[2] == 0])
154
- xs = tuple([c[0] for c in coords])
155
- ys = tuple([c[1] for c in coords])
156
-
157
- ## COORDINATES DO NOT MATCH UP because of c[2] = 0 condition
158
- ## Needs a different indexing approach
159
-
160
- # Set values in the target image
161
- source_array = dss.get_pixel_array()
162
- target_array = np.zeros((dst.Columns, dst.Rows))
163
- target_array[(xt, yt)] = source_array[(xs, ys)]
164
- # for masking map values to {0, 1}
165
- result = source.new_sibling()
166
- result.set_pixel_array(target_array)
167
-
168
- return result
169
-
170
-
171
- def map_mask_to(record, target):
172
- """Map non-zero image pixels onto a target image.
173
- Overwrite pixel values in the target"""
174
- dsr = record.get_dataset()
175
- dst = target.get_dataset()
176
- array = dsr.map_mask_to(dst)
177
- result = target.copy_to(record.parent()) # inherit geometry header from target
178
- result.set_pixel_array(array)
179
- return result
180
-
181
-
182
-
183
-
184
-
dbdicom/types/patient.py DELETED
@@ -1,40 +0,0 @@
1
- # Importing annotations to handle or sign in import type hints
2
- from __future__ import annotations
3
-
4
- from dbdicom.record import Record
5
-
6
- class Patient(Record):
7
-
8
- name = 'PatientID'
9
-
10
- def new_study(self, **kwargs):
11
- attr = {**kwargs, **self.attributes}
12
- uid, key = self.manager.new_study(parent=self.uid, key=self.key(), **attr)
13
- return self.record('Study', uid, key, **attr)
14
-
15
- def parent(self):
16
- return self.record('Database')
17
-
18
- def children(self, **kwargs):
19
- return self.studies(**kwargs)
20
-
21
- def new_child(self, dataset=None, **kwargs):
22
- attr = {**kwargs, **self.attributes}
23
- return self.new_study(**attr)
24
-
25
- def new_sibling(self, suffix=None, **kwargs):
26
- if suffix is not None:
27
- desc = self.manager._at(self.key(), 'PatientName')
28
- kwargs['PatientName'] = desc + ' [' + suffix + ']'
29
- return self.parent().new_child(**kwargs)
30
-
31
- def _copy_from(self, record, **kwargs):
32
- attr = {**kwargs, **self.attributes}
33
- uids = self.manager.copy_to_patient(record.uid, self.key(), **attr)
34
- if isinstance(uids, list):
35
- return [self.record('Study', uid, **attr) for uid in uids]
36
- else:
37
- return self.record('Study', uids, **attr)
38
-
39
-
40
-