How to use the gala.morpho.watershed 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 / test / test_gala.py View on Github external
def test_watershed_seeded_nodams(self):
        seeds_bool = self.landscape==0
        seeded_nodam_ws_result = numpy.array([1,1,1,1,1,1,2,2,2,3,3,3])
        seeded_nodam_ws = morpho.watershed(self.landscape,
                    seeds=seeds_bool, override_skimage=True, dams=False)
        self.assertTrue((seeded_nodam_ws == seeded_nodam_ws_result).all())
github janelia-flyem / gala / tests / test_watershed.py View on Github external
def test_watershed_saddle_basin():
    saddle_landscape = np.array([[0,0,3],[2,1,2],[0,0,3]])
    saddle_result = np.array([[1,1,1],[0,0,0],[2,2,2]])
    saddle_ws = morpho.watershed(saddle_landscape, dams=True)
    assert_array_equal(saddle_ws, saddle_result)
github janelia-flyem / gala / test / test_gala.py View on Github external
def test_watershed(self):
        regular_watershed_result = numpy.array([1,1,1,0,2,0,3,3,3,0,4,4])
        regular_watershed = morpho.watershed(self.landscape, dams=True)
        self.assertTrue((regular_watershed == regular_watershed_result).all())
github janelia-flyem / gala / tests / test_watershed.py View on Github external
def test_watershed_plateau_performance():
    """Test time taken by watershed on plateaus is acceptable.
    
    Versions prior to 2d319e performed redundant computations in the
    idxs_adjacent_to_labels queue which resulted in an explosion in 
    runtime on plateaus. This test checks against that behavior.
    """
    plat = np.ones((11,11))
    plat[5,5] = 0
    timed_watershed = time_me(morpho.watershed)
    time_taken = timed_watershed(plat)[1]
    assert_array_less(time_taken, 100, 'watershed plateau too slow')
github janelia-flyem / gala / test / test_gala.py View on Github external
def test_watershed_plateau_performance(self):
        """Test time taken by watershed on plateaus is acceptable.
        
        Versions prior to 2d319e performed redundant computations in the
        idxs_adjacent_to_labels queue which resulted in an explosion in 
        runtime on plateaus. This test checks against that behavior.
        """
        plat = numpy.ones((11,11))
        plat[5,5] = 0
        tws = time_me(morpho.watershed)
        self.assertTrue(tws(plat) < 100)
github janelia-flyem / gala / tests / test_watershed.py View on Github external
def test_watershed_seeded():
    seeds_bool = (landscape == 0)
    seeds_unique = nd.label(seeds_bool)[0]
    seeded_watershed_result = np.array([1,1,1,1,1,0,2,2,2,0,3,3])
    seeded_watershed1 = morpho.watershed(landscape, seeds_bool, dams=True)
    seeded_watershed2 = morpho.watershed(landscape, seeds_unique, dams=True)
    assert_array_equal(seeded_watershed1, seeded_watershed_result)
    assert_array_equal(seeded_watershed2, seeded_watershed_result)
github janelia-flyem / gala / test / test_gala.py View on Github external
def test_watershed_seeded(self):
        seeds_bool = self.landscape==0
        seeds_unique = label(seeds_bool)[0]
        seeded_watershed_result = numpy.array([1,1,1,1,1,0,2,2,2,0,3,3])
        seeded_watershed1 = \
            morpho.watershed(self.landscape, seeds_bool, dams=True)
        seeded_watershed2 = \
            morpho.watershed(self.landscape, seeds_unique, dams=True)
        self.assertTrue((seeded_watershed1 == seeded_watershed_result).all())
        self.assertTrue((seeded_watershed2 == seeded_watershed_result).all())
github janelia-flyem / gala / test / test_gala.py View on Github external
def test_watershed_images(self):
        wss = [morpho.watershed(self.probs[i], dams=True) for i in range(3)] + \
            [morpho.watershed(self.probs[3], dams=False)]
        for i in range(self.num_tests):
            self.assertTrue((wss[i]==self.results[i]).all(),
                                    'Watershed test number %i failed.'%(i+1))
github janelia-flyem / gala / tests / test_watershed.py View on Github external
def test_watershed_images():
    wss = [morpho.watershed(probs[i], dams=(i == 0)) for i in range(2)]
    for i, (ws, res) in enumerate(zip(wss, results)):
        yield (assert_array_equal, ws, res,
               'Image watershed test %i failed.' % i)
github janelia-flyem / gala / gala / imio.py View on Github external
start_plane = sp2seg_list[:,0].min()
    for z, sp, seg in sp2seg_list:
        if z not in sp2seg:
            sp2seg[z] = zeros(max_sp+1, uint32)
        sp2seg[z][sp] = seg
    max_seg = seg2bod_list[:,0].max()
    seg2bod = zeros(max_seg+1, uint32)
    seg2bod[seg2bod_list[:,0]] = seg2bod_list[:,1]
    initial_output_volume = zeros_like(spmap)
    for i, m in enumerate(spmap):
        j = start_plane + i
        initial_output_volume[i] = seg2bod[sp2seg[j][m]]
    if use_watershed:
        probs = np.ones_like(spmap) if probability_map is None \
                                    else probability_map
        output_volume = morpho.watershed(probs, seeds=initial_output_volume)
    else:
        output_volume = initial_output_volume
    if (output_volume[:, 0, 0] == 0).all() and \
                        (output_volume == 0).sum() == output_volume.shape[0]:
        output_volume[:, 0, 0] = output_volume[:, 0, 1]
    if get_glia:
        annots = json.load(
            open(os.path.join(rav_export_dir, 'annotations-body.json'), 'r'))
        glia = [a['body ID'] for a in annots['data'] 
                                        if a.get('comment', None) == 'glia']
        return output_volume, glia
    else:
        return output_volume