Tracking with R
The paper describes a two-step procedure that joins objects from one frame to
the next, then joins the starts and ends of runs of objects to ends, starts
and middles of other joins to correct errors caused by gaps in segmentations
and to track merging and splitting events. At the heart of it is a
linear assignment
problem solver which optimizes the possible choices over an entire image
(in the first pass) or the entire movie (in the second pass). The algorithm
takes both object velocities and historical variance into account (using a
Kalman filter). The
method looks promising.
Viewing tracking data in R

I love
R. It's a spectacular
example of the best of open-source programming. The underpinnings are
computationally elegant, you can do a lot of mathematics with very
little typing and the user community is enormous - R is now an
"everything but the kitchen sink" project. You'll find what you are looking
for; someone has done it for you.
The picture above is a static image of an OpenGL graphing package for R:
RGL. As with most
OpenGL stuff, the image without the interaction doesn't do it justice. You
can easily rotate and zoom and explore your data. The above is a rendering
of the tracking of a movie as calculated by CellProfiler's TrackObjects.
Each color represents a track with the z-axis being time. If you have R,
you can do this yourself with tracking data from CellProfiler. Probably,
the best idea is to save one data file per movie; this makes the R code
exceptionally easy:
- Run CellProfiler and output the object data to a .csv file using
ExportToSpreadsheet. The X and Y positions of your objects
are in the Location_Center_X and Location_Center_Y
columns and the assignments made by TrackObjects into
a column with a name like TrackObjects_Label_50 (yours
is likely to have a different number at the end, depending on
parameters you've used).
- Install RGL: it's available for download from the Packages / Install Package(s)
menu in the GUI.
library("rgl")
data = read.csv("tracking.csv", sep=",")
This loads the CellProfiler data into an R data frame. Just so simple.
plot3d(data$Location_Center_X, data$Location_Center_Y, data$ImageNumber, col=data$TrackObjects_Label_50)
This plots the tracks in 3-d for you. data$ImageNumber is the z-height of the
3-d display so Z = time. col=data$TrackObjects_Label_50 assigns a color to
each object based on the label given by the TrackObjects module.
Accessing tracks from the database
You can access track data from the database from R. You need some
sort of database connection. I've tried RMySQL which didn't work for me and RODBC
which did (but you have to set up an ODBC data source to the database). For RODBC,
the following gets you a channel object:
| > library('RODBC') |
| > conn=odbcConnect('my-dsn') |
| > sqlQuery(conn,'use my-database') |
After this, you can fetch the data for one of your tracks. Each image set
in a track has the same group number and they are ordered by group index. You
can join your image table to your object table through ImageNumber. Here's a
possible script:
| > stmt = "select i.Image_Metadata_Plate, i.Image_Metadata_Well,
i.Image_Group_Index, s.* from my-image-table i join
my-object-table s on i.ImageNumber = s.ImageNumber
where i.Group_Number = group-number" |
| > data = sqlQuery(conn, stmt) |
| > plot3d(data$my-object-name_Location_Center_X,
data$my-object-name_Location_Center_Y, data$Image_Group_Index,
col=data$my-object-name_TrackObjects_Label,
main=paste("Plate=",data$Image_MetadataPlate,"Well=",data$Image_MetadataWell)) |