## ----setup, include = FALSE--------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(thinr) ## ----------------------------------------------------------------------------- # A 'V' shape — exercises diagonal preservation make_v <- function() { m <- matrix(0L, 11, 11) for (k in seq(0, 5)) { m[2 + k, 2 + k] <- 1L m[2 + k, 10 - k] <- 1L m[3 + k, 2 + k] <- 1L m[3 + k, 10 - k] <- 1L } m } v <- make_v() v ## ----------------------------------------------------------------------------- thin(v, method = "zhang_suen") ## ----------------------------------------------------------------------------- thin(v, method = "guo_hall") ## ----------------------------------------------------------------------------- thin(v, method = "hilditch") ## ----------------------------------------------------------------------------- thin(v, method = "k3m") ## ----------------------------------------------------------------------------- thin(v, method = "holt") ## ----------------------------------------------------------------------------- m <- matrix(0L, 9, 11) m[3:7, 3:9] <- 1L # 5x7 solid rectangle medial_axis(m) ## ----------------------------------------------------------------------------- result <- medial_axis(m, return_distance = TRUE) result$skeleton round(result$distance, 3) ## ----------------------------------------------------------------------------- m <- matrix(1L, 5, 5) m[1, 1] <- 0L distance_transform(m, metric = "manhattan") distance_transform(m, metric = "chessboard") round(distance_transform(m, metric = "euclidean"), 3) ## ----eval = FALSE------------------------------------------------------------- # library(bench) # m <- matrix(0L, 200, 200) # m[50:150, 50:150] <- 1L # solid square # # bench::mark( # zs = thin(m, method = "zhang_suen"), # gh = thin(m, method = "guo_hall"), # hild = thin(m, method = "hilditch"), # k3m = thin(m, method = "k3m"), # ma = medial_axis(m), # dt_eucl = distance_transform(m, metric = "euclidean"), # iterations = 5, # check = FALSE # )