-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain.py
49 lines (40 loc) · 1.35 KB
/
Main.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
# built from thunder examples
import json
import thunder as td
from extraction import NMF
class BrainBlast:
def __init__(self, f, d, s):
self.folder = f
self.data = d
self.submission = s
def learn_data(self):
for d in self.data:
path = self.folder + d
print "Analyzing " + path
image_data = td.images.fromtif(path + '/images', ext='tiff')
algorithm = NMF(k=10, percentile=99, max_iter=50, overlap=0.1)
model = algorithm.fit(image_data, chunk_size=(50, 50), padding=(25, 25))
merged = model.merge(0.1)
regions = [{'coordinates': region.coordinates.tolist()} for region in merged.regions]
result = {'dataset': self.data, 'regions': regions}
self.submission.append(result)
def save_submission(self):
with open('submission.json', 'w') as sf:
sf.write(json.dumps(self.submission))
if __name__ == "__main__":
folder_path = '/media/brad/disk2/nf_data_test/neurofinder.'
files = [
'00.00.test',
'00.01.test',
'01.00.test',
'01.01.test',
'02.00.test',
'02.01.test',
'03.00.test',
'04.00.test',
'04.01.test'
]
submission = []
bb = BrainBlast(folder_path, files, submission)
bb.learn_data()
bb.save_submission()