#RSAJscriptR will convert pixel lengths to centimeters or whatever units you want, calculate lateral root branching density, and calculate the uncorrected and corrected sweep angles. Created by Larry M York on April 4, 2014. Feel free to contact larry.york@rootbiologist.com for help or more information.
RSAJval <- Results #load results from RSAJ and rename them
knownscale <- 3 #save the known length of the scale in units you want - 3 cm for test case
######Converting pixel widths and lengths to desired units. Here we assume the zoom and camera height were always the same so can use an average of the measured scale in pixels. you could also do the calculation per image. We are also saving over top of the old columns, but you could create new ones if desired.
pixpercm <- mean(RSAJval$scale.length)/knownscale #pixels per cm
#convert all measured lengths from pixels to your units
RSAJval$stem.width <- RSAJval$stem.width/pixpercm
RSAJval$system.width <- RSAJval$system.width/pixpercm
RSAJval$depth.to.width <- RSAJval$depth.to.width/pixpercm
RSAJval$distance.to.branching <- RSAJval$distance.to.branching/pixpercm
RSAJval$lateral.count.length <- RSAJval$lateral.count.length/pixpercm
RSAJval$lateral.length1 <- RSAJval$lateral.length1/pixpercm
RSAJval$lateral.length2 <- RSAJval$lateral.length2/pixpercm
RSAJval$lateral.length3 <- RSAJval$lateral.length3/pixpercm
#create new column for lateral root branching density
RSAJval$lateral.density <- RSAJval$lateral.count / RSAJval$lateral.count.length
#####OK, so let's calculate angles from the widths and height
##uncorrected sweep angle
RSAJval$sweep.angle.uncorrected <- 2*atan((RSAJval$system.width/2)/RSAJval$depth.to.width)*(180/pi) #times 180/pi because atan produces radians, and by 2 because we solved for half
##corrected sweep angle
RSAJval$sweep.angle.corrected <- 2*atan(((RSAJval$system.width - RSAJval$stem.width)/2)/RSAJval$depth.to.width)*(180/pi) #times 180/pi because atan produces radians, and by 2 because we solved for half
#####End.