# NOT RUN {
##############################
### 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)
# }
Run the code above in your browser using DataLab