# NOT RUN {
#### plot lot caudal amplitude and produce a classic midline waveform plot of swimming fish
##A very long example.
# }
# NOT RUN {
#download example images and place in 'example' subdirectory
f <- "https://github.com/ckenaley/exampledata/blob/master/example.zip?raw=true"
download.file(f, paste0(tempdir(),"/temp.zip"))
unzip(paste0(tempdir(),"/temp.zip"), exdir=tempdir())
unlink(paste0(tempdir(),"/temp.zip"))
dir.create(paste0(tempdir(),"/processed_images"))
kin <- kin.search(image.dir =paste0(tempdir(),"/example"),
search.for = "largest",
smoothing = "loess",frames=1:50,
out.dir=paste0(tempdir(),"/processed_images"),
show.prog = FALSE,thr = "otsu",
image.type="bin",smooth=0.4)
#plot instantaneous amplitude of tail (last/rightmost point) over frames
p <- ggplot(dat=kin$kin.dat,aes(x=frame,y=amp))+geom_line()+geom_point()+theme_classic(15)
print(p)
# midline plot
ml <- kin$midline
#leftmost x starts at 0
ml <- ml[,x2:=x-x[1],by=frame]
ml <- merge(ml,kin$kin.dat[,list(frame,amp)],by="frame") #merge these
pal <- wes_palette("Zissou1", 100, type = "continuous") #"Zissou" color palette
p <- ggplot(dat=ml,aes(x=x2,y=wave.y))+theme_classic(15)+scale_color_gradientn(colours = pal)
p <- p+geom_line(aes(group=frame,color=amp),stat="smooth",method = "loess", size = 1.5)
print(p)
#Make a video of processed frames
images.to.video2(image.dir=paste0(tempdir(),"/processed_images"),
vid.name="trout_test",out.dir=tempdir(),frame.rate=5,qual=100,raw=FALSE)
file.exists(paste0(tempdir(),"/trout_test_red.mp4"))
# }
# NOT RUN {
## A very short example.
#retrieve image
i <- EBImage::readImage(system.file("extdata/img", "sunfish_BCF.jpg", package = "trackter"))
#create directory and write image to it
t <- tempdir()
dir.create(paste0(t,"/images"))
EBImage::writeImage(i,paste0(t,"/images/sunfish001.jpg"),type = "jpeg")
list.files(paste0(t,"/images"))
#run kin.search and save output image to directory
kin.i<- kin.search(image.dir = paste0(t,"/images"),smooth=0.7,save = TRUE,out.dir = t)
#plot midline over original image
with(kin.i$midline,plot(x,wave.y))
i2 <- EBImage::readImage(paste0(t,"/sunfish001_000.jpg"))
EBImage::display(i2,method="raster")
#clean up
unlink(paste0(t,"/images"),recursive=TRUE)
# }
Run the code above in your browser using DataLab