How to use the gala.morpho 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_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 / gala / stack_np.py View on Github external
def build_border(self, supervoxels1, prediction1, supervoxels2,
            prediction2, mask1, mask2, reset_edges):
        self.init_build(supervoxels1, prediction1)
        self.init_build2(supervoxels2, prediction2)

        if mask1 is not None and mask2 is not None:
            mask1 = morpho.pad(mask1, 0)
            mask1 = mask1.astype(numpy.double)    
            mask2 = morpho.pad(mask2, 0)
            mask2 = mask2.astype(numpy.double)    
            # use masks to handle 0 cases 
            neuroproof.init_masks(self.stack, mask1, mask2)
        
        self.stack.build_rag_border(reset_edges)
github janelia-flyem / gala / gala / imio.py View on Github external
def remove_small(a):
        return morpho.remove_small_connected_components(a, min_size)
    mplanes = map(remove_small, nd_map)
github janelia-flyem / gala / gala / imio.py View on Github external
if not os.path.exists(sp_path): 
        os.mkdir(sp_path)
    write_png_image_stack(sps, os.path.join(sp_path, 'sp_map.%05i.png'),
        bitdepth=16, axis=0)

    # write grayscale
    if gray is not None:
        if not os.path.exists(im_path): 
            os.mkdir(im_path)
        write_png_image_stack(gray, 
                              os.path.join(im_path, 'img.%05d.png'), axis=0)

    # body annotations
    if body_annot is not None:
        if type(body_annot) == ndarray:
            orphans = morpho.orphans(body_annot)
            non_traversing = morpho.non_traversing_segments(body_annot)
            body_annot = raveler_body_annotations(orphans, non_traversing)
        write_json(body_annot, os.path.join(directory, 'annotations-body.json'))

    # make tiles, bounding boxes, and contours, and compile HDF5 stack info.
    with tmp.TemporaryFile() as tmp_stdout:
        try: 
            def call(arglist):
                return subprocess.call(arglist, stdout=tmp_stdout)
            r1 = call(['createtiles', im_path, sp_path, tile_path])
            r2 = call(['bounds', directory])
            r3 = call(['compilestack', directory])
        except:
            logging.warning(
                'Error during Raveler export post-processing step. ' +
                'Possible causes are that you do not have Raveler installed ' +
github janelia-flyem / gala / gala / segmentation_stitch.py View on Github external
prediction_vol[lowerb[0]:upperb[0],lowerb[1]:upperb[1],50:100] = prediction_vol_temp
        
        prediction2[lowerb[0]:upperb[0],lowerb[1]:upperb[1]] = b2_prediction_temp 
        supervoxels2[lowerb[0]:upperb[0],lowerb[1]:upperb[1]] = b2_seg_temp 

        master_logger.info("Examining border between " + block1["segmentation-file"] + " and " + block2["segmentation-file"])
       
        mask1 = None
        mask2 = None

        if options.run_watershed:
            # generate watershed as in gala main flow over thick boundary stuff
            master_logger.info("Generating watershed in boundary region")
            boundary_vol = prediction_vol[...,0]
            seeds = label(boundary_vol==0)[0]
            seeds = morpho.remove_small_connected_components(seeds, 5)
            supervoxels = skmorph.watershed(boundary_vol, seeds)
            master_logger.info("Finished generating watershed in boundary region")
            
            # generate thick boundary in neuroproof and return volume
            supervoxels = agglom_stack.dilate_edges(supervoxels) 

            # grab inner 2 slices and mask supervoxels (ignore if one 0) 
            # OR increase edge size to 0 when one is 0
            mask1 = supervoxels[:,:,49:50]
            mask2 = supervoxels[:,:,50:51]

            if not firstblock_first:
                mask2 = supervoxels[:,:,49:50]
                mask1 = supervoxels[:,:,50:51]

        # special build mode
github janelia-flyem / gala / gala / agglo.py View on Github external
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 / imio.py View on Github external
os.mkdir(sp_path)
    write_png_image_stack(sps, os.path.join(sp_path, 'sp_map.%05i.png'),
        bitdepth=16, axis=0)

    # write grayscale
    if gray is not None:
        if not os.path.exists(im_path): 
            os.mkdir(im_path)
        write_png_image_stack(gray, 
                              os.path.join(im_path, 'img.%05d.png'), axis=0)

    # body annotations
    if body_annot is not None:
        if type(body_annot) == ndarray:
            orphans = morpho.orphans(body_annot)
            non_traversing = morpho.non_traversing_segments(body_annot)
            body_annot = raveler_body_annotations(orphans, non_traversing)
        write_json(body_annot, os.path.join(directory, 'annotations-body.json'))

    # make tiles, bounding boxes, and contours, and compile HDF5 stack info.
    with tmp.TemporaryFile() as tmp_stdout:
        try: 
            def call(arglist):
                return subprocess.call(arglist, stdout=tmp_stdout)
            r1 = call(['createtiles', im_path, sp_path, tile_path])
            r2 = call(['bounds', directory])
            r3 = call(['compilestack', directory])
        except:
            logging.warning(
                'Error during Raveler export post-processing step. ' +
                'Possible causes are that you do not have Raveler installed ' +
                'or you did not specify the correct installation path.')