Download these images if you would like to follow along with my example, or you can use images of your own
Snapping Shrimp Photos With Scale Bar
Install Geomorph
install.packages("geomorph", dependencies = TRUE)
Load Geomorph
library(geomorph)
Create a folder inside your assignments folder to store your jpeg files. These must be jpegs, there are other packages that allow you to analyze other file types.
I created a folder in my assignments folder titled “my work”
Set working directory to the folder with your images
Make a file list from the images in your folder
filelist <- list.files(pattern = "*.jpeg")
Set scale and select landmarks
Digitize your photos by selecting landmarks. You need to choose images with a scale such as a ruler in the photo to get an accurate measurement. nlandmarks- the number of points you will mark on your photo scale- the amount in mm you will set
This should pull up the first image you have in your filelist. It will have you set a scale, the first two clicks are setting the scalebar. It will something along the lines of is this the scale you want to set? (y/n). Select y if it is satisfactory.
digitize2d(filelist, nlandmarks = 11, scale = 3, tpsfile = "shrimp3.tps", verbose = TRUE)
Now it is asking you to set your landmark points. You can set as many landmark features as you want, I would suggest doing around ten. After each selection you need to enter ‘y’ to move onto the next landmark.
After digitizing this, all the points have been landmarked in shrimp3.tps
Make a data file
mydata <- readland.tps("shrimp3.tps", specID= "ID")
Need to create both of these files to be able to plot data
Y.gpa <- gpagen(mydata, print.progress = FALSE)
ref <- mshape(Y.gpa$coords)
This takes your landmark data and plots it
plotRefToTarget(ref, Y.gpa$coords[,,2], method="TPS")
Takes landmark data and magnifies the difference between your reference and target by 3X
plotRefToTarget(ref, Y.gpa$coords[,,2], mag=3, method="TPS")
Shows the displacement between target and reference sequence using the vector method. Arrows show direction of displacement
plotRefToTarget(ref, Y.gpa$coords[,,2], mag=3, method="vector")
Plots both the reference and the target landmark data, one in black one in grey
plotRefToTarget(ref, Y.gpa$coords[,,2], mag=3, method="points")
Y.gpa <- gpagen(mydata, print.progress = FALSE)
This plots all the landmark data that has been digitized. The green color is your original landmark points and the black is the mean between landmarks.
plotAllSpecimens(Y.gpa$coords, label=T, plot.param = list(pt.bg = "green", mean.cex=1, link.col= "red", txt.pos=3, txt.cex=1))
1. Chose two images of the same animal and compare a morphological feature through landmarking (at least ten landmark points.
2. Make a plot with either plotAllSpecimens or plotRefToTarget (points, vector, or TPS method)
3. Upload as "Hansen seminar assignment"