Detect Skeleton Points: Branching Points and Endpoints
Source:R/Thinning4.R
detect_skeleton_points.Rd
Identifies the branching points and endpoints of a skeletonized binary image.
Value
A named list containing two `SpatRaster` objects:
endpoints
: A binary raster where endpoints are marked as1
.branching_points
: A binary raster where branching points are marked as1
.
Details
This function detects key points in a skeletonized binary image:
Endpoints: Pixels with exactly one neighbor in the skeleton.
Branching Points: Pixels with more than two neighbors in the skeleton.
The function uses a 3x3 neighborhood kernel to count the number of neighbors for each foreground pixel (1
) in the image. Based on the neighbor count, points are classified as endpoints or branching points.
The input image should be skeletonized (thin and connected) before using this function. If not already binary, the input image will be binarized internally.
Examples
if (FALSE) { # \dontrun{
library(terra)
# Example skeletonized image
skeleton <- rast(matrix(c(0, 1, 1, 0, 0, 1, 1, 0), nrow = 4))
# Detect endpoints and branching points
points <- detect_skeleton_points(skeleton)
# Access results
endpoints <- points$endpoints
branching_points <- points$branching_points
} # }