Skip to content

Instantly share code, notes, and snippets.

@freeman-lab
Created July 4, 2016 03:39
Show Gist options
  • Save freeman-lab/330183fdb0ea7f4103deddc9fae18113 to your computer and use it in GitHub Desktop.
Save freeman-lab/330183fdb0ea7f4103deddc9fae18113 to your computer and use it in GitHub Desktop.
neurofinder algorithm : local nmf
# neurofinder submission
# local nmf
#
# requirements:
# thunder-python v1.2.0
# thunder-extraction v1.1.0
import json
import thunder as td
from extraction import NMF
datasets = [
'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 = []
for dataset in datasets:
print('processing dataset: %s' % dataset)
print('loading')
path = 'neurofinder.' + dataset
data = td.images.fromtif(path + '/images', ext='tiff')
print('analyzing')
algorithm = NMF(k=5, percentile=99, max_iter=50, overlap=0.1)
model = algorithm.fit(data, chunk_size=(50,50), padding=(25,25))
merged = model.merge(0.1)
print('found %g regions' % merged.regions.count)
regions = [{'coordinates': region.coordinates.tolist()} for region in merged.regions]
result = {'dataset': dataset, 'regions': regions}
submission.append(result)
print('writing results')
with open('submission.json', 'w') as f:
f.write(json.dumps(submission))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment