Introduction

This is an example to measure tree-ring widths in scanned images with the R-package measuRing. If you run R from an Interactive Development Environment (IDE), you should be sure that such environments support multiple graphics devices (e.g., RStudio is not ideal).

A youtube video covers much of this material as available as well.

Citing measuRing and R

There is a citation() function in R that gives you information on how to best cite R and, in many cases, its packages. Please cite measuRing and R appropriately in your work.

citation()
## 
## To cite R in publications use:
## 
##   R Core Team (2016). R: A language and environment for
##   statistical computing. R Foundation for Statistical Computing,
##   Vienna, Austria. URL https://www.R-project.org/.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {R: A Language and Environment for Statistical Computing},
##     author = {{R Core Team}},
##     organization = {R Foundation for Statistical Computing},
##     address = {Vienna, Austria},
##     year = {2016},
##     url = {https://www.R-project.org/},
##   }
## 
## We have invested a lot of time and effort in creating R, please
## cite it when using it for data analysis. See also
## 'citation("pkgname")' for citing R packages.
citation("measuRing")
## 
## To cite package 'measuRing' in publications use:
## 
##   Wilson Lara, Carlos Sierra and Felipe Bravo (2015). measuRing:
##   Detection and Control of Tree-Ring Widths on Scanned Image
##   Sections. R package version 0.3.
##   https://CRAN.R-project.org/package=measuRing
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {measuRing: Detection and Control of Tree-Ring Widths on Scanned Image
## Sections},
##     author = {Wilson Lara and Carlos Sierra and Felipe Bravo},
##     year = {2015},
##     note = {R package version 0.3},
##     url = {https://CRAN.R-project.org/package=measuRing},
##   }
## 
## ATTENTION: This citation information has been auto-generated from
## the package DESCRIPTION file and may need manual editing, see
## 'help("citation")'.

Install

The first requirement is to install and require the package from the R environment. If you haven’t installed measuRing yet you can so by running install.packages('measuRing') from the R prompt.

library("measuRing")
## Loading required package: pastecs
## Loading required package: boot
## Loading required package: png
## Loading required package: tiff

Basic Usage

To get started, you first have to provide a path to the scanned image of the ring widths In this example we will use a tif image provided with the package:

image1 <- system.file("P105_a.tif", package = "measuRing")
image1
## [1] "/Users/bunna/Rlibs/measuRing/P105_a.tif"

measuRing has many diverse functions to work with ring widths, but the complete measurement procedure can be developed with only two functions: ringDetect() processes the image section and records outputs from the measurement process; ringSelect() is used to manually select column numbers (positions of ring borders in the gray matrix of the image).

In this example, we will plot an initial diagnostic plot with three image segments (segs = 3); an example of the first image segment is printed below.

Example of image segment

Adjusting, including, and excluding rings by column

Function ringDetect() can be updated to include new arguments: some noise in smoothed gray will be avoided by moving argument origin from 0 to -0.03, formation year of the last visible ring will be fixed to the year 2012 (last.yr = 2012), and several columns numbers will be included/avoided from the analysis (see vectors Toinc and Toexc). For instance:

detect1 <- ringDetect(image1, segs = 3)
detect1 <- update(detect1, origin = -0.03)
detect1 <- update(detect1, last.yr=2012)

# find narrow rings 
Toinc <- c(202,387,1564)                                                      
detect2 <- update(detect1, inclu = Toinc)

Toexc <- c(208,1444,1484)
detect3 <- update(detect2, exclu = Toexc)

Including and excluding rings interactively

A good way to select the column numbers to be included/excluded is by using the function ringSelect() which allows the user to click on the screen:

## ring borders to be included (click on images)
Toinc <- ringSelect(detect1)    
## Object detec2 is updated with Toinc
detect2 <- update(detect2, inclu = Toinc) 
# ring borders to be excluded (click on images)
Toexc <- ringSelect(detect2,any.col = FALSE)                                  
detect3 <- update(detect2,exclu=Toexc)      

The distances between detected rings are stored in lists like detect3. For instance:

str(detect3)
## List of 3
##  $ ringBorders:'data.frame': 1610 obs. of  2 variables:
##   ..$ P105_a : num [1:1610] 0.0832 0.0962 0.1098 0.1211 0.1304 ...
##   ..$ borders: logi [1:1610] NA NA NA NA NA NA ...
##  $ ringWidths :'data.frame': 65 obs. of  2 variables:
##   ..$ year  : num [1:65] 2012 2011 2010 2009 2008 ...
##   ..$ P105_a: num [1:65] 1.016 0.813 0.686 0.94 0.813 ...
##  $ call       : language ringDetect(image1, segs = 3, origin = -0.03, last.yr = 2012, inclu = Toinc,      exclu = Toexc)
##  - attr(*, "gray.dim")= int [1:2] 20 1610
##  - attr(*, "opar")=List of 4
##   ..$ mfrow: num [1:2] 2 1
##   ..$ mar  : num [1:4] 3 2 3 2
##   ..$ oma  : num [1:4] 2 3 0 0
##   ..$ xpd  : logi NA
rings <- detect3$'ringWidths'
head(rings)
##     year P105_a
## 10  2012 1.0160
## 50  2011 0.8128
## 82  2010 0.6858
## 109 2009 0.9398
## 146 2008 0.8128
## 178 2007 0.4826

Extracting ring widths

The detected ring widths can be plotted as follows:

plot(rings, ylab = 'width (mm)', type='l', col = 'red',
     main="P105_a Ring Widths")

Conclusions

This is just a brief introduction to the very young measuRing package. There are many more functions and examples in the documentation. For instance narrow rings can be marked with dots in the images, multiple cores can be measured in series, etc. Please refer to a recent paper in Dendrochronologia for more information.

Back to R4AmeriDendro Home