Example #1
0
    def get_islands(self, props=['area', 'maxwidth', 'major_axis_length',
                                 'minor_axis_length', 'surrounding_links'],
                          connectivity=2):
        """
        Finds all the islands in the binary mask and computes their morphological
        properties. Can be used to help "clean" masks of small islands. Must
        run compute_network() first.

        Parameters
        ----------
        props : list, optional
            Properties to compute for each island. Properties can be any of those
            provided by rivgraph.im_utils.regionprops.
            The default is ['area', 'maxwidth', 'major_axis_length', 'minor_axis_length'].
        connectivity : int, optional
            If 1, 4-connectivity will be used to determine connected blobs. If
            2, 8-connectivity will be used. The default is 2.

        Returns
        -------
        islands : geopandas GeoDataFrame
             Contains the polygons of each island with the requested property
             attributes as columns. An additional 'remove' attribute is
             initialized to make thresholding easier.

        """
        do_surr = False
        if 'surrounding_links' in props:
            props.remove('surrounding_links')
            if hasattr(self, 'links') is True:
                do_surr = True
            else:
                logger.info('Cannot compute surrounding island links without first computing the network. Skipping.')

        logger.info('Getting island properties...')

        islands, Iislands = mu.get_island_properties(self.Imask, self.pixlen, self.pixarea, self.crs, self.gt, props, connectivity=connectivity)

        logger.info('got island properties.')

        if do_surr is True:
            if hasattr(self.links, 'wid_adj') is False:
                self.compute_link_width_and_length()

            logger.info('Computing surrounding links for each island...')

            islands = mu.surrounding_link_properties(self.links, self.nodes, self.Imask, islands, Iislands, self.pixlen, self.pixarea)

            logger.info('surrounding links computed.')

        # Add a column to be used for thresholding
        islands['remove'] = [False for i in range(len(islands))]

        return islands, Iislands
 def test_no_props(self, test_net):
     """Test, no island properties."""
     props = []
     gdf, Ilabel = mask_utils.get_island_properties(test_net.Imask,
                                                    test_net.pixlen,
                                                    test_net.pixarea,
                                                    test_net.crs,
                                                    test_net.gt, props)
     # assert image mask size same as labeled image size
     assert Ilabel.shape == test_net.Imask.shape
     # make assertion about gdf shape
     assert np.shape(gdf) == (99, 2)
Example #3
0
 def test_islandprops(self, test_net):
     """Test given island properties."""
     props = ['area', 'major_axis_length', 'minor_axis_length',
              'perim_len', 'convex_area']
     gdf, Ilabel = mask_utils.get_island_properties(test_net.Imask,
                                                    test_net.pixlen,
                                                    test_net.pixarea,
                                                    test_net.crs,
                                                    test_net.gt,
                                                    props)
     # assert image mask size same as labeled image size
     assert Ilabel.shape == test_net.Imask.shape
     # make assertion about gdf shape
     assert np.shape(gdf) == (99, 7)