Read frame from a ufmf format movie

read.ufmf(x, framei = NULL, return.boxes = FALSE)

Arguments

x

Either a path to a file on disk, a connection or a parsed ufmf header object (as returned by read.ufmf.header)

framei

Integer index of the frame to read

return.boxes

Whether to return an matrix describing the position of pixels that differ from the mean image (see details, default FALSE).

Value

An array/matrix containing the image data with the frame timestamp and (optionally) boxes as attributes. MONO8 data will be returned as width x height matrix, while RGB8 data will be a width x height x 3 array.

Details

When reading multiple frames, the recommended idiom is to read the header and store it in an object, then pass that object to read.ufmf along with the integer index of the required frame. See examples.

When present, bounding boxes for foreground pixels are returned in an N x 4 matrix where the four columns specify (x, y, width , height).

See also

connection, read.ufmf.header

Examples

# NOT RUN {
h=read.ufmf.header("movie.ufmf")
frames=lapply(1:5, function(i) read.ufmf(h, i))

## Show foreground boxes
f5=read.ufmf(h, 5, return.boxes=TRUE)
# plot image with integer pixel indices for x and y axes (rather than 0-1)
image(1:nrow(f5), 1:ncol(f5), f5, useRaster = T)
bb=attr(f5, "boxes")
# plot rectangles for foreground boxes
rect(bb[,1], bb[,2], bb[,1]+bb[,3], bb[,2]+bb[,4])
# }