getTrajectory: Get Object Trajectory from Image Sequence

View source: R/getTrajectory.R

getTrajectoryR Documentation

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)

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. The trajectory is tracked across frames, and the centroid coordinates are returned for each frame.

Value

A data frame with two columns: the x and y coordinates of the object centroid in each frame. If no object is detected in a frame, the coordinates are set to 'NA'.

Examples

 
 # 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"),
    r1 = 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"), r2 = 13))
 trajectory <- getTrajectory(images, B, 1, 1, 1)
 print(trajectory) 
 


BioTrajectory documentation built on June 8, 2025, 11:54 a.m.