fin.kin: Tracking of fin-like extensions of body contours

Description Usage Arguments Details Value See Also Examples

View source: R/kin.R

Description

Estimates the amplitudes of regions along a body contour that are protruding. Useful in computing paired-fin amplitudes from contour data produced from kin.simple and kin.search. Also computes a smoothed midline based on the body outline with the fin region removed.

Usage

1
2
3
4
5
6
7
8
9
fin.kin(
  x,
  fin.pos = NULL,
  smooth.n = 50,
  tip.ang = 10,
  smoothing = "loess",
  x.bins = 0.2,
  ml.smooth = 0.25
)

Arguments

x

a data frame or matrix with 'x' and 'y' data as columns.

fin.pos

numeric, a vector of length 2 indicating the start and end of the contour region that contains the fins of interest as a proportion of the body length.

smooth.n

numeric, the number of smoothing operations undertaken by coo_smooth on the contour described by 'x'.

tip.ang

the minimum angle, in degrees, that defines tip of each fin. See Details.

smoothing

character, the midline smoothing method, either 'loess' or 'spline'.

x.bins

numeric, when less than or equal to 1, the proportion of contour coordinates to sample for midline estimation. If greater than 1, the absolute number of equally spaced x values from which to compute the midline. See Details.

ml.smooth

numeric the smoothing value for the midline. If smoothing is set to 'loess', passed to 'span' value for loess. If smoothing is set to 'spline', passed to 'spar' value for smooth.spline

Details

The algorithm assumes a left-right orientation, i.e., the head of the contour is left. If otherwise oriented, contour can be flipped with coo_flipx and coo_flipy after converting contour to class coo.

tip.angle is used to define the tip of the fin, assuming that the tip of the fin is pointed and, for a sufficiently smoothed fin contour, will have contour edges that form the highest angles within the fin region defined by fin.pos. Low values of smooth.n ($<$5) should be avoided if the contour is jagged, perhaps due to digitization.

In addition to fin amplitude and contour extraction, also produces a composite contour of the body minus the fin area described by fin.pos. Fin contours are replaced by a simple linear prediction constructed from the coordinates of the first and last values covered by fin.pos. The result is a straight line between the start and end of each fin. From this composite body contour, a midline prediction is made based on the method indicated by smoothing and number of points indicated by x.bins.

x.bins controls the bin size of x values used to estimate the midline. From these bins, mean x and the range of y is calculated. The midpoint at each mean x is then calculated from the mid point of y. When less then 1, x.bins values approaching 1 may result in poor a midline as x values on one side of the contour may not have corresponding identical values on the other. Values closer to 0 will result in fewer points but a more robust midline. Higher smooth.n values will also result in a more robust midline estimation (but also a loss of contour information).

Value

A list with the following components:

body a data table consisting of x,y coordinates of the body contour

fin a data table describing the contour of the fins consisting of the following:

fin.pts a data table describing fin position consisting of the following:

comp a data table describing the composite contour of the body minus the fins.

midline a data table describing the estimated

See Also

kin.simple, kin.LDA, kin.search, efourier, coo_angle_edges, coo_smooth, loess, smooth.spline

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
###plot pectoral-fin amplitudes of a swimming sunfish
## Not run: 
require(ggplot2)

#download example avi video
f <- "https://github.com/ckenaley/exampledata/blob/master/sunfish_pect.avi?raw=true"
download.file(f,"sunfish.avi")

#extract images with ffmpeg opereations and reduce them to 600 px wide with a filter
filt.red <- " -vf scale=600:-1 " #filter
vid.to.images2(vid.path="sunfish.avi",filt = filt.red) #extract

#number of frames
fr <- length(list.files("images"))
#extract contours and other data
kin <- kin.simple(image.dir = "images",frames=c(1:fr),thr=0.9,ant.per = 0.25)
#fin amplitudes by frame with data.table
fin.pos <- c(0.25,.5)
fin.dat <- kin$cont[, { f <- fin.kin(data.frame(x=x,y=y),fin.pos =fin.pos);
list(amp=f$amp$amp,fin=f$amp$fin,amp.bl=f$amp$amp.bl)},by=list(frame)]
p <- ggplot(dat=fin.dat,aes(x=frame,y=amp,col=fin))+geom_line()+theme_classic(15)
print(p)


## plot body and fin contours of frame 1
cont <- data.frame(x=kin$cont[frame==2,list(x,y)]$x,y=kin$cont[frame==2,list(y)]$y)
fins <- fin.kin(cont,fin.pos =fin.pos,x.bins=100)

#plot body contour and fins 
p <- qplot(data=fins$body,x=x,y=y)+geom_point(data=fins$fin,aes(x,y),col="red",size=3)
p+geom_point(data=fins$fin.pts,aes(x,y,shape=pos))+xlim(c(0,kin$dim[1]))+ylim(c(0,kin$dim[2]))

#plot body contour minus fins and the body midline
p <- qplot(data=fins$comp,x=x,y=y)+geom_point(data=fins$midline,aes(x,ml.pred),col="red",size=2)
p+xlim(c(0,kin$dim[1]))+ylim(c(0,kin$dim[2]))


## End(Not run)

trackter documentation built on April 19, 2021, 1:08 a.m.