spydcmtk 1.2.2__tar.gz → 1.2.3__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.
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/PKG-INFO +16 -4
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/README.md +2 -1
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/setup.py +2 -2
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/spydcmtk/dcmTK.py +43 -16
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/spydcmtk/dcmTools.py +4 -0
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/spydcmtk/dcmVTKTK.py +6 -10
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/spydcmtk/spydcm.py +50 -6
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/spydcmtk.egg-info/PKG-INFO +16 -4
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/spydcmtk.egg-info/requires.txt +1 -1
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/LICENSE +0 -0
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/setup.cfg +0 -0
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/spydcmtk/ParaViewGlance.html +0 -0
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/spydcmtk/__init__.py +0 -0
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/spydcmtk/spydcm_config.py +0 -0
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/spydcmtk/spydcmtk.conf +0 -0
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/spydcmtk.egg-info/SOURCES.txt +0 -0
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/spydcmtk.egg-info/dependency_links.txt +0 -0
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/spydcmtk.egg-info/entry_points.txt +0 -0
- {spydcmtk-1.2.2 → spydcmtk-1.2.3}/spydcmtk.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: spydcmtk
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.3
|
|
4
4
|
Summary: Simple python dicom toolkit.
|
|
5
5
|
Home-page: https://github.com/fraser29/spydcmtk
|
|
6
6
|
Author: Fraser M. Callaghan
|
|
@@ -27,7 +27,18 @@ Requires-Dist: vtk>=9.3.0
|
|
|
27
27
|
Requires-Dist: python-gdcm
|
|
28
28
|
Requires-Dist: highdicom
|
|
29
29
|
Requires-Dist: matplotlib
|
|
30
|
-
Requires-Dist: ngawari
|
|
30
|
+
Requires-Dist: ngawari>=0.1.2
|
|
31
|
+
Dynamic: author
|
|
32
|
+
Dynamic: author-email
|
|
33
|
+
Dynamic: classifier
|
|
34
|
+
Dynamic: description
|
|
35
|
+
Dynamic: description-content-type
|
|
36
|
+
Dynamic: home-page
|
|
37
|
+
Dynamic: keywords
|
|
38
|
+
Dynamic: license
|
|
39
|
+
Dynamic: requires-dist
|
|
40
|
+
Dynamic: requires-python
|
|
41
|
+
Dynamic: summary
|
|
31
42
|
|
|
32
43
|
|
|
33
44
|
# *spydcmtk*
|
|
@@ -42,8 +53,9 @@ This package extends pydicom with a class structure based upon the Patient-Study
|
|
|
42
53
|
|
|
43
54
|
## Version
|
|
44
55
|
|
|
45
|
-
Current is VERSION 1.2.
|
|
56
|
+
Current is VERSION 1.2.3 Release.
|
|
46
57
|
|
|
58
|
+
- 1.2.3: Fix VTI to DICOM and add to script. Update tests. Fix jpg to DICOM. nii2dcm also handled but nii orientation is not adjusted from RAS to LPS.
|
|
47
59
|
- 1.2.2: Fix DICOM to VTK conversion bug. Add 4DFlow MRI to VTK conversion capability.
|
|
48
60
|
- 1.2.1: Add filter by tag name and value. Add build image overview option. Update to use pydicom >=3.0.1
|
|
49
61
|
- 1.2.0: Improved stability of VTK conversion. Bug fixes. Add basic interactive functionality. Add functionality to construct 4D-flow datasets. Add reliance on external library ngawari for basic IO operations, format conversion and vtk filter actions.
|
|
@@ -10,8 +10,9 @@ This package extends pydicom with a class structure based upon the Patient-Study
|
|
|
10
10
|
|
|
11
11
|
## Version
|
|
12
12
|
|
|
13
|
-
Current is VERSION 1.2.
|
|
13
|
+
Current is VERSION 1.2.3 Release.
|
|
14
14
|
|
|
15
|
+
- 1.2.3: Fix VTI to DICOM and add to script. Update tests. Fix jpg to DICOM. nii2dcm also handled but nii orientation is not adjusted from RAS to LPS.
|
|
15
16
|
- 1.2.2: Fix DICOM to VTK conversion bug. Add 4DFlow MRI to VTK conversion capability.
|
|
16
17
|
- 1.2.1: Add filter by tag name and value. Add build image overview option. Update to use pydicom >=3.0.1
|
|
17
18
|
- 1.2.0: Improved stability of VTK conversion. Bug fixes. Add basic interactive functionality. Add functionality to construct 4D-flow datasets. Add reliance on external library ngawari for basic IO operations, format conversion and vtk filter actions.
|
|
@@ -16,12 +16,12 @@ URL = 'https://github.com/fraser29/spydcmtk'
|
|
|
16
16
|
EMAIL = 'callaghan.fm@gmail.com'
|
|
17
17
|
AUTHOR = 'Fraser M. Callaghan'
|
|
18
18
|
REQUIRES_PYTHON = '>=3.9.0'
|
|
19
|
-
VERSION = '1.2.
|
|
19
|
+
VERSION = '1.2.3'
|
|
20
20
|
KEYWORDS="medical, imaging, mri, ct, dicom"
|
|
21
21
|
|
|
22
22
|
# What packages are required for this module to be executed?
|
|
23
23
|
REQUIRED = [
|
|
24
|
-
'pydicom>=3.0.1', 'numpy>=1.26.2', 'tqdm>=4.66.1', 'vtk>=9.3.0', 'python-gdcm', 'highdicom', 'matplotlib', 'ngawari'
|
|
24
|
+
'pydicom>=3.0.1', 'numpy>=1.26.2', 'tqdm>=4.66.1', 'vtk>=9.3.0', 'python-gdcm', 'highdicom', 'matplotlib', 'ngawari>=0.1.2'
|
|
25
25
|
]
|
|
26
26
|
|
|
27
27
|
|
|
@@ -47,6 +47,7 @@ class DicomSeries(list):
|
|
|
47
47
|
self.HIDE_PROGRESSBAR = HIDE_PROGRESSBAR
|
|
48
48
|
self.FORCE_READ = FORCE_READ
|
|
49
49
|
self.SAFE_NAME_MODE = SAFE_NAME_MODE
|
|
50
|
+
self.NOT_FULLY_LOADED = False
|
|
50
51
|
list.__init__(self, dsList)
|
|
51
52
|
|
|
52
53
|
def __str__(self):
|
|
@@ -95,7 +96,9 @@ class DicomSeries(list):
|
|
|
95
96
|
DicomSeries: An instance of DicomSeries class.
|
|
96
97
|
"""
|
|
97
98
|
dicomDict = dcmTools.organiseDicomHeirarchyByUIDs(dirName, HIDE_PROGRESSBAR=HIDE_PROGRESSBAR, FORCE_READ=FORCE_READ, ONE_FILE_PER_DIR=ONE_FILE_PER_DIR, OVERVIEW=OVERVIEW)
|
|
98
|
-
|
|
99
|
+
obj = DicomSeries._setFromDictionary(dicomDict, OVERVIEW=OVERVIEW, HIDE_PROGRESSBAR=HIDE_PROGRESSBAR, FORCE_READ=FORCE_READ)
|
|
100
|
+
obj.NOT_FULLY_LOADED = ONE_FILE_PER_DIR
|
|
101
|
+
return obj
|
|
99
102
|
|
|
100
103
|
@classmethod
|
|
101
104
|
def setFromFileList(cls, fileList, OVERVIEW=False, HIDE_PROGRESSBAR=False, FORCE_READ=False):
|
|
@@ -194,15 +197,16 @@ class DicomSeries(list):
|
|
|
194
197
|
dd.pop('7FE00010') # Remove actual PixelData
|
|
195
198
|
dOut[ds.InstanceNumber] = dd
|
|
196
199
|
dcmTools.writeDictionaryToJSON(jsonFileOut, dOut)
|
|
200
|
+
return jsonFileOut
|
|
197
201
|
|
|
198
|
-
def _isSeriesFullyLoaded(self):
|
|
199
|
-
return len(self) == dcmTools.countFilesInDir(self.getRootDir())
|
|
200
202
|
|
|
201
203
|
def _loadToMemory(self):
|
|
202
|
-
if
|
|
204
|
+
if self.NOT_FULLY_LOADED:
|
|
203
205
|
rootDir = self.getRootDir()
|
|
204
206
|
self.clear()
|
|
205
207
|
self.extend([dicom.dcmread(os.path.join(rootDir, i), force=self.FORCE_READ) for i in tqdm(os.listdir(rootDir), disable=self.HIDE_PROGRESSBAR)])
|
|
208
|
+
self.NOT_FULLY_LOADED = False
|
|
209
|
+
|
|
206
210
|
|
|
207
211
|
def getSeriesOverview(self, tagList=SpydcmTK_config.SERIES_OVERVIEW_TAG_LIST):
|
|
208
212
|
names, vals = self.getTagListAndNames(tagList)
|
|
@@ -267,9 +271,26 @@ class DicomSeries(list):
|
|
|
267
271
|
if k2 in timesIDs_ToRemove:
|
|
268
272
|
dsToRm.append(self[c0])
|
|
269
273
|
c0 += 1
|
|
270
|
-
|
|
274
|
+
self._rm_via_DS_List(dsToRm)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def removeInstances(self, instanceIDs_to_remove):
|
|
278
|
+
dsToRm = []
|
|
279
|
+
for k1 in range(len(self)):
|
|
280
|
+
if self.getTag("InstanceNumber", k1, convertToType=int) in instanceIDs_to_remove:
|
|
281
|
+
dsToRm.append(self[k1])
|
|
282
|
+
self._rm_via_DS_List(dsToRm)
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def _rm_via_DS_List(self, dsList):
|
|
286
|
+
for iDS in dsList:
|
|
271
287
|
self.remove(iDS)
|
|
272
288
|
|
|
289
|
+
|
|
290
|
+
def deleteTag(self, tag, dsID):
|
|
291
|
+
tagObj = self.getTagObj(tag, dsID)
|
|
292
|
+
del tagObj
|
|
293
|
+
|
|
273
294
|
# ----------------------------------------------------------------------------------------------------
|
|
274
295
|
def resetUIDs(self, studyUID):
|
|
275
296
|
"""Reset SOPInstanceUID, SeriesInstanceUID and StudyInstaceUID (must pass last)
|
|
@@ -329,6 +350,7 @@ class DicomSeries(list):
|
|
|
329
350
|
""" Recurse down directory tree - grab dicoms and move to new
|
|
330
351
|
hierarchical folder structure rooted at 'studyOutputDir'
|
|
331
352
|
"""
|
|
353
|
+
self._loadToMemory()
|
|
332
354
|
if SAFE_NAMING_CHECK:
|
|
333
355
|
self.checkIfShouldUse_SAFE_NAMING()
|
|
334
356
|
ADD_TRANSFERSYNTAX = False
|
|
@@ -475,6 +497,7 @@ class DicomSeries(list):
|
|
|
475
497
|
numpy array - shape [nRow, nCol, nSlice, nTime],
|
|
476
498
|
dictionary - keys: Spacing, Origin, ImageOrientationPatient, PatientPosition, Dimensions, Times
|
|
477
499
|
"""
|
|
500
|
+
self._loadToMemory()
|
|
478
501
|
I,J,K = int(self.getTag('Rows')), int(self.getTag('Columns')), int(self.getNumberOfSlicesPerVolume())
|
|
479
502
|
self.sortBySlice_InstanceNumber() # This takes care of order - slices grouped, then time for each slice
|
|
480
503
|
N = self.getNumberOfTimeSteps()
|
|
@@ -694,16 +717,15 @@ class DicomStudy(list):
|
|
|
694
717
|
dStudyList = ListOfDicomStudies.setFromDcmDict(dicomDict, OVERVIEW=OVERVIEW, HIDE_PROGRESSBAR=HIDE_PROGRESSBAR, FORCE_READ=FORCE_READ)
|
|
695
718
|
if len(dStudyList) > 1:
|
|
696
719
|
raise ValueError('More than one study found - use ListOfDicomStudies class')
|
|
697
|
-
# dicomDirs = getAllDirsUnderRootWithDicoms(dirName) # this was meant to work as a quick shortcut - but potential problems if used incorrectly
|
|
698
|
-
# dSeriesList = []
|
|
699
|
-
# for iDir in dicomDirs:
|
|
700
|
-
# dSeriesList.append(DicomSeries.setFromDirectory(iDir, OVERVIEW=OVERVIEW, HIDE_PROGRESSBAR=HIDE_PROGRESSBAR))
|
|
701
720
|
return cls(dStudyList[0], OVERVIEW=OVERVIEW, HIDE_PROGRESSBAR=HIDE_PROGRESSBAR)
|
|
702
721
|
|
|
703
722
|
@classmethod
|
|
704
723
|
def setFromDirectory(cls, dirName, OVERVIEW=False, HIDE_PROGRESSBAR=False, FORCE_READ=False, ONE_FILE_PER_DIR=False):
|
|
705
724
|
dicomDict = dcmTools.organiseDicomHeirarchyByUIDs(dirName, HIDE_PROGRESSBAR=HIDE_PROGRESSBAR, FORCE_READ=FORCE_READ, ONE_FILE_PER_DIR=ONE_FILE_PER_DIR, OVERVIEW=OVERVIEW)
|
|
706
|
-
|
|
725
|
+
obj = DicomStudy.setFromDictionary(dicomDict, OVERVIEW=OVERVIEW, HIDE_PROGRESSBAR=HIDE_PROGRESSBAR, FORCE_READ=FORCE_READ)
|
|
726
|
+
for iSeries in obj:
|
|
727
|
+
iSeries.NOT_FULLY_LOADED = ONE_FILE_PER_DIR
|
|
728
|
+
return obj
|
|
707
729
|
|
|
708
730
|
|
|
709
731
|
def __str__(self):
|
|
@@ -978,7 +1000,11 @@ class ListOfDicomStudies(list):
|
|
|
978
1000
|
ONE_FILE_PER_DIR=ONE_FILE_PER_DIR,
|
|
979
1001
|
OVERVIEW=OVERVIEW,
|
|
980
1002
|
extn_filter=extn_filter)
|
|
981
|
-
|
|
1003
|
+
obj = ListOfDicomStudies.setFromDcmDict(dicomDict, OVERVIEW, HIDE_PROGRESSBAR, FORCE_READ=FORCE_READ)
|
|
1004
|
+
for iStudy in obj:
|
|
1005
|
+
for iSeries in iStudy:
|
|
1006
|
+
iSeries.NOT_FULLY_LOADED = ONE_FILE_PER_DIR
|
|
1007
|
+
return obj
|
|
982
1008
|
|
|
983
1009
|
@classmethod
|
|
984
1010
|
def setFromDcmDict(cls, dicomDict, OVERVIEW=False, HIDE_PROGRESSBAR=False, FORCE_READ=False):
|
|
@@ -1045,7 +1071,8 @@ class ListOfDicomStudies(list):
|
|
|
1045
1071
|
ioutputRootDir = outputRootDir
|
|
1046
1072
|
|
|
1047
1073
|
ooD = iStudy.writeToOrganisedFileStructure(ioutputRootDir)
|
|
1048
|
-
|
|
1074
|
+
if ooD is not None:
|
|
1075
|
+
outDirs.append(ooD)
|
|
1049
1076
|
return outDirs
|
|
1050
1077
|
|
|
1051
1078
|
def writeToZipArchive(self, outputRootDir, CLEAN_UP=True):
|
|
@@ -1206,6 +1233,10 @@ def studySummary(pathToDicoms):
|
|
|
1206
1233
|
def writeVTIToDicoms(vtiFile, dcmTemplateFile_or_ds, outputDir, arrayName=None, tagUpdateDict=None, patientMeta=None):
|
|
1207
1234
|
if type(vtiFile) == str:
|
|
1208
1235
|
vti = dcmVTKTK.fIO.readVTKFile(vtiFile)
|
|
1236
|
+
if vtiFile.endswith(".nii") or vtiFile.endswith(".nii.gz"):
|
|
1237
|
+
# TODO - need to also adjust patientMeta if this is nifti
|
|
1238
|
+
vti.SetOrigin([i*0.001 for i in vti.GetOrigin()])
|
|
1239
|
+
vti.SetSpacing([i*0.001 for i in vti.GetSpacing()])
|
|
1209
1240
|
else:
|
|
1210
1241
|
vti = vtiFile
|
|
1211
1242
|
if arrayName is None:
|
|
@@ -1213,8 +1244,6 @@ def writeVTIToDicoms(vtiFile, dcmTemplateFile_or_ds, outputDir, arrayName=None,
|
|
|
1213
1244
|
else:
|
|
1214
1245
|
A = dcmVTKTK.vtkfilters.getArrayAsNumpy(vti, arrayName)
|
|
1215
1246
|
A = np.reshape(A, vti.GetDimensions(), 'F')
|
|
1216
|
-
A = np.rot90(A)
|
|
1217
|
-
A = np.flipud(A)
|
|
1218
1247
|
if patientMeta is None:
|
|
1219
1248
|
patientMeta = dcmVTKTK.PatientMeta()
|
|
1220
1249
|
patientMeta.initFromVTI(vti)
|
|
@@ -1298,7 +1327,6 @@ def writeImageStackToDicom(images_sortedList, patientMeta, dcmTemplateFile_or_ds
|
|
|
1298
1327
|
outputDir, tagUpdateDict=None):
|
|
1299
1328
|
|
|
1300
1329
|
combinedImage = dcmVTKTK.readImageStackToVTI(images_sortedList, patientMeta, CONVERT_TO_GREYSCALE=True)
|
|
1301
|
-
combinedImage = dcmVTKTK.vtkfilterFlipImageData(combinedImage, 1)
|
|
1302
1330
|
writeVTIToDicoms(combinedImage,
|
|
1303
1331
|
dcmTemplateFile_or_ds=dcmTemplateFile_or_ds,
|
|
1304
1332
|
outputDir=outputDir,
|
|
@@ -1310,7 +1338,6 @@ def writeImageStackToDicom(images_sortedList, patientMeta, dcmTemplateFile_or_ds
|
|
|
1310
1338
|
def getResolution(dataVts):
|
|
1311
1339
|
o,p1,p2,p3 = [0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0]
|
|
1312
1340
|
i0,i1,j0,j1,k0,k1 = dataVts.GetExtent()
|
|
1313
|
-
print(i0,i1,j0,j1,k0,k1)
|
|
1314
1341
|
dataVts.GetPoint(i0,j0,k0, o)
|
|
1315
1342
|
dataVts.GetPoint(i0+1,j0,k0, p1)
|
|
1316
1343
|
dataVts.GetPoint(i0,j0+1,k0, p2)
|
|
@@ -151,6 +151,10 @@ def dbDateToDateTime(dbDate):
|
|
|
151
151
|
return datetime.datetime.strptime(dbDate, '%Y%m%dT%H%M%S')
|
|
152
152
|
|
|
153
153
|
|
|
154
|
+
def dateTime_to_dbString(dateTime):
|
|
155
|
+
return dateTime.strftime('%Y%m%d')
|
|
156
|
+
|
|
157
|
+
|
|
154
158
|
def distPts(pt1, pt2):
|
|
155
159
|
try:
|
|
156
160
|
dist = np.sqrt((pt1[0] - pt2[0]) ** 2 + (pt1[1] - pt2[1]) ** 2 + (pt1[2] - pt2[2]) ** 2)
|
|
@@ -482,10 +482,13 @@ def readImageStackToVTI(imageFileNames: List[str], patientMeta: PatientMeta=None
|
|
|
482
482
|
patientMeta = PatientMeta()
|
|
483
483
|
combinedImage.SetOrigin(patientMeta.Origin)
|
|
484
484
|
combinedImage.SetSpacing(patientMeta.Spacing)
|
|
485
|
-
a = vtkfilters.getScalarsAsNumpy(combinedImage)
|
|
485
|
+
a = vtkfilters.getScalarsAsNumpy(combinedImage, RETURN_3D=True)
|
|
486
486
|
if CONVERT_TO_GREYSCALE:
|
|
487
|
-
a = np.mean(a, 1)
|
|
488
|
-
|
|
487
|
+
a = np.mean(a, -1)
|
|
488
|
+
# Manipulation required to bring jpgs to same orientation as vti
|
|
489
|
+
a = np.rot90(a, k=-1)
|
|
490
|
+
a = np.flipud(a)
|
|
491
|
+
vtkfilters.setArrayFromNumpy(combinedImage, a, arrayName, SET_SCALAR=True, IS_3D=True)
|
|
489
492
|
vtkfilters.delArraysExcept(combinedImage, [arrayName])
|
|
490
493
|
return combinedImage
|
|
491
494
|
|
|
@@ -630,13 +633,6 @@ class NoVtkError(Exception):
|
|
|
630
633
|
# =========================================================================
|
|
631
634
|
## HELPFUL FILTERS
|
|
632
635
|
# =========================================================================
|
|
633
|
-
def vtkfilterFlipImageData(vtiObj, axis):
|
|
634
|
-
flipper = vtk.vtkImageFlip()
|
|
635
|
-
flipper.SetFilteredAxes(axis)
|
|
636
|
-
flipper.SetInputData(vtiObj)
|
|
637
|
-
flipper.Update()
|
|
638
|
-
return flipper.GetOutput()
|
|
639
|
-
|
|
640
636
|
|
|
641
637
|
def addFieldDataFromDcmDataSet(vtkObj, ds, extra_tags={}):
|
|
642
638
|
tagsDict = dcmTools.getDicomTagsDict()
|
|
@@ -415,7 +415,7 @@ def checkArgs(args):
|
|
|
415
415
|
return any(allActionArgs)
|
|
416
416
|
|
|
417
417
|
## ========= RUN ACTIONS =========
|
|
418
|
-
def
|
|
418
|
+
def _runActions(args, ap):
|
|
419
419
|
|
|
420
420
|
####
|
|
421
421
|
if args.dcmdump:
|
|
@@ -438,9 +438,13 @@ def runActions(args, ap):
|
|
|
438
438
|
if args.STREAM:
|
|
439
439
|
dcmTools.streamDicoms(args.inputPath, args.outputFolder, FORCE_READ=args.FORCE, HIDE_PROGRESSBAR=args.QUIET, SAFE_NAMING=args.SAFE)
|
|
440
440
|
return 0
|
|
441
|
+
##
|
|
442
|
+
## NOW READING DICOMS
|
|
441
443
|
try:
|
|
442
444
|
onlyOverview = args.inspect or args.inspectFull or args.INTERACTIVE
|
|
443
|
-
oneFilePerDir = args.inspectQuick or args.INTERACTIVE
|
|
445
|
+
oneFilePerDir = args.inspectQuick or args.INTERACTIVE or args.seNumber or args.filter
|
|
446
|
+
# If read one file per dir then will read all dicoms upon write out (or conversion).
|
|
447
|
+
# Only issue is if dicoms not well organised - TODO - NOTE this somewhere... Maybe bettter ad an option for force read all by user.
|
|
444
448
|
if not args.QUIET:
|
|
445
449
|
print(f"READING...")
|
|
446
450
|
ListDicomStudies = dcmTK.ListOfDicomStudies.setFromInput(args.inputPath,
|
|
@@ -451,6 +455,15 @@ def runActions(args, ap):
|
|
|
451
455
|
if args.SAFE:
|
|
452
456
|
ListDicomStudies.setSafeNameMode()
|
|
453
457
|
|
|
458
|
+
if args.seNumber is not None:
|
|
459
|
+
if len(ListDicomStudies) > 1:
|
|
460
|
+
ListDicomStudies = ListDicomStudies.filterByTag('SeriesNumber', args.seNumber)
|
|
461
|
+
else:
|
|
462
|
+
newListOfDicomStudies = []
|
|
463
|
+
for iStudy in ListDicomStudies:
|
|
464
|
+
newListOfDicomStudies.append(iStudy.filterByTag('SeriesNumber', args.seNumber))
|
|
465
|
+
ListDicomStudies = dcmTK.ListOfDicomStudies(newListOfDicomStudies)
|
|
466
|
+
|
|
454
467
|
if args.filter is not None:
|
|
455
468
|
if len(ListDicomStudies) > 1:
|
|
456
469
|
ListDicomStudies = ListDicomStudies.filterByTag(args.filter[0], args.filter[1])
|
|
@@ -464,11 +477,26 @@ def runActions(args, ap):
|
|
|
464
477
|
ap.exit(1, f'Error reading {args.inputPath}.\n {e}')
|
|
465
478
|
# Let IOERROR play out here is not correct input
|
|
466
479
|
##
|
|
480
|
+
## NOW ACTIONS
|
|
467
481
|
if args.inspect or args.inspectFull or args.inspectQuick:
|
|
468
482
|
for iStudy in ListDicomStudies:
|
|
469
483
|
print(iStudy.getTopDir())
|
|
470
484
|
print(iStudy.getStudySummary(args.inspectFull))
|
|
471
485
|
print('\n')
|
|
486
|
+
|
|
487
|
+
elif args.vti2dcm is not None:
|
|
488
|
+
if not os.path.isfile(args.vti2dcm):
|
|
489
|
+
ap.exit(1, f'ERROR: VTI file {args.vti2dcm} not found')
|
|
490
|
+
if not args.vti2dcm.lower().endswith('.vti'):
|
|
491
|
+
ap.exit(1, f'ERROR: VTI file {args.vti2dcm} is not a valid VTI file')
|
|
492
|
+
vtiObj = dcmTK.dcmVTKTK.fIO.readVTKFile(args.vti2dcm)
|
|
493
|
+
series = ListDicomStudies[0][0]
|
|
494
|
+
series.sortBySlice_InstanceNumber()
|
|
495
|
+
dcmDirOut = dcmTK.writeVTIToDicoms(vtiObj, series[0], outputDir=args.outputFolder)
|
|
496
|
+
if not args.QUIET:
|
|
497
|
+
print(f'Written {dcmDirOut}')
|
|
498
|
+
# elif args.nii2dcm is not None:
|
|
499
|
+
# dcmTK.dcmVTKTK.fIO.readNifti(args.nii2dcm)
|
|
472
500
|
elif args.INTERACTIVE:
|
|
473
501
|
# TODO - check if multiple studies
|
|
474
502
|
INTER = INTERACTIVE(ListDicomStudies[0], outputPath=args.outputFolder)
|
|
@@ -505,9 +533,12 @@ def runActions(args, ap):
|
|
|
505
533
|
if not args.QUIET:
|
|
506
534
|
print(f"WRITTING...")
|
|
507
535
|
outDirList = ListDicomStudies.writeToOrganisedFileStructure(args.outputFolder)
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
536
|
+
if len(outDirList) > 0:
|
|
537
|
+
allDirsPresent = all([os.path.isdir(i) for i in outDirList])
|
|
538
|
+
res = 0 if allDirsPresent else 1
|
|
539
|
+
ap.exit(res, f'Transfer and sort from {args.inputPath} to {args.outputFolder} COMPLETE\n')
|
|
540
|
+
else:
|
|
541
|
+
ap.exit(1, f'No dicoms written out for given conditions from {args.inputPath}\n')
|
|
511
542
|
##
|
|
512
543
|
|
|
513
544
|
### ====================================================================================================================
|
|
@@ -531,6 +562,8 @@ def main():
|
|
|
531
562
|
help='set to remove private tags during anonymisation [optional - only used if anonName is given, default="False"]', action='store_true')
|
|
532
563
|
ap.add_argument('-filter', dest='filter',
|
|
533
564
|
help='Will filter dicoms based on tag name and value. Tag name and value required. If input is multiple studies then act on each.', nargs=2, default=None)
|
|
565
|
+
ap.add_argument('-seNumber', dest='seNumber',
|
|
566
|
+
help='Will filter dicoms based on series number. Same as -filter SeriesNumber #', type=str, default=None)
|
|
534
567
|
ap.add_argument('-inspect', dest='inspect',
|
|
535
568
|
help='Will output a summary of dicoms to the terminal', action='store_true')
|
|
536
569
|
ap.add_argument('-inspectFull', dest='inspectFull',
|
|
@@ -553,6 +586,11 @@ def main():
|
|
|
553
586
|
ap.add_argument('-html', dest='html',
|
|
554
587
|
help='Will convert each series to html file for web viewing. Naming: outputfolder argument', action='store_true')
|
|
555
588
|
#
|
|
589
|
+
ap.add_argument('-vti2dcm', dest='vti2dcm',
|
|
590
|
+
help='Will convert VTI to dicom series. Pass reference dicoms as input.', type=str, default=None)
|
|
591
|
+
# ap.add_argument('-nii2dcm', dest='nii2dcm',
|
|
592
|
+
# help='Will convert NII to dicom series. Pass reference dicoms as input.', type=str, default=None)
|
|
593
|
+
#
|
|
556
594
|
ap.add_argument('-I', dest='INTERACTIVE', help='Will read input and launch interactive mode', action='store_true')
|
|
557
595
|
#
|
|
558
596
|
ap.add_argument('-config', dest='configFile', help='Path to configuration file to use.', type=str, default=None)
|
|
@@ -592,8 +630,14 @@ def main():
|
|
|
592
630
|
## -------------
|
|
593
631
|
if arguments.outputFolder is not None:
|
|
594
632
|
arguments.outputFolder = os.path.abspath(arguments.outputFolder)
|
|
633
|
+
# Check if input is subdirectory of output
|
|
634
|
+
if os.path.commonpath([arguments.inputPath]) == os.path.commonpath([arguments.inputPath, arguments.outputFolder]):
|
|
635
|
+
print(f'## ERROR: Input directory ({arguments.inputPath}) cannot be a subdirectory of output directory ({arguments.outputFolder})')
|
|
636
|
+
print('This would cause recursive copying and potential data corruption.')
|
|
637
|
+
print('EXITING')
|
|
638
|
+
sys.exit(1)
|
|
595
639
|
|
|
596
|
-
|
|
640
|
+
_runActions(arguments, ap)
|
|
597
641
|
|
|
598
642
|
|
|
599
643
|
if __name__ == '__main__':
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: spydcmtk
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.3
|
|
4
4
|
Summary: Simple python dicom toolkit.
|
|
5
5
|
Home-page: https://github.com/fraser29/spydcmtk
|
|
6
6
|
Author: Fraser M. Callaghan
|
|
@@ -27,7 +27,18 @@ Requires-Dist: vtk>=9.3.0
|
|
|
27
27
|
Requires-Dist: python-gdcm
|
|
28
28
|
Requires-Dist: highdicom
|
|
29
29
|
Requires-Dist: matplotlib
|
|
30
|
-
Requires-Dist: ngawari
|
|
30
|
+
Requires-Dist: ngawari>=0.1.2
|
|
31
|
+
Dynamic: author
|
|
32
|
+
Dynamic: author-email
|
|
33
|
+
Dynamic: classifier
|
|
34
|
+
Dynamic: description
|
|
35
|
+
Dynamic: description-content-type
|
|
36
|
+
Dynamic: home-page
|
|
37
|
+
Dynamic: keywords
|
|
38
|
+
Dynamic: license
|
|
39
|
+
Dynamic: requires-dist
|
|
40
|
+
Dynamic: requires-python
|
|
41
|
+
Dynamic: summary
|
|
31
42
|
|
|
32
43
|
|
|
33
44
|
# *spydcmtk*
|
|
@@ -42,8 +53,9 @@ This package extends pydicom with a class structure based upon the Patient-Study
|
|
|
42
53
|
|
|
43
54
|
## Version
|
|
44
55
|
|
|
45
|
-
Current is VERSION 1.2.
|
|
56
|
+
Current is VERSION 1.2.3 Release.
|
|
46
57
|
|
|
58
|
+
- 1.2.3: Fix VTI to DICOM and add to script. Update tests. Fix jpg to DICOM. nii2dcm also handled but nii orientation is not adjusted from RAS to LPS.
|
|
47
59
|
- 1.2.2: Fix DICOM to VTK conversion bug. Add 4DFlow MRI to VTK conversion capability.
|
|
48
60
|
- 1.2.1: Add filter by tag name and value. Add build image overview option. Update to use pydicom >=3.0.1
|
|
49
61
|
- 1.2.0: Improved stability of VTK conversion. Bug fixes. Add basic interactive functionality. Add functionality to construct 4D-flow datasets. Add reliance on external library ngawari for basic IO operations, format conversion and vtk filter actions.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|