How to use the gala.morpho.pad 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 / gala / agglo.py View on Github external
"""
        if len(probs) == 0:
            self.probabilities = zeros_like(self.watershed)
            self.probabilities_r = self.probabilities.ravel()
        probs = probs.astype('float')
        if normalize and len(probs) > 1:
            probs -= probs.min() # ensure probs.min() == 0
            probs /= probs.max() # ensure probs.max() == 1
        sp = probs.shape
        sw = tuple(array(self.watershed.shape, dtype=int)-\
                    2*self.pad_thickness*ones(self.watershed.ndim, dtype=int))
        p_ndim = probs.ndim
        w_ndim = self.watershed.ndim
        padding = [inf]+(self.pad_thickness-1)*[0]
        if p_ndim == w_ndim:
            self.probabilities = morpho.pad(probs, padding)
            self.probabilities_r = self.probabilities.ravel()[:,newaxis]
        elif p_ndim == w_ndim+1:
            axes = list(range(p_ndim-1))
            self.probabilities = morpho.pad(probs, padding, axes)
            self.probabilities_r = self.probabilities.reshape(
                                                (self.watershed.size, -1))
github janelia-flyem / gala / gala / stack_np.py View on Github external
def init_build2(self, watershed, probabilities):
        watershed = morpho.pad(watershed, 0)
        watershed = watershed.astype(numpy.double)    

        neuroproof.reinit_stack2(self.stack, watershed)

        probabilities = probabilities.astype(numpy.double)
        num_channels = 1
        if self.single_channel:
            probabilities = morpho.pad(probabilities, 0)
            neuroproof.add_prediction_channel2(self.stack, probabilities)
        else:
            num_channels = probabilities.shape[probabilities.ndim-1]
            for channel in range(0,num_channels):
                curr_prob = morpho.pad(probabilities[...,channel], 0)
                neuroproof.add_prediction_channel2(self.stack, curr_prob)
github janelia-flyem / gala / gala / stack_np.py View on Github external
def init_build2(self, watershed, probabilities):
        watershed = morpho.pad(watershed, 0)
        watershed = watershed.astype(numpy.double)    

        neuroproof.reinit_stack2(self.stack, watershed)

        probabilities = probabilities.astype(numpy.double)
        num_channels = 1
        if self.single_channel:
            probabilities = morpho.pad(probabilities, 0)
            neuroproof.add_prediction_channel2(self.stack, probabilities)
        else:
            num_channels = probabilities.shape[probabilities.ndim-1]
            for channel in range(0,num_channels):
                curr_prob = morpho.pad(probabilities[...,channel], 0)
                neuroproof.add_prediction_channel2(self.stack, curr_prob)
github janelia-flyem / gala / gala / agglo.py View on Github external
Exclusions work as follows: the volume `excl` is the same
            shape as the initial segmentation (see ``set_watershed``),
            and consists of mostly 0s. Any voxels with *the same*
            non-zero label will not be allowed to merge during
            agglomeration (provided they were not merged in the initial
            segmentation).

            This allows manual separation *a priori* of difficult-to-
            -segment regions.

        Returns
        -------
        None
        """
        if excl.size != 0:
            excl = morpho.pad(excl, [0]*self.pad_thickness)
        for n in self.nodes():
            if excl.size != 0:
                eids = unique(excl.ravel()[self.extent(n)])
                eids = eids[flatnonzero(eids)]
                self.node[n]['exclusions'] = set(list(eids))
            else:
                self.node[n]['exclusions'] = set()
github janelia-flyem / gala / gala / agglo.py View on Github external
Returns
        -------
        None
        """
        ws = ws.astype(label_dtype)
        try:
            self.boundary_body = np.max(ws) + 1
        except ValueError: # empty watershed given
            self.boundary_body = 1
        self.volume_size = ws.size
        if ws.size > 0:
            ws, _, inv = relabel_sequential(ws)
            self.inverse_watershed_map = inv  # translates to original labels
            self.forward_map = dict(zip(inv, np.arange(inv.size)))
        self.watershed = morpho.pad(ws, self.boundary_body)
        self.watershed_r = self.watershed.ravel()
        self.pad_thickness = 1
        self.steps = morpho.raveled_steps_to_neighbors(self.watershed.shape,
                                                       connectivity)
github janelia-flyem / gala / gala / stack_np.py View on Github external
def init_build(self, watershed, probabilities):
        watershed = morpho.pad(watershed, 0)
        watershed = watershed.astype(numpy.double)    

        neuroproof.reinit_stack(self.stack, watershed)

        probabilities = probabilities.astype(numpy.double)
        num_channels = 1
        if self.single_channel:
            probabilities = morpho.pad(probabilities, 0)
            neuroproof.add_prediction_channel(self.stack, probabilities)
        else:
            num_channels = probabilities.shape[probabilities.ndim-1]
            for channel in range(0,num_channels):
                curr_prob = morpho.pad(probabilities[...,channel], 0)
                neuroproof.add_prediction_channel(self.stack, curr_prob)
github janelia-flyem / gala / gala / stack_np.py View on Github external
def init_build2(self, watershed, probabilities):
        watershed = morpho.pad(watershed, 0)
        watershed = watershed.astype(numpy.double)    

        neuroproof.reinit_stack2(self.stack, watershed)

        probabilities = probabilities.astype(numpy.double)
        num_channels = 1
        if self.single_channel:
            probabilities = morpho.pad(probabilities, 0)
            neuroproof.add_prediction_channel2(self.stack, probabilities)
        else:
            num_channels = probabilities.shape[probabilities.ndim-1]
            for channel in range(0,num_channels):
                curr_prob = morpho.pad(probabilities[...,channel], 0)
                neuroproof.add_prediction_channel2(self.stack, curr_prob)