How to use the gala.features.base function in gala

To help you get started, we’ve selected a few gala examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github janelia-flyem / gala / tests / test_server.py View on Github external
def dummy_data():
    frag0 = np.arange(1, 17, dtype=int).reshape((4, 4))
    gt0 = np.array([[1, 1, 2, 2], [1, 1, 2, 2], [3] * 4, [3] * 4], dtype=int)
    frag, gt = (ndi.zoom(image, 4, order=0, mode='reflect')
                for image in [frag0, gt0])
    fman = features.base.Mock(frag, gt)
    return frag, gt, fman
github janelia-flyem / gala / gala / features / moments.py View on Github external
import numpy as np
from scipy.misc import comb as nchoosek
from . import base

class Manager(base.Null):
    def __init__(self, nmoments=4, use_diff_features=True, oriented=False, 
            normalize=False, *args, **kwargs):
        super(Manager, self).__init__()
        self.nmoments = nmoments
        self.use_diff_features = use_diff_features
        self.oriented = oriented
        self.normalize = normalize

    @classmethod
    def load_dict(cls, fm_info):
        obj = cls(fm_info['nmoments'], fm_info['use_diff'],
                    fm_info['oriented'], fm_info['normalize'])
        return obj

    def write_fm(self, json_fm={}):
        if 'feature_list' not in json_fm:
github janelia-flyem / gala / gala / features / orientation.py View on Github external
import numpy as np
from numpy.linalg import eig, norm
from . import base

class Manager(base.Null):
    def __init__(self, *args, **kwargs):
        super(Manager, self).__init__()

    def write_fm(self, json_fm={}):
        if 'feature_list' not in json_fm:
            json_fm['feature_list'] = []
        json_fm['feature_list'].append('orientation')
        json_fm['orientation'] = {} 
        return json_fm

    def create_node_cache(self, g, n):
        # Get subscripts of extent (morpho.unravel_index was slow)
        M = np.zeros_like(g.watershed); 
        M.ravel()[list(g.extent(n))] = 1 
        ind = np.array(np.nonzero(M)).T
        # Get second moment matrix
github janelia-flyem / gala / gala / features / graph.py View on Github external
from __future__ import absolute_import
# external libraries
import numpy as np
import networkx as nx

# local imports
from . import base

class Manager(base.Null):
    def __init__(self, *args, **kwargs):
        super(Manager, self).__init__()

    def write_fm(self, json_fm={}):
        if 'feature_list' not in json_fm:
            json_fm['feature_list'] = []
        json_fm['feature_list'].append('graph')
        json_fm['graph'] = {}
        return json_fm

    def compute_node_features(self, g, n, cache=None):
        deg = g.degree(n)
        ndeg = nx.algorithms.average_neighbor_degree(g, nodes=[n])[n]
        return np.array([deg, ndeg])

    def compute_edge_features(self, g, n1, n2, cache=None):
github janelia-flyem / gala / gala / features / inclusion.py View on Github external
import numpy as np
from . import base

class Manager(base.Null):
    def __init__(self, *args, **kwargs):
        super(Manager, self).__init__()

    @classmethod
    def load_dict(cls, fm_info):
        obj = cls()
        return obj

    def write_fm(self, json_fm={}):
        if 'feature_list' not in json_fm:
            json_fm['feature_list'] = []
        json_fm['feature_list'].append('inclusiveness')
        json_fm['inclusiveness'] = {} 
        return json_fm

    def compute_node_features(self, g, n, cache=None):
github janelia-flyem / gala / gala / features / histogram.py View on Github external
import numpy as np

from . import base
 
class Manager(base.Null):
    def __init__(self, nbins=4, minval=0.0, maxval=1.0, 
            compute_percentiles=[], oriented=False, 
            compute_histogram=True, use_neuroproof=False, *args, **kwargs):
        super(Manager, self).__init__()
        self.minval = minval
        self.maxval = maxval
        self.nbins = nbins
        self.oriented = oriented
        self.compute_histogram = compute_histogram
        self.use_neuroproof = use_neuroproof

        try:
            _ = len(compute_percentiles)
        except TypeError: # single percentile value given
            compute_percentiles = [compute_percentiles]
        self.compute_percentiles = compute_percentiles
github janelia-flyem / gala / gala / features / graph.py View on Github external
# external libraries
import numpy as np
import networkx as nx

# local imports
from . import base

class Manager(base.Null):
    def __init__(self, *args, **kwargs):
        super(Manager, self).__init__()

    def write_fm(self, json_fm={}):
        if 'feature_list' not in json_fm:
            json_fm['feature_list'] = []
        json_fm['feature_list'].append('graph')
        json_fm['graph'] = {}
        return json_fm

    def compute_node_features(self, g, n, cache=None):
        deg = g.degree(n)
        ndeg = nx.algorithms.average_neighbor_degree(g, nodes=[n])[n]
        return np.array([deg, ndeg])

    def compute_edge_features(self, g, n1, n2, cache=None):