Two appraoches for separating individual instances in case of overlapping segmentation. The approaches assume a symmetry in shape, as such can be useful for separating merged objects such as trees and cells.
This approach first finds the object centers, and then relabels the image based upon weighted distance to these centers. So, if a given blob contains multiple centers, then it will be divide into various instances accordingly. Current implementation adds a large penalty for not-in-sight centers, and additionally performs majority filtering to remove the lone-pixels.
In this approach, we erode the image at multiple levels and store that new instances that merge in the process. For example, if a given blob were two split into multiple instances during erosion, we will store them as new instances and continue the process.
In this approach, we work on individual polygons instead of large rasters. At the core, this approach uses either 1a or 1b. The main advantage is that it can be optimized for the end task directly, e.g. if you are only interested in the center of the tree and it's area.
- Clone repo
git clone git@github.com:ankitkariryaa/seperate_trees.git
- Change your current working directory to the github repo
cd seperate_trees
- Install dependencies
conda env create -f environment.yml
- Activate environment
conda activate separate-trees
- Run the scripts
or
python -m src.center_separation -h
python -m src.polygon_separation -i ./sample_vectorfiles -ft gpkg -p small --cpu 1 -oaa true -crd ./sample_images -crt tif
Predicted centers and pixel labels using center based separation technique (approach 1).
In this image the centers were found in 108ms and the labels were found in 52 seconds on 1 core (single thread), and 24 seconds on 4 CPU cores.
Predicted pixel labels using erosion based separation technique (approach 2).
In this image the labels were found in 84.8 seconds on 4 CPU cores. The instances were eroded at [3,8,15] pixels from the boundary. A more granual erosion example [2,5,8,11,14,17] might lead to finer results but it will be slower.
- Approach 1 (center based separation) can in somecases lead to lone pixels. It usually happens when the closest/expected center is not in sight.
- Extremely slow processing with certain large images. I am still debugging this issue.