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
from cloudvolume import CloudVolume | |
cv = CloudVolume( | |
'graphene://https://fafbv2.dynamicannotationframework.com/segmentation/1.0/fly_v31', # neuroglancer layer | |
use_https=True # uses the public access interface | |
) | |
# Download and Save a Mesh to Disk | |
mesh = cv.mesh.get(720575940621065107) | |
with open('720575940621065107.ply', 'wb') as f: |
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 numpy as np | |
import h5py | |
from tqdm import tqdm | |
from cloudvolume import view | |
def find_section_clamping_values(zlevel, lowerfract, upperfract): | |
filtered = np.copy(zlevel) | |
# remove pure black from frequency counts as |
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
def countless_stippled(data): | |
""" | |
Vectorized implementation of downsampling a 2D | |
image by 2 on each side using the COUNTLESS algorithm | |
that treats zero as "background" that doesn't count | |
for the purposes of choosing the mode. | |
data is a 2D numpy array with even dimensions. | |
""" | |
sections = [] |
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
from itertools import combinations | |
from functools import reduce | |
import numpy as np | |
def countlessND(data, factor): | |
assert len(data.shape) == len(factor) | |
sections = [] | |
mode_of = reduce(lambda x,y: x * y, factor) |
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
from itertools import combinations | |
from functools import reduce | |
import numpy as np | |
def dynamic_zero_corrected_countless3d(data): | |
sections = [] | |
# shift zeros up one so they don't interfere with bitwise operators | |
# we'll shift down at the end | |
data += 1 |
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
from itertools import combinations | |
from functools import reduce | |
import numpy as np | |
def countless3d(data): | |
"""Now write countless8 in such a way that it could be used | |
to process an image.""" | |
sections = [] | |
# shift zeros up one so they don't interfere with bitwise operators |
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
from itertools import combinations | |
from functools import reduce | |
def countless8(a,b,c,d,e,f,g,h): | |
"""Extend countless5 to countless8. Same deal, except we also | |
need to check for matches of length 4.""" | |
sections = [ a, b, c, d, e, f, g, h ] | |
# PICKN = PICK with N arguments | |
p2 = lambda q,r: q * (q == r) # PICK2 |
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
from itertools import combinations | |
from functools import reduce | |
def countless5(a,b,c,d,e): | |
"""First stage of generalizing from countless2d. | |
You have five slots: A, B, C, D, E | |
You can decide if something is the winner by first checking for | |
matches of three, then matches of two, then picking just one if |
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 csv | |
import os | |
import sys | |
from collections import defaultdict | |
rows = [] | |
filename = sys.argv[1] | |
_, ext = os.path.splitext(filename) |
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 csv | |
from collections import defaultdict | |
import copy | |
import random | |
def tabulate(voters, round=1): | |
votes = defaultdict(int) | |
for voter in voters: | |
if len(voter) == 0: # abstention |
NewerOlder