Last active
June 8, 2016 18:49
-
-
Save freeman-lab/5197ee99b8a54145cb9c to your computer and use it in GitHub Desktop.
example neurofinder algorithm : generates random regions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from numpy import zeros, random, asarray, where, ones | |
from scipy.ndimage.morphology import binary_closing, binary_dilation | |
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'] | |
dims = [500,500] | |
margin = 20 | |
n = 200 | |
submission = [] | |
def topoly(c): | |
tmp = zeros(dims) | |
coords = asarray([c[0] + random.randn(32) * 3, c[1] + random.randn(32) * 3]) | |
tmp[coords.astype('int').tolist()] = 1 | |
tmp = binary_dilation(tmp, ones((3, 3))) | |
tmp = binary_closing(tmp, ones((7, 7))) | |
return asarray(where(tmp)).T.tolist() | |
for dataset in datasets: | |
xcenters = (dims[0] - margin) * random.random_sample(n) + margin/2 | |
ycenters = (dims[1] - margin) * random.random_sample(n) + margin/2 | |
centers = zip(xcenters, ycenters) | |
regions = [{'coordinates': topoly(c)} for c in centers] | |
result = {'dataset': dataset, 'regions': regions} | |
submission.append(result) | |
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
this "algorithm" generates garbage, and is intended only as an example of how to create a results file!