|
@@ -0,0 +1,70 @@
|
|
|
+import numpy
|
|
|
+import config
|
|
|
+import SimpleITK
|
|
|
+import os
|
|
|
+import getData
|
|
|
+
|
|
|
+def guessPixelPosition(sx=-1,sy=-1,sz=-1):
|
|
|
+ #guess position of segments
|
|
|
+ if sx<0:
|
|
|
+ sx=12
|
|
|
+ if sy<0:
|
|
|
+ sy=28
|
|
|
+ if sz<0:
|
|
|
+ sz=32
|
|
|
+ rz=4
|
|
|
+ oz=0
|
|
|
+
|
|
|
+ slc=[sx,sy,sz]
|
|
|
+ p1=[sx,sy,sz]
|
|
|
+
|
|
|
+ #tip
|
|
|
+ fp={'0':[\
|
|
|
+ [sx,sy,sz],
|
|
|
+ [sx-5,sy,sz],\
|
|
|
+ [sx-2,sy,sz-rz],\
|
|
|
+ [sx+3,sy,sz-rz],\
|
|
|
+ [sx-2,sy,sz+rz-1],\
|
|
|
+ [sx+3,sy,sz+rz]],\
|
|
|
+ '1':[\
|
|
|
+ [sx,sy,sz],
|
|
|
+ [sx-5,sy,sz],\
|
|
|
+ [sx-1,sy-rz,sz],\
|
|
|
+ [sx-1,sy+rz-1,sz],\
|
|
|
+ [sx+3,sy-rz,sz],\
|
|
|
+ [sx+3,sy+rz,sz]],\
|
|
|
+ '2':[\
|
|
|
+ [sx,sy,sz],
|
|
|
+ [sx,sy+rz+oz,sz],\
|
|
|
+ [sx,sy+0.3*rz+oz,sz-rz],\
|
|
|
+ [sx,sy-0.3*rz+oz,sz-rz],\
|
|
|
+ [sx,sy-rz+oz,sz],\
|
|
|
+ [sx,sy-0.3*rz+oz,sz+rz],\
|
|
|
+ [sx,sy+0.3*rz+oz,sz+rz]]}
|
|
|
+ return fp
|
|
|
+
|
|
|
+
|
|
|
+def getPatientNIM(r,setup):
|
|
|
+ locDir=config.getLocalDir(r,setup)
|
|
|
+ fileName=config.getNodeName(r,setup,'NM',19)+'.nrrd'
|
|
|
+ f=os.path.join(locDir,fileName)
|
|
|
+ im=SimpleITK.ReadImage(f)
|
|
|
+ nim=SimpleITK.GetArrayFromImage(im)
|
|
|
+ return nim
|
|
|
+
|
|
|
+def writeSegmentation(db,r,setup):
|
|
|
+ locDir=config.getLocalDir(r,setup)
|
|
|
+ fileName='{}_Segmentation.txt'.format(config.getCode(r,setup))
|
|
|
+ idFilter={'variable':'PatientId','value':config.getPatientId(r,setup),'oper':'eq'}
|
|
|
+ visitFilter={'variable':'visitName','value':config.getVisitId(r,setup),'oper':'eq'}
|
|
|
+ rows=getData.getSegmentation(db,setup,[idFilter,visitFilter])
|
|
|
+ v=numpy.zeros((len(rows),3))
|
|
|
+ for qr in rows:
|
|
|
+ region=int(qr['regionId'])
|
|
|
+ v[region,2]=float(qr['x'])
|
|
|
+ v[region,1]=float(qr['y'])
|
|
|
+ v[region,0]=float(qr['z'])
|
|
|
+ #for i in range(len(rows)):
|
|
|
+ # print(v[i,:])
|
|
|
+ numpy.savetxt(os.path.join(locDir,fileName),v)
|
|
|
+
|