[R-sig-Geo] Skeletonize, distmap, medial axis transform

Andrew Niccolai andrew.niccolai at yale.edu
Mon Apr 21 22:23:32 CEST 2008


Greetings list.
Below is some code that anyone can run to produce a distance transform image
of the R logo.  I am interested in some code that will skeletonize this
distmap image or the equivalent SpatialGridDataFrame object.  Essentially I
need to find the ridgeline of the distance transform that would in theory
trace the R logo image at all locations that are the maximum distance from
the boundaries.  Any help would be greatly appreciated.  I have also read of
a way to skeletonize a set of discrete boundary points using Voronoi
tessellation and then thinning the lines but I think the medial axis
transform of the distance map will be easier to handle.  Thanks again for
any and all help!

## Code to produce distance transform image (and SGDF) of R logo.
.spatstat_check <- FALSE # this is the trick used to pass FALSE to check=
w2 <- letterR
plot(w2)
m <- complement.owin(w2)
rm(.spatstat_check)
p1 <- as.psp(w2)
plot(p1)
d <- distmap(p1)
summary(d)
plot(d)
plot(w2, add=TRUE)
d[m] <- NA
summary(d)
plot(d)
## Convert to SpatialGridDataFrame if this helps
dsgdf <- as.SpatialGridDataFrame.im(d)
image(dsgdf)





Andrew Niccolai
Doctoral Candidate
Yale School of Forestry




More information about the R-sig-Geo mailing list