Description Usage Arguments Details Value Author(s) References See Also Examples
Filters then amplifies each pixel's time series signal.
1 |
img.list |
A series of images saved in a list. Each list element is a matrix that represents pixel values of an image, the dimensions of which correspond to the rows and columns of the matrix. |
fps |
Sample rate of video in frames per second (FPS). Each list element of |
f.corners |
Corners to use in the filter. Currently only a Butterworth filter is implemented. |
amp |
Scalar to multiply filtered signals by. Defaults to 10. |
n.poles |
Number of poles used in Butterworth filter. Defaults to two. |
type |
Type of filter used in Butterworth filter (i.e. 'low', 'high', 'stop', 'pass'. Defaults to 'pass' if |
This algorithm is based on the landmark study by Wu et. al (2012) though is organized and implemented slightly differently. Namely, this algorithm takes advantage of R functionality instead of the original development language, MATLAB.
If the goal is to amplify subtle time variations in an image (e.g. heartbeat, breathing, volcanic emissions, etc...) choose corner frequencies that contain the desired signal. For example, most adult resting heart rates range between 1 and 1.5 Hz. To amplify these signals, use a filter type of either low
, high
, or pass
. If the goal is to dampen or remove signals, choose appropriate corner frequencies and use a filter type of low
, high
, or stop
. To help choose appropriate corner frequencies, see sig.extract
.
Filtering is accomplished via the apply
function for speed. However, if the dimensions of the images are large (i.e. dim(img.list[[1]])
) or if the number of frames is large (i.e. length(img.list)
), the RAM may fill up and the R session may crash.
List with the same length and element dimensions as img.list
. Each list element contains the amplified version of the original image list.
Alex J.C. Witsil
Wu, Hao-Yu, et al. "Eulerian video magnification for revealing subtle changes in the world." (2012)
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | ##############################
### SYNTHETIC VIDEO INPUTS ###
##############################
## x and y dimension of the frame
dim.x = 64
dim.y = 64
## sample rate in frames per second
fps = 30
## how many seconds does the video last
n.secs =3
## what is the frequency at which the boxed region oscillates
sig.f = 2
## what is the peak amplitude of the signal
sig.peak = 0.2
## size of the boxed region
box.width = 10
box.height = 10
##################################
### VIDEO AMPLIFICATION INPUTS ###
##################################
## how much to amplify the signal by
amp=500
## filter corners -- should contain the signal of interest
f.corners = c(sig.f-0.2, sig.f+0.2)
## number of poles in Butterworth filter
n.poles = 2
## type of filter
type = 'pass'
################################
### GENERATE SYNTHETIC VIDEO ###
################################
## use the inputs to generate an image list (i.e. video)
img.list <- gen.eg.img.list(dim.x, dim.y, fps, n.secs, sig.f, sig.peak, box.width, box.height)
################################
### AMPLIFY THE VIDEO SIGNAL ###
################################
## amplify the video signal
amp.list <- amp.sig(img.list, fps, f.corners, amp, n.poles, type)
################
### PLOTTING ###
################
## save the users original margins
mar.org <- par()$mar
## generate a time axis
tax <- (1:(n.secs*fps)) / fps
## get the raw video into a spatiotemporal matrix
org.spat.temp <- matrix(unlist(lapply(img.list,rowSums)),ncol=length(tax))
amp.spat.temp <- matrix(unlist(lapply(amp.list,rowSums)),ncol=length(tax))
## define some example frames to plot
eg.frames = c(18,26,34,41)
## define a layout matrix
layout.mat <- matrix(c(1:length(eg.frames), rep(5,4),6:9,rep(10,4)),nrow=2,byrow=TRUE)
layout(layout.mat)
## plot some example 'frames' from the original video
i=1
while(i<=length(eg.frames)) {
par(mar=c(2,1,3,1))
## make the current title
c.main = paste('Org. Frame ', eg.frames[i], sep='')
image2(img.list[[eg.frames[i]]],axes=FALSE,main=c.main,cex.main=2,asp=1)
i=i+1
}
## plot the spatiotemporal variations of the original and amplified video
par(mar=c(2,1,3,1))
image2(org.spat.temp, ylab='y',axes=FALSE,xaxs='i',asp=1)
mtext('y', side=2,line=0.5)
axis(1)
box()
## plot the same example frames from the amplified video
i=1
while(i<=length(eg.frames)) {
par(mar=c(2,1,3,1))
## make the current title
c.main = paste('Amp. Frame ', eg.frames[i], sep='')
## add the image
image2(amp.list[[eg.frames[i]]],axes=FALSE,main=c.main,cex.main=2,asp=1)
i=i+1
}
par(mar=c(2,1,3,1))
image2(amp.spat.temp, xlab='',ylab='',axes=FALSE,xaxs='i',asp=1)
axis(3)
mtext('y', side=2,line=0.5)
mtext('frames', side=1,line=0.5)
box()
## set the layout and par back to the users original value
par(mfrow=c(1,1),mar=mar.org)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.