patch¶
- treesegmentation.patch.compute_patch_neighbors(grid, labeled_grid, all_patches)¶
Determine the neighbors of a given labeled patch feature in the 2-D discretized grid. These neighbors will be used to build the directed Hierarchy graph in the hierarchy building step
- Parameters
grid – The discretized grid
labeled_grid – The grid labeled with patch features
all_patches – A list of all the Patch objects
- Returns
None
- treesegmentation.patch.compute_patches(grid, discretization, min_height, neighbor_mask=None)¶
Compute patches by height level in the discretized grid. For every height level that we want to examine in the interval [min_height, discretization], find all the patches in that height level and add them to all_patches array.
- Parameters
grid – The discretized grid
discretization – The number of discrete intervals used to create grid
min_height – The minimum height level that we want to create patches for
- Neighbor_mask
The 3x3 adjacency matrix used to determine 4-way or 8-way adjacency.
- Returns
all_patches, a list of patches in the grid
- treesegmentation.patch.create_labeled_grid(grid, all_patches)¶
Label the grid by unique Patch IDs. This is used to create a Patch raster if specified by the user.
- Parameters
grid – The discretized grid
all_patches – A list of all the Patch objects
- Returns
labeled_grid, a grid labeled by unique Patch IDs
- treesegmentation.patch.find_patches_of_height(grid, height_level, neighbor_mask=None)¶
For a given height level, find all features of that match that height level and create a patch for each unique feature. This function is called by compute patches as a helper function.
- Parameters
grid – The discretized grid
height_level – The height level we are interested in finding patches for
- Neighbor mask
The 3x3 adjacency matrix used to determine 4-way or 8-way adjacency.
- Returns
A list of Patch objects for a given height level (if any exist)
- treesegmentation.patch.patches_to_dict(all_patches)¶
Converts the all_patches array to a dictionary. This is used in the weighted graph and partitioning steps for quick lookup of a Patch. The keys are the Patch ID and the values are the Patch objects associated with that ID.
- Parameters
all_patches – The list of Patch object created by compute_patches
- Returns
patch_dict, a dictionary of patches