|
@@ -3,6 +3,7 @@ import config
|
|
import SimpleITK
|
|
import SimpleITK
|
|
import os
|
|
import os
|
|
import getData
|
|
import getData
|
|
|
|
+import matplotlib.pyplot
|
|
|
|
|
|
def guessPixelPosition15(sx=-1,sy=-1,sz=-1):
|
|
def guessPixelPosition15(sx=-1,sy=-1,sz=-1):
|
|
#guess position of segments
|
|
#guess position of segments
|
|
@@ -134,14 +135,6 @@ def updateSegmentation(db,setup,r,pixels):
|
|
print('Done')
|
|
print('Done')
|
|
|
|
|
|
|
|
|
|
-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):
|
|
def writeSegmentation(db,r,setup):
|
|
locDir=config.getLocalDir(r,setup)
|
|
locDir=config.getLocalDir(r,setup)
|
|
fileName='{}_Segmentation.txt'.format(config.getCode(r,setup))
|
|
fileName='{}_Segmentation.txt'.format(config.getCode(r,setup))
|
|
@@ -157,4 +150,62 @@ def writeSegmentation(db,r,setup):
|
|
#for i in range(len(rows)):
|
|
#for i in range(len(rows)):
|
|
# print(v[i,:])
|
|
# print(v[i,:])
|
|
numpy.savetxt(os.path.join(locDir,fileName),v)
|
|
numpy.savetxt(os.path.join(locDir,fileName),v)
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+def plotSegmentation(db,fb,r,setup):
|
|
|
|
+ copyFields=['PatientId','visitName']
|
|
|
|
+ qFilter=[{'variable':x,'value':r[x],'oper':'eq'} for x in copyFields]
|
|
|
|
+ nim=getData.getPatientNIM(fb,r,setup)
|
|
|
|
+ rows=getData.getSegmentation(db,setup,qFilter)
|
|
|
|
+
|
|
|
|
+ if len(rows)==0:
|
|
|
|
+ print('Not found for id={}/{}'.format(pId,visitName))
|
|
|
|
+ return
|
|
|
|
+
|
|
|
|
+ fp={}
|
|
|
|
+
|
|
|
|
+ for q in rows:
|
|
|
|
+ if q['regionId']==0:
|
|
|
|
+ slc=[q['x'],q['y'],q['z']]
|
|
|
|
+ slc=[int(x) for x in slc]
|
|
|
|
+ slices=q['sliceId'].split(';')
|
|
|
|
+ for s in slices:
|
|
|
|
+ try:
|
|
|
|
+ fp[s].append([float(x) for x in [q['x'],q['y'],q['z']]])
|
|
|
|
+ except KeyError:
|
|
|
|
+ fp[s]=[]
|
|
|
|
+ fp[s].append([float(x) for x in [q['x'],q['y'],q['z']]])
|
|
|
|
+
|
|
|
|
+ cut0=20
|
|
|
|
+ w0=20
|
|
|
|
+ cut1=20
|
|
|
|
+ w1=20
|
|
|
|
+ cut2=20
|
|
|
|
+ w2=20
|
|
|
|
+ vmax=1000
|
|
|
|
+ vmin=0
|
|
|
|
+ nd=3
|
|
|
|
+ fig,ax=matplotlib.pyplot.subplots(3,2*nd+1,figsize=(20,12))
|
|
|
|
+ for i in numpy.arange(0,2*nd+1):
|
|
|
|
+ ax[0,i].set_xlabel('z')
|
|
|
|
+ ax[0,i].set_ylabel('x')
|
|
|
|
+ ax[0,i].imshow(nim[cut2:cut2+w2,slc[1]-nd+i,cut0:cut0+w0],cmap='gray_r',vmax=vmax,vmin=vmin)
|
|
|
|
+ ax[1,i].set_xlabel('x')
|
|
|
|
+ ax[1,i].set_ylabel('y')
|
|
|
|
+ ax[1,i].imshow(nim[cut2:cut2+w2,cut0:cut0+w0,slc[2]-nd+i].T,cmap='gray_r',vmax=vmax,vmin=vmin)
|
|
|
|
+ ax[2,i].set_xlabel('z')
|
|
|
|
+ ax[2,i].set_ylabel('y')
|
|
|
|
+ ax[2,i].imshow(nim[slc[0]-nd+i,cut1:cut1+w1,cut1:cut1+w1],cmap='gray_r',vmax=vmax,vmin=vmin)
|
|
|
|
+ if i==nd:
|
|
|
|
+ pt=fp['0']
|
|
|
|
+ ax[0,i].scatter([x[2]-cut0 for x in pt],[x[0]-cut2 for x in pt])
|
|
|
|
+ pt=fp['1']
|
|
|
|
+ ax[1,i].scatter([x[0]-cut2 for x in pt],[x[1]-cut0 for x in pt])
|
|
|
|
+ pt=fp['2']
|
|
|
|
+ ax[2,i].scatter([x[2]-cut1 for x in pt],[x[1]-cut1 for x in pt])
|
|
|
|
+
|
|
|
|
+ if i==0:
|
|
|
|
+ ax[0,i].text(2,2,pId,fontsize='large')
|
|
|
|
+ name='{}_segmentation.png'.format(config.getCode(r,setup))
|
|
|
|
+ fPath=getData.getLocalPath(r,setup,name)
|
|
|
|
+ fig.savefig(fPath)
|
|
|
|
+ getData.copyToServer(fb,r,setup,[name])
|