|
@@ -46,13 +46,16 @@ class parseDicomLogic(ScriptedLoadableModuleLogic):
|
|
|
def setFileBrowser(self,fb):
|
|
|
self.fb=fb
|
|
|
|
|
|
+ def setTempBase(self,tb):
|
|
|
+ self.tempBase=tb
|
|
|
+
|
|
|
def filelist(self,mypath,remote=True):
|
|
|
if remote:
|
|
|
print("Using labkey")
|
|
|
#not sure if labkey is available, so try it
|
|
|
- ok, files=self.fb.listRemoteDir(labkeyPath)
|
|
|
+ ok, files=self.fb.listRemoteDir(mypath)
|
|
|
if not ok:
|
|
|
- print "Error accessing path"
|
|
|
+ print("Error accessing path")
|
|
|
return []
|
|
|
#files=[self.net.GetRelativePathFromLabkeyPath(f) for f in files]
|
|
|
|
|
@@ -92,13 +95,13 @@ class parseDicomLogic(ScriptedLoadableModuleLogic):
|
|
|
try:
|
|
|
plan = pydicom.dcmread(g)
|
|
|
except:
|
|
|
- print ("{}: Not a dicom file").format(g)
|
|
|
+ print ("{}: Not a dicom file".format(g))
|
|
|
return False
|
|
|
|
|
|
try:
|
|
|
self.nframe=plan[0x0019,0x10a5].value;
|
|
|
except:
|
|
|
- print ("{}: Not a master file").format(g)
|
|
|
+ print ("{}: Not a master file".format(g))
|
|
|
return False
|
|
|
if not (type(self.nframe) is list) :
|
|
|
print("nframe not a list")
|
|
@@ -126,7 +129,7 @@ class parseDicomLogic(ScriptedLoadableModuleLogic):
|
|
|
try:
|
|
|
plan = pydicom.dcmread(g)
|
|
|
except:
|
|
|
- print ("{}: Not a dicom file").format(g)
|
|
|
+ print ("{}: Not a dicom file".format(g))
|
|
|
return False
|
|
|
|
|
|
try:
|
|
@@ -152,8 +155,8 @@ class parseDicomLogic(ScriptedLoadableModuleLogic):
|
|
|
#(as the mid point between starting and ending the frame)
|
|
|
self.frame_time[ifi]=0.5*(self.frame_start[ifi]+self.frame_stop[ifi]); #in ms
|
|
|
|
|
|
- print "({},{}) converted to {} at {} for {}".format(
|
|
|
- phase,cycle,ifi,self.frame_time[ifi],self.frame_duration[ifi])
|
|
|
+ print("({},{}) converted to {} at {} for {}".format(\
|
|
|
+ phase,cycle,ifi,self.frame_time[ifi],self.frame_duration[ifi]))
|
|
|
|
|
|
|
|
|
#play with pixel data
|
|
@@ -162,7 +165,7 @@ class parseDicomLogic(ScriptedLoadableModuleLogic):
|
|
|
sh=list(sh)
|
|
|
sh.append(self.nframe[-1])#add number of time slots
|
|
|
self.frame_data=np.empty(sh)
|
|
|
- print "Setting frame_data to",sh
|
|
|
+ print(" Setting frame_data to {}".format(sh))
|
|
|
|
|
|
#check & update pixel size
|
|
|
pixel_size_read=[plan.PixelSpacing[0],plan.PixelSpacing[1],
|
|
@@ -172,26 +175,26 @@ class parseDicomLogic(ScriptedLoadableModuleLogic):
|
|
|
if self.pixel_size[i] == 0:
|
|
|
self.pixel_size[i] = float(pixel_size_read[i])
|
|
|
if abs(self.pixel_size[i]-pixel_size_read[i]) > 1e-3:
|
|
|
- print 'Pixel size mismatch {.2f}/{.2f}'.format(self.pixel_size[i],
|
|
|
- pixel_size_read[i])
|
|
|
+ print('Pixel size mismatch {.2f}/{.2f}'.format(self.pixel_size[i],\
|
|
|
+ pixel_size_read[i]))
|
|
|
|
|
|
center_read=plan.DetectorInformationSequence[0].ImagePositionPatient
|
|
|
- print "Stored center at ({0},{1},{2})".format(self.center[0],self.center[1],self.center[2])
|
|
|
- print "Read center at ({0},{1},{2})".format(center_read[0],center_read[1],center_read[2])
|
|
|
+ print("Stored center at ({0},{1},{2})".format(self.center[0],self.center[1],self.center[2]))
|
|
|
+ print("Read center at ({0},{1},{2})".format(center_read[0],center_read[1],center_read[2]))
|
|
|
for i in range(0,3):
|
|
|
if self.center[i] == 0:
|
|
|
self.center[i] = float(center_read[i])
|
|
|
if abs(self.center[i]-center_read[i]) > 1e-3:
|
|
|
- print 'Image center mismatch {.2f}/{.2f}'.format(self.center[i],
|
|
|
- center_read[i])
|
|
|
+ print('Image center mismatch {.2f}/{.2f}'.format(self.center[i],\
|
|
|
+ center_read[i]))
|
|
|
|
|
|
frame_orientation_read=plan.DetectorInformationSequence[0].ImageOrientationPatient
|
|
|
for i in range(0,6):
|
|
|
if self.frame_orientation[i] == 0:
|
|
|
self.frame_orientation[i] = float(frame_orientation_read[i])
|
|
|
if abs(self.frame_orientation[i]-frame_orientation_read[i]) > 1e-3:
|
|
|
- print 'Image orientation mismatch {.2f}/{.2f}'.format(
|
|
|
- self.frame_rotation[i], frame_orientation_read[i])
|
|
|
+ print('Image orientation mismatch {.2f}/{.2f}'.format(
|
|
|
+ self.frame_rotation[i], frame_orientation_read[i]))
|
|
|
|
|
|
|
|
|
|
|
@@ -205,12 +208,12 @@ class parseDicomLogic(ScriptedLoadableModuleLogic):
|
|
|
try:
|
|
|
plan = pydicom.dcmread(g)
|
|
|
except:
|
|
|
- print ("{}: Not a dicom file").format(g)
|
|
|
+ print ("{}: Not a dicom file".format(g))
|
|
|
return False
|
|
|
|
|
|
|
|
|
if plan.Modality != 'CT':
|
|
|
- print ('{}: Not a CT file').format(g)
|
|
|
+ print ('{}: Not a CT file'.format(g))
|
|
|
return False
|
|
|
|
|
|
#this doesn't work in 2019 data version
|
|
@@ -221,17 +224,19 @@ class parseDicomLogic(ScriptedLoadableModuleLogic):
|
|
|
try:
|
|
|
iType=plan.ImageType
|
|
|
except:
|
|
|
- print "Image type not found"
|
|
|
+ print("Image type not found")
|
|
|
return False
|
|
|
|
|
|
if iType[3].find("SPI")<0:
|
|
|
- print "Not a spiral image"
|
|
|
+ print("Not a spiral image")
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
- print '.',
|
|
|
- self.ct_data.append(plan.pixel_array)
|
|
|
+ self.ct_data.append(\
|
|
|
+ pydicom.pixel_data_handlers.util.apply_modality_lut(\
|
|
|
+ plan.pixel_array,plan))
|
|
|
+
|
|
|
self.ct_idx.append(plan.InstanceNumber)
|
|
|
self.ct_z.append(plan.ImagePositionPatient[2])
|
|
|
|
|
@@ -243,15 +248,15 @@ class parseDicomLogic(ScriptedLoadableModuleLogic):
|
|
|
if self.ct_pixel_size[i] == 0:
|
|
|
self.ct_pixel_size[i] = float(pixel_size_read[i])
|
|
|
if abs(self.ct_pixel_size[i]-pixel_size_read[i]) > 1e-3:
|
|
|
- print 'Pixel size mismatch {.2f}/{.2f}'.format(self.ct_pixel_size[i],
|
|
|
- pixel_size_read[i])
|
|
|
+ print('Pixel size mismatch {.2f}/{.2f}'.format(self.ct_pixel_size[i],
|
|
|
+ pixel_size_read[i]))
|
|
|
|
|
|
for i in range(0,2):
|
|
|
if self.ct_center[i] == 0:
|
|
|
self.ct_center[i] = float(plan.ImagePositionPatient[i])
|
|
|
if abs(self.ct_center[i]-plan.ImagePositionPatient[i]) > 1e-3:
|
|
|
- print 'Image center mismatch {.2f}/{.2f}'.format(self.ct_center[i],
|
|
|
- plan.ImagePositionPatient[i])
|
|
|
+ print('Image center mismatch {.2f}/{.2f}'.format(self.ct_center[i],
|
|
|
+ plan.ImagePositionPatient[i]))
|
|
|
#not average, but minimum (!) why??
|
|
|
|
|
|
if plan.ImagePositionPatient[2]<self.ct_center[2]:
|
|
@@ -261,19 +266,19 @@ class parseDicomLogic(ScriptedLoadableModuleLogic):
|
|
|
if self.ct_orientation[i] == 0:
|
|
|
self.ct_orientation[i] = float(plan.ImageOrientationPatient[i])
|
|
|
if abs(self.ct_orientation[i]-plan.ImageOrientationPatient[i]) > 1e-3:
|
|
|
- print 'Image orientation mismatch {0:.2f}/{1:.2f}'.format(self.ct_orientation[i],
|
|
|
- plan.ImageOrientationPatient[i])
|
|
|
+ print('Image orientation mismatch {0:.2f}/{1:.2f}'.format(self.ct_orientation[i],\
|
|
|
+ plan.ImageOrientationPatient[i]))
|
|
|
|
|
|
return True
|
|
|
|
|
|
def readMasterDirectory(self,mypath,remote=True):
|
|
|
self.axisShift=(2,1,0)
|
|
|
|
|
|
- print("Reading master from {}").format(mypath)
|
|
|
+ print("Reading master from {}".format(mypath))
|
|
|
|
|
|
filelist=self.filelist(mypath,remote)
|
|
|
for f in filelist:
|
|
|
- print '{}:'.format(f)
|
|
|
+ print('{}:'.format(f))
|
|
|
|
|
|
g,ok=self.getfile(f,remote)
|
|
|
if not(ok):
|
|
@@ -313,7 +318,7 @@ class parseDicomLogic(ScriptedLoadableModuleLogic):
|
|
|
self.ct_center[2]=1e30
|
|
|
self.ct_orientation=[0,0,0,0,0,0]
|
|
|
for f in onlyfiles:
|
|
|
- print '{}:'.format(f)
|
|
|
+ print('{}:'.format(f))
|
|
|
|
|
|
g,ok=self.getfile(f,remote)
|
|
|
if not(ok):
|