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
@@ -0,0 +1,338 @@
1
+ import os
2
+
3
+ import numpy as np
4
+ import vreg
5
+ import pydicom
6
+ from pydicom.dataset import FileMetaDataset, Dataset, FileDataset
7
+ from pydicom.sequence import Sequence
8
+ from pydicom.uid import (
9
+ ExplicitVRLittleEndian,
10
+ generate_uid,
11
+ MRImageStorage,
12
+ )
13
+
14
+ from datetime import datetime
15
+
16
+ import dbdicom.utils.image as image
17
+
18
+
19
+ def pixel_data(ds):
20
+ """Read the pixel array from an MR image"""
21
+
22
+ array = ds.pixel_array
23
+ array = array.astype(np.float32)
24
+ if [0x2005, 0x100E] in ds: # 'Philips Rescale Slope'
25
+ slope = ds[(0x2005, 0x100E)].value
26
+ intercept = ds[(0x2005, 0x100D)].value
27
+ if (intercept == 0) and (slope == 1):
28
+ array = array.astype(np.int16)
29
+ else:
30
+ array = array.astype(np.float32)
31
+ array -= intercept
32
+ array /= slope
33
+ else:
34
+ slope = float(getattr(ds, 'RescaleSlope', 1))
35
+ intercept = float(getattr(ds, 'RescaleIntercept', 0))
36
+ if (intercept == 0) and (slope == 1):
37
+ array = array.astype(np.int16)
38
+ else:
39
+ array = array.astype(np.float32)
40
+ array *= slope
41
+ array += intercept
42
+ return np.transpose(array)
43
+
44
+
45
+ def set_pixel_data(ds, array):
46
+
47
+ # Delete 'Philips Rescale Slope'
48
+ if (0x2005, 0x100E) in ds:
49
+ del ds[0x2005, 0x100E]
50
+ if (0x2005, 0x100D) in ds:
51
+ del ds[0x2005, 0x100D]
52
+
53
+ ds.BitsAllocated = 16
54
+ ds.BitsStored = 16
55
+ ds.HighBit = 15
56
+
57
+ if array.dtype==np.int16:
58
+ array = image.clip(array) # remove nan and infs
59
+ ds.PixelRepresentation = 1
60
+ ds.RescaleSlope = 1
61
+ ds.RescaleIntercept = 0
62
+ elif array.dtype==np.uint16:
63
+ array = image.clip(array) # remove nan and infs
64
+ ds.PixelRepresentation = 0
65
+ ds.RescaleSlope = 1
66
+ ds.RescaleIntercept = 0
67
+ else:
68
+ array = image.clip(array) # remove nan and infs
69
+ array, slope, intercept = image.scale_to_range(array, ds.BitsStored)
70
+ ds.PixelRepresentation = 0
71
+ ds.RescaleSlope = 1 / slope
72
+ ds.RescaleIntercept = - intercept / slope
73
+
74
+ array = np.transpose(array)
75
+ ds.Rows = array.shape[0]
76
+ ds.Columns = array.shape[1]
77
+ ds.PixelData = array.tobytes()
78
+
79
+
80
+
81
+ def default(): # from the RIDER dataset
82
+
83
+ # File meta info data elements
84
+ file_meta = FileMetaDataset()
85
+ file_meta.FileMetaInformationGroupLength = 190
86
+ file_meta.FileMetaInformationVersion = b'\x00\x01'
87
+ file_meta.MediaStorageSOPClassUID = '1.2.840.10008.5.1.4.1.1.4'
88
+ file_meta.MediaStorageSOPInstanceUID = '1.3.6.1.4.1.9328.50.16.175333593952805976694548436931998383940'
89
+ file_meta.TransferSyntaxUID = '1.2.840.10008.1.2'
90
+ file_meta.ImplementationClassUID = '1.2.40.0.13.1.1'
91
+ file_meta.ImplementationVersionName = 'dcm4che-1.4.27'
92
+
93
+ # Create the main dataset
94
+ ds = FileDataset(
95
+ filename_or_obj=None,
96
+ dataset=Dataset(),
97
+ file_meta=file_meta,
98
+ preamble=b"\0" * 128,
99
+ )
100
+
101
+ ds.is_implicit_VR = True
102
+ ds.is_little_endian = True
103
+
104
+ # Main data elements
105
+ ds.SpecificCharacterSet = 'ISO_IR 100'
106
+ ds.ImageType = ['ORIGINAL', 'PRIMARY', 'M', 'ND', 'NORM']
107
+ ds.SOPClassUID = '1.2.840.10008.5.1.4.1.1.4'
108
+ ds.SOPInstanceUID = pydicom.uid.generate_uid()
109
+ ds.StudyDate = '19040321'
110
+ ds.ContentDate = '19040321'
111
+ ds.StudyTime = ''
112
+ ds.AcquisitionTime = '075649.057496'
113
+ ds.ContentTime = ''
114
+ ds.AccessionNumber = '2819497684894126'
115
+ ds.Modality = 'MR'
116
+ ds.Manufacturer = 'SIEMENS'
117
+ ds.ReferringPhysicianName = ''
118
+ ds.StationName = ''
119
+ ds.StudyDescription = 'BRAIN^RESEARCH'
120
+ ds.SeriesDescription = 'sag 3d gre +c'
121
+ ds.ManufacturerModelName = ''
122
+ ds.ReferencedSOPClassUID = '1.3.6.1.4.1.9328.50.16.295504506656781074046411123909869020125'
123
+ ds.ReferencedSOPInstanceUID = '1.3.6.1.4.1.9328.50.16.303143938897288157958328401346374476407'
124
+ ds.PatientName = '281949'
125
+ ds.PatientID = pydicom.uid.generate_uid()
126
+ ds.PatientBirthDate = ''
127
+ ds.PatientSex = ''
128
+ ds.PatientIdentityRemoved = 'YES'
129
+ ds.DeidentificationMethod = 'CTP:NBIA Default w/ extra date removal:20100323:172722'
130
+ ds.ContrastBolusAgent = 'Magnevist'
131
+ ds.BodyPartExamined = 'FAKE'
132
+ ds.ScanningSequence = 'GR'
133
+ ds.SequenceVariant = 'SP'
134
+ ds.ScanOptions = ''
135
+ ds.MRAcquisitionType = '3D'
136
+ ds.SequenceName = '*fl3d1'
137
+ ds.AngioFlag = 'N'
138
+ ds.SliceThickness = '1.0'
139
+ ds.RepetitionTime = '8.6'
140
+ ds.EchoTime = '4.11'
141
+ ds.NumberOfAverages = '1.0'
142
+ ds.ImagingFrequency = '63.676701'
143
+ ds.ImagedNucleus = '1H'
144
+ ds.EchoNumbers = '0'
145
+ ds.MagneticFieldStrength = '1.4939999580383'
146
+ ds.NumberOfPhaseEncodingSteps = '224'
147
+ ds.EchoTrainLength = '1'
148
+ ds.PercentSampling = '100.0'
149
+ ds.PercentPhaseFieldOfView = '100.0'
150
+ ds.PixelBandwidth = '150.0'
151
+ ds.DeviceSerialNumber = '25445'
152
+ ds.SoftwareVersions = 'syngo MR 2004V 4VB11D'
153
+ ds.ProtocolName = 'sag 3d gre +c'
154
+ ds.ContrastBolusVolume = '20.0'
155
+ ds.DateOfLastCalibration = '19031229'
156
+ ds.TimeOfLastCalibration = '155156.000000'
157
+ ds.TransmitCoilName = 'Body'
158
+ ds.InPlanePhaseEncodingDirection = 'ROW'
159
+ ds.FlipAngle = '20.0'
160
+ ds.VariableFlipAngleFlag = 'N'
161
+ ds.SAR = '0.09494107961655'
162
+ ds.dBdt = '0.0'
163
+ ds.PatientPosition = 'HFS'
164
+ ds.StudyInstanceUID = pydicom.uid.generate_uid()
165
+ ds.SeriesInstanceUID = pydicom.uid.generate_uid()
166
+ ds.StudyID = ''
167
+ ds.SeriesNumber = '14'
168
+ ds.AcquisitionNumber = '1'
169
+ ds.InstanceNumber = '1'
170
+ ds.ImagePositionPatient = [0, 0, 0]
171
+ ds.ImageOrientationPatient = [1, 0, 0, 0, 1, 0]
172
+ ds.FrameOfReferenceUID = '1.3.6.1.4.1.9328.50.16.22344679587635360510174487884943834158'
173
+ ds.PositionReferenceIndicator = ''
174
+ ds.SliceLocation = '0.0'
175
+ ds.SamplesPerPixel = 1
176
+ ds.PhotometricInterpretation = 'MONOCHROME2'
177
+ ds.Rows = 64
178
+ ds.Columns = 64
179
+ ds.PixelSpacing = [1, 1]
180
+ ds.BitsAllocated = 16
181
+ ds.BitsStored = 16
182
+ ds.HighBit = 15
183
+ ds.PixelRepresentation = 0
184
+ ds.SmallestImagePixelValue = 0
185
+ ds.LargestImagePixelValue = 913
186
+ ds.WindowCenter = '136.0'
187
+ ds.WindowWidth = '380.0'
188
+ ds.RescaleIntercept = '0.0'
189
+ ds.RescaleSlope = '1.0'
190
+ ds.RescaleType = 'PIXELVALUE'
191
+ ds.WindowCenterWidthExplanation = 'Algo1'
192
+ ds.RequestedProcedureDescription = 'MRI BRAIN W/WO ENHANCEMENT'
193
+ ds.ScheduledProcedureStepDescription = 'MRI BRAIN W/WO ENHANCEMENT'
194
+ ds.ScheduledProcedureStepID = '5133240'
195
+ ds.PerformedProcedureStepStartDate = '19040611'
196
+ ds.PerformedProcedureStepDescription = 'MRI BRAIN W/WO ENHANCEMENT'
197
+ ds.RequestAttributesSequence = Sequence()
198
+ ds.RequestedProcedureID = '5133240'
199
+ ds.StorageMediaFileSetUID = '1.3.6.1.4.1.9328.50.16.162890465625511526068665093825399871205'
200
+ pixel_values = np.arange(ds.Rows*ds.Columns)*ds.LargestImagePixelValue/(ds.Rows*ds.Columns)
201
+ ds.PixelData = pixel_values.astype(np.uint16).tobytes()
202
+
203
+ return ds
204
+
205
+
206
+ def chat_gpt_3d(num_frames=10, rows=256, columns=256):
207
+
208
+ # File meta info
209
+ file_meta = FileMetaDataset()
210
+ file_meta.MediaStorageSOPClassUID = MRImageStorage
211
+ file_meta.MediaStorageSOPInstanceUID = generate_uid()
212
+ file_meta.ImplementationClassUID = generate_uid()
213
+ file_meta.TransferSyntaxUID = ExplicitVRLittleEndian
214
+
215
+ # Create FileDataset in memory
216
+ ds = FileDataset(
217
+ filename_or_obj=None,
218
+ dataset=Dataset(),
219
+ file_meta=file_meta,
220
+ preamble=b"\0" * 128,
221
+ )
222
+
223
+ # Transfer syntax
224
+ ds.is_little_endian = True
225
+ ds.is_implicit_VR = False
226
+
227
+ now = datetime.now()
228
+
229
+ # Required fields
230
+ ds.SOPClassUID = MRImageStorage
231
+ ds.SOPInstanceUID = file_meta.MediaStorageSOPInstanceUID
232
+ ds.PatientName = "Multi^Frame"
233
+ ds.PatientID = "999999"
234
+ ds.StudyInstanceUID = generate_uid()
235
+ ds.SeriesInstanceUID = generate_uid()
236
+ ds.StudyDate = now.strftime("%Y%m%d")
237
+ ds.StudyTime = now.strftime("%H%M%S")
238
+ ds.Modality = "MR"
239
+ ds.Manufacturer = "PythonPACS"
240
+ ds.StudyID = "1"
241
+ ds.SeriesNumber = "1"
242
+ ds.InstanceNumber = "1"
243
+
244
+ # Image geometry
245
+ ds.Rows = rows
246
+ ds.Columns = columns
247
+ ds.PixelSpacing = [1.0, 1.0]
248
+ ds.ImagePositionPatient = [0.0, 0.0, 0.0]
249
+ ds.ImageOrientationPatient = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0]
250
+ ds.FrameOfReferenceUID = generate_uid()
251
+ ds.PositionReferenceIndicator = ""
252
+
253
+ # Multi-frame specific
254
+ ds.NumberOfFrames = str(num_frames)
255
+ ds.InstanceNumber = "1"
256
+
257
+ # Pixel data requirements
258
+ ds.SamplesPerPixel = 1
259
+ ds.PhotometricInterpretation = "MONOCHROME2"
260
+ ds.BitsAllocated = 16
261
+ ds.BitsStored = 12
262
+ ds.HighBit = 11
263
+ ds.PixelRepresentation = 0 # unsigned
264
+
265
+ # Create dummy image data (e.g., black frames)
266
+ pixel_array = np.zeros((num_frames, rows, columns), dtype=np.uint16)
267
+ ds.PixelData = pixel_array.tobytes()
268
+
269
+ return ds
270
+
271
+
272
+
273
+ def chat_gpt_2d():
274
+ # Basic identifiers
275
+ file_meta = FileMetaDataset()
276
+ file_meta.MediaStorageSOPClassUID = MRImageStorage
277
+ file_meta.MediaStorageSOPInstanceUID = generate_uid()
278
+ file_meta.ImplementationClassUID = generate_uid()
279
+
280
+ # Create the main dataset
281
+ ds = FileDataset(
282
+ filename_or_obj=None,
283
+ dataset=Dataset(),
284
+ file_meta=file_meta,
285
+ preamble=b"\0" * 128,
286
+ )
287
+
288
+ # Set transfer syntax
289
+ ds.is_little_endian = True
290
+ ds.is_implicit_VR = False
291
+
292
+ # Required DICOM tags for MR Image Storage
293
+ now = datetime.now()
294
+ ds.SOPClassUID = MRImageStorage
295
+ ds.SOPInstanceUID = file_meta.MediaStorageSOPInstanceUID
296
+ ds.PatientName = "Anonymous^Patient"
297
+ ds.PatientID = "123456"
298
+ ds.StudyInstanceUID = generate_uid()
299
+ ds.SeriesInstanceUID = generate_uid()
300
+ ds.StudyDate = now.strftime("%Y%m%d")
301
+ ds.StudyTime = now.strftime("%H%M%S")
302
+ ds.Modality = "MR"
303
+ ds.Manufacturer = "PythonPACS"
304
+ ds.StudyID = "1"
305
+ ds.SeriesNumber = "1"
306
+ ds.InstanceNumber = "1"
307
+ ds.ImagePositionPatient = [0.0, 0.0, 0.0]
308
+ ds.ImageOrientationPatient = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0]
309
+ ds.FrameOfReferenceUID = generate_uid()
310
+ ds.PositionReferenceIndicator = ""
311
+ ds.Rows = 256
312
+ ds.Columns = 256
313
+ ds.PixelSpacing = [1.0, 1.0]
314
+ ds.BitsAllocated = 16
315
+ ds.BitsStored = 12
316
+ ds.HighBit = 11
317
+ ds.PixelRepresentation = 0 # unsigned
318
+ ds.SamplesPerPixel = 1
319
+ ds.PhotometricInterpretation = "MONOCHROME2"
320
+ ds.PixelData = (b"\0" * (ds.Rows * ds.Columns * 2)) # Dummy black image
321
+
322
+ return ds
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+ if __name__ == '__main__':
331
+ file = os.path.join(os.getcwd(), 'chat_gpt_mri.dcm')
332
+ chat_gpt_3d().save_as(file)
333
+ file = os.path.join(os.getcwd(), 'default_mri.dcm')
334
+ default().save_as(file)
335
+ print(file)
336
+
337
+
338
+