Learn R Programming

BioTrajectory (version 1.1.0)

getTrajectory: Get Object Trajectory from Image Sequence

Description

This function calculates the trajectory of an object in a sequence of images. It compares each frame to a background image to detect movement. The function identifies the largest object in each frame and calculates its centroid coordinates across the sequence.

Usage

getTrajectory(listImages, Barnes, iBackground, iBegin, iEnd)

Value

An object of class `trayectoria` containing the points (coordinates) of the object in each frame. The `trayectoria` object will include the `x` and `y` coordinates. If no object is detected in a frame, the corresponding coordinates will be set to `NA` in the `trayectoria` object.

Arguments

listImages

A vector of file paths to the images in the sequence.

Barnes

A parameter used by the `removeBackground()` function to remove background noise.

iBackground

An index indicating which image from the sequence is used as the background.

iBegin

An index specifying the first image in the sequence to start tracking.

iEnd

An index specifying the last image in the sequence to track.

Details

The function reads the images from `listImages` and compares each frame to the background image specified by `iBackground`. Background subtraction is performed using the `removeBackground()` function, followed by thresholding to identify significant changes between the background and the current frame. The largest connected component in the thresholded image is assumed to be the object of interest, and its centroid is calculated.

Instead of directly returning the centroid coordinates, the function now creates an object of class `trayectoria` to store the calculated centroids. The coordinates of the object in each frame are added to the `trayectoria` object. If no object is detected in a frame, the corresponding coordinates are set to `NA`. The resulting `trayectoria` object is returned, which allows users to further manipulate and analyze the trajectory of the object across frames.

The returned `trayectoria` object contains methods for extracting and analyzing the coordinates, making it easier to track the object over time.

Examples

Run this code
# \donttest{
# Not run:
path <- system.file('extdata/frames', package='BioTrajectory')
images <- list.files(path, full.names = TRUE)
B  <- list(c1 = structure(list(x = 342L, y = 263L), row.names = 1L, class = "data.frame"),
    boardRadius = 207, c2 = structure(list(x = c(157L, 172L, 202L, 245L,
    297L, 352L, 408L, 455L, 494L, 517L, 522L, 507L, 476L, 430L,
    375L, 318L, 262L, 215L, 180L, 160L), y = c(242L, 188L, 141L,
    105L, 85L, 80L, 93L, 124L, 166L, 219L, 277L, 334L, 383L,
    420L, 440L, 442L, 426L, 394L, 350L, 298L), class = "data.frame")), holeRadius = 13)

trajectory <- getTrajectory(images, B, 1, 1, 2)
print(trajectory) 
# }

Run the code above in your browser using DataLab