[R] 3d line smoothing

Gregory Jefferis gsxej2 at cam.ac.uk
Mon Mar 31 22:46:21 CEST 2008


Dear R People,

I would like to smooth some 3d lines, which consist of line segments
specified by start and end 3d coordinates.  These are experimentally derived
from microscope images of neurons, so there is no sense in which one axis is
any different from any other (predictor vs response).

I have tried doing repeated smoothing interpolation with smooth.splines (see
below), but this doesn't behave that well with some of my data which can be
multivalued with respect to x and is not a directly 3d approach since.

Could anyone suggest a package which might have appropriate functionality or
a link to read up about possible approaches?

With many thanks for your help,

Greg Jefferis.

PS As an aside, wouldn't categorising the 1350 downloadable packages on CRAN
according to their content make a nice exercise in applied statistical
learning/visualisation?

--

LineSmooth3d<-function(l){
    lxy=smooth.spline(l[,1:2])
    lxz=smooth.spline(l[,c(1,3)])
    cbind(l[,1],predict(lxy,l[,1])$y,predict(lxz,l[,1])$y)
}

# First 2 segments of a neuron
l=structure(c(2.240391, 5.629143, 8.140456, 9.94432, 12.295891,
13.457473, 15.170222, 17.758942, 18.290545, 20.334337, 22.027239,
23.263636, 24.24404, 26.234032, 27.411226, 29.369003, 30.806803,
32.68042, 35.012493, 37.436077, 40.567665, 46.615963, 49.906017,
57.803772, 62.236923, 63.849625, 131.309967, 129.133469, 127.194168,
125.517822, 123.464272, 121.037727, 118.98951, 116.41317, 114.511192,
111.733353, 108.64267, 106.416183, 103.347008, 100.653694, 98.72525,
96.918602, 95.4189, 94.231995, 92.493828, 91.070656, 88.901505,
86.535431, 86.055229, 86.209984, 86.143341, 86.368622, 9.116494,
10.510942, 12.17625, 14.124721, 17.23107, 21.285524, 24.150547,
26.97097, 29.702291, 32.635288, 35.791851, 39.013748, 41.252228,
42.638962, 44.100445, 45.742134, 47.191525, 49.838848, 51.361511,
52.929546, 55.789406, 60.742428, 61.489536, 60.880463, 61.653023,
61.472942), .Dim = c(26L, 3L), .Dimnames = list(NULL, c("X", "Y", "Z")))

l2=structure(list(X = c(63.849625, 63.710838, 64.202766, 64.650017,
64.965698, 64.609695, 64.352356), Y = c(86.368622, 83.420357,
80.972359, 79.352409, 77.604141, 76.094627, 74.800072), Z = c(61.472942,
62.381229, 62.161339, 63.138336, 64.076202, 65.080811, 68.487137
)), .Names = c("X", "Y", "Z"), row.names = c("26", "27", "28",
"29", "30", "31", "32"), class = "data.frame")

# install.packages('rgl')
require(rgl)
# First line OK
rgl.linestrips(l)
rgl.linestrips(LineSmooth3d(l),col='red')
# second line not so good
rgl.linestrips(l2)
rgl.linestrips(LineSmooth3d(l2),col='red')

-- 
Gregory Jefferis, PhD                                   and:
Research Fellow    
Department of Zoology                                   St John's College
University of Cambridge                                 Cambridge
Downing Street                                          CB2 1TP
Cambridge, CB2 3EJ 
United Kingdom

Lab Tel: +44 (0)1223 336683                     Office: +44 (0)1223 339899
Lab Fax: +44 (0)1223 336676

gsxej2 at cam.ac.uk
http://www.zoo.cam.ac.uk/zoostaff/jefferis.html
http://www.neuroscience.cam.ac.uk/directory/profile.php?gsxej2
http://flybrain.stanford.edu



More information about the R-help mailing list