Skip to contents

Given an object of class "tracklets" containing a list of tracklets, this function returns a list of resampled tracklets according to the length of the resampling step specified by the Tstep argument.

Usage

resampTracklets(trackDat, timeCol = "frame", Tstep = NULL, progress = TRUE)

Arguments

timeCol

A character string corresponding to the name of the column containing time information (default = 'frame').

Tstep

A numeric value corresponding to the length of the resampling step according to the time unit used in timeCol (e.g., frame).

progress

A logical value (i.e., TRUE or FALSE) indicating whether a progress bar should be displayed to inform process progression (default = TRUE).

trackDatA

An object of class "tracklets" containing a list of tracklets and their characteristics classically used for further computations (at least x.pos, y.pos, frame).

Value

An object of class "tracklets" containing the resampled tracklets.

Author

Quentin PETITJEAN

Examples


set.seed(2023)
# generate some dummy tracklets
## start to specify some parameters to generate tracklets
trackN <- 50 # the number of tracklets to simulate
trackL <-
  100:1000 # the length of the tracklets or a sequence to randomly sample tracklets length

trackList <- MoveR::trackletsClass(stats::setNames(lapply(lapply(seq(trackN), function(i)
  trajr::TrajGenerate(sample(trackL, 1), random = TRUE, fps = 1)), function(j)
    data.frame(
      x.pos = j$x - min(j$x),
      y.pos = j$y - min(j$y),
      frame = j$time
    )), seq(trackN)))

# check the tracklets
MoveR::drawTracklets(trackList,
                 timeCol = "frame")


# convert the time unit (frame) to seconds using analyseTracklets (according to a frame rate of 25 fps)
trackListV1 <-
  MoveR::analyseTracklets(trackList,
                      customFunc = list(
                        # convert the time expressed in frame in second using a conversion factor of 25 frame per second
                        TimeSec = function(x)
                          x[["frame"]] / 25
                      ))
# resample the tracklets every 1 seconds
## check the size of the tracklets
trackSize <- unlist(lapply(trackListV1, function(x)
  nrow(x)))

## resample the tracklets every 1 seconds
trackListSampled1S <- MoveR::resampTracklets(trackListV1,
                                           timeCol = "TimeSec",
                                           Tstep = 1)

## check the size of the tracklets after resampling
trackSize1s <- unlist(lapply(trackListSampled1S, function(x)
  nrow(x)))

## Compare the tracklets size
cbind(trackSize, trackSize1s)
#>    trackSize trackSize1s
#> 1        985          40
#> 2        334          14
#> 3        648          26
#> 4        109           5
#> 5        872          35
#> 6        613          25
#> 7        215           9
#> 8        640          26
#> 9        876          36
#> 10       982          40
#> 11       223           9
#> 12       679          28
#> 13       720          29
#> 14       491          20
#> 15       670          27
#> 16       848          34
#> 17       425          17
#> 18       810          33
#> 19       649          26
#> 20       180           8
#> 21       509          21
#> 22       186           8
#> 23       275          11
#> 24       987          40
#> 25       254          11
#> 26       486          20
#> 27       615          25
#> 28       889          36
#> 29       320          13
#> 30       450          18
#> 31       721          29
#> 32       974          39
#> 33       908          37
#> 34       780          32
#> 35       497          20
#> 36       316          13
#> 37       228          10
#> 38       865          35
#> 39       348          14
#> 40       184           8
#> 41       989          40
#> 42       715          29
#> 43       373          15
#> 44       194           8
#> 45       849          34
#> 46       717          29
#> 47       603          25
#> 48       119           5
#> 49       577          24
#> 50       147           6