-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckImages.py
executable file
·81 lines (73 loc) · 3.55 KB
/
CheckImages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import nrrd, os, glob, sys, csv
import xscore, slicescore
import numpy as np
try:
from cmtk import template
except:
template = '/Volumes/Macintosh HD/Users/robertcourt/BTSync/usedtemplate.nrrd'
testtemp = template
if os.path.isfile(template):
data1, header1 = nrrd.read(template)
elif os.path.isfile('/disk/data/VFBTools/Alignment/template/flyVNCtemplate20xA.nrrd'):
data1, header1 = nrrd.read('/disk/data/VFBTools/Alignment/template/flyVNCtemplate20xA.nrrd')
else:
print 'Template file missing!'
data1 = []
if not data1==[]:
ctemplate = xscore.xslice(data1)
ztemplate = slicescore.zsampleslice(data1)
ytemplate = slicescore.ysampleslice(data1)
xtemplate = slicescore.xsampleslice(data1)
del data1, header1
def rateAll(path,match="*BG*.nrrd",results="./OverlapResults.csv", methord=slicescore.OverlapCoeff):
r=[]
for file in glob.glob(path + os.sep + match):
print "testing:" + os.path.basename(file)
data2, header2 = nrrd.read(file)
calignment = xscore.xslice(data2)
zalignment = slicescore.zsampleslice(data2)
yalignment = slicescore.ysampleslice(data2)
xalignment = slicescore.xsampleslice(data2)
del data2, header2
r.append((os.path.basename(file),xscore.symTest(methord,calignment),methord(ctemplate,calignment),methord(ztemplate,zalignment),methord(ytemplate,yalignment),methord(xtemplate,xalignment)))
if not results==None:
with open(results, 'a') as csvfile:
spamwriter = csv.writer(csvfile)
spamwriter.writerow([path,r[-1][0],"[Symmetry,Diagonal,Zsample,Ysample,Xsample,Final]score",r[-1][1],r[-1][2],r[-1][3],r[-1][4],r[-1][5],min(r[-1][1:])])
del xalignment
if r == []:
print 'no files found matching: ' + path + match
return r
def rateOne(file,results="./OverlapResults.csv", methord=slicescore.OverlapCoeff, template=template):
if os.path.isfile(template):
data1, header1 = nrrd.read(template)
else:
print 'Template file missing!'
data1 = []
if not data1==[]:
ctemplate = xscore.xslice(data1)
ztemplate = slicescore.zsampleslice(data1)
ytemplate = slicescore.ysampleslice(data1)
xtemplate = slicescore.xsampleslice(data1)
del data1, header1
r=np.float128(0.0)
if os.path.isfile(file):
print "testing:" + os.path.basename(file)
data2, header2 = nrrd.read(file)
calignment = xscore.xslice(data2)
zalignment = slicescore.zsampleslice(data2)
yalignment = slicescore.ysampleslice(data2)
xalignment = slicescore.xsampleslice(data2)
del data2, header2
r = np.fmin(np.array([xscore.symTest(slicescore.OverlapCoeff,calignment),methord(ctemplate,calignment),methord(ztemplate,zalignment),methord(ytemplate,yalignment),methord(xtemplate,xalignment)]))
if not results==None:
with open(results, 'a') as csvfile:
spamwriter = csv.writer(csvfile)
spamwriter.writerow([path,r[-1][0],"[Symmetry,Diagonal,Zsample,Ysample,Xsample,Final]score",r[-1][1],r[-1][2],r[-1][3],r[-1][4],r[-1][5],min(r[-1][1:])])
del xalignment
return r
#out = rateAll("/Volumes/Data0/BTDataSync/NewLineageScans/Aligned/failed",results="/Volumes/Macintosh HD/Users/robertcourt/BTSync/failed-xscore.csv")
#out = rateAll("/Volumes/Data0/BTDataSync/NewLineageScans/Aligned",results=None)
if __name__ == "__main__":
print 'example: out = rateAll("/Volumes/Data0/BTDataSync/NewLineageScans/Aligned",results="/Volumes/Data0/BTDataSync/NewLineageScans/Aligned/aligned-xscore.csv")'
#print 'Done.'