the analysis of tree rings typically involves measuring the distance between ring boundaries , comparing measurements between cores and checking for errors .
while the fastest way to measure tree rings is to measure prepared cores or stem discs directly ( e.g. , with the lintab system [ frank rinn , heidelberg , germany ] ) , this method is very time - consuming if rings are sometimes indistinct , in which case it becomes necessary to compare and re - measure the original cores ( levani , 2007 ) . here , measuring digitized images that can be re - analysed easily is an advantage .
several programs are available to measure tree rings on digital images , differing in cost and capacity
while the more upmarket programs provide many extras , they may not be optimal for all purposes .
for instance , in tropical tree rings , which are difficult to identify and cross - date , it is useful to compare cores on several images that can be scrolled up and down individually to search for matching features , but windendro and lignovision can open only one image at the time ( table 1 ) .
writing completely new software for the analysis of tree - ring images for some specific needs tends to be too complex or time - consuming for most researchers .
however , different programs are available that are able to perform part of the task necessary , such as image analysis , detrending or graphical presentations .
if these programs can run macros in a common environment such as visual basic for applications ( vba ) , they can be linked to exchange data or commands even if their programming languages differ .
compared to writing new software it then becomes relatively easy to produce versatile and flexible software for specific applications such as tree - ring analysis .
i here present simple procedures to measure and evaluate digitized cores , combining existing programs via vba macros . while the software was designed to help with the analysis of tropical tree rings that are difficult to date , the first macro , with only about 160 lines of effective code , is simple to change and features such as graphic presentation and simple statistical evaluation can be modified in excel without any code - writing .
the macros combine sigmascan pro , a program for image analysis , excel , a spreadsheet program with simple graphic and statistic features , and r , a powerful open - source statistical package .
it was developed and tested with sigmascan pro 5.0 ( systat software inc . , chicago , usa ) , excel 2003 ( microsoft inc . , redmont , usa ) and r 2.9.0 ( r development core team , 2009 , http://www.r-project.org ) on a pc with windows xp as well as on a mac with windows xp .
some technical details are given in the following chapters , the full source code with comments can be seen by opening the macro in excel .
many researchers produce images from sanded increment cores with a high - end desktop scanner , but obtaining images with a microscope and stitching adjacent parts of a core together is also an option ( levani , 2007 ) .
the image resolution needs to balance the amount of detail required and the size of the image files , a resolution of 12002400  dpi is almost always sufficient and substantially less ( 300600  dpi ) is sufficient for samples with clear ring boundaries .
sigmascan supports a large range of image formats , including bmp , jpeg , pcx , tga , tif and psd , b / w as well as colour images .
the size of the image as well as the number of images open at the same time are basically limited by computer memory , but should not be unnecessarily large to avoid slow performance . open the image with sigmascan and use the overlay draw mode of sigmascan ( mode  >  overlay draw mode ) to mark ring boundaries with a dot .
an overlay in sigmascan is a layer placed onto the original image but stored in a separate file , so that the original image is not modified . since only one overlay ( the standard is green )
is needed to mark ring , four other colours can be used to mark additional features or write comments to the image .
the size of the dot can be set in tools  >  cursor / pen size , 59 pixel is mostly useful , depending on the image size and how easily the marks should be visible .
dots on successive ring boundaries should be approximately along a straight line , which is best achieved by following the rays from bark to pith . if this is not possible because the core does not exactly follow the rays from bark to pith , start a new line along a different ray by placing a second dot on the same ring boundary ( see arrows in fig . 2 and details in the next chapter ) .
when all ring boundaries have been marked , save and close the file , the overlay with the ring boundaries will be saved in a separate file with the extension 
open tr r in excel ( click  activate macros  when asked ) and check that in the sheet 
setup  the directory of the image files , the outer year and the calibration ( in pixels per mm , e.g. , 94.5 for a resolution of 2400  dpi ) are correct .
put the name of the image files ( including the extension but excluding the directory ) in the third row of the sheet 
( via extra  >  macro  >  macros or alt - f8 ) .
the detrended series are written below the cell with the filename , the raw data to the sheet  raw  , pearson correlation coefficients and gleichlufigkeit to the sheet
names and general layout of excel sheets should not be changed unless users also modify the code in the macro that addresses these sheets .
the name of the excel file ( tr r ) can be changed as required .
the raw - data measurement does not require r , so the program will run with excel and sigmascan alone . however , for detrending and the calculation of the correlation coefficient and gleichlufigkeit ( eckstein and bauch , 1969 ) r routines are called , and it is recommended to install r ( http://www.r-project.org ) and rexcel ( http://rcom.univie.ac.at/ ) as well . for users familiar with r ,
this provides a seamless interface to a powerful and increasingly popular statistics and graphics software .
alternatively , excel can be used for graphic display and simple statistics , or data can be exported and used in other tree ring software .
special export formats such as heidelberg or tuscon that some tree ring programs require are currently not provided . after running the macro ,
ring boundaries are tagged with the year ( see fig . 1 in the manual ) .
this annotation is saved in a separate file and will be shown when the image file is opened in sigmascan the next time . depending on the project and how complex cross - correlation turns out to be , users will validate the first dating by comparing the graphs of detrended series or by using correlation coefficients and gleichlufigkeit . the sheet
 detr  shows the pearson correlation and gleichlufigkeit with the mean series , the sheet  cor  has cross - correlations between each two series .
when cross - correlation indicates error in dating or problematic rings , images are compared in sigmascan .
a major advantage compared to other available software is that various images of different cores can be opened at the same time and compared by scrolling individual images up and down so that matching tree rings can be aligned .
this is a substantial advantage when identifying ring boundaries is difficult and detailed anatomical comparisons between cores are necessary .
when dots marking ring - boundaries are changed and the excel macro is run , graphs and correlations in excel are updated automatically .
the number of files open at the same time is limited by the computer 's memory , but more than six to eight is not of much use given the size of even a large screen .
sigmascan is a flexible package for image analysis and sigmascan pro can be programmed with a specific macro language . in order to measure tree rings
it is only necessary to mark ring boundaries on images and to measure the distance between boundaries . in sigmascan images
can be drawn on in five different colour - coded overlays , which are stored in separate files and do not modify the image .
thus the distance between two points , positioned on ring boundaries along the radius , yields the ring width .
points marking rings can be placed along a line following the rays , which will generally not be a completely straight line .
if required one can also draw a straight line with a different colour and place boundaries exactly along this line .
since only one overlay is used to mark ring boundaries , other colours can be used for annotations .
a typical core does not follow exactly the radius to the pith , and it is thus not possible to measure all rings along one single straight line or ray . to start a new line ,
if the angle between three successive points is lower than a user - defined threshold ( 160 was found to be useful ) , the program records a new line with the first point assumed to be on the same ring boundary as the last point of the previous line .
the angle ( gamma ) between successive points is calculated with the code below , where x0-y0 , x1-y1 , x2-y2 are the x and y positions of three consecutive points . sometimes cores are broken and the gap between two pieces needs to be excluded .
if marked by short lines ( anything longer than 20 pixels ) along the gap boundaries , this is recognized as a gap and will be subtracted from the distance between the two boundaries next to the gap .
running the macro measures ring widths , recognizing new lines and gaps , and will mark the rings with the year .
the above procedure will work in sigmascan alone , however , to evaluate and compare the measurement of several cores requires graphics , which are very limited in sigmascan .
thus the data are written to an excel spreadsheet where any graphic is immediately updated and the macro is called from within excel .
we found it useful to plot ring - widths of several cores together with a mean curve , as well as the pearson correlation ( r2 ) and gleichlufigkeit ( gl ) between a measured core and the mean or standard curve , to indicate where cores cross - date well and where a likely error may have occurred .
if the cell with the filename is marked in excel , starting the macro loads the image , measures distances , writes year - tags to the image and writes the results to the excel spreadsheets .
thus a series of images whose filenames are written to a line in the spreadsheet can be measured quickly , updating tables and graphs immediately without the need to copy and paste results .
r is code - based and it has been possible to link r with other programs such as c++ or vba previously .
the recent release of rexcel ( baier and neuwirth , 2008 ) provides an easy link between r and excel , which combines the power of r with the comfort of a widely used spreadsheet and enables , for instance , to call r functions from the spreadsheet or to exchange data between r and excel .
rexcel requires additional programs to function , which can be installed with the free package randfriends ( http:\\rcom.univie.ac.at ) .
several published ( bigler , 2005 ; bunn , 2008 ) and many unpublished routines for tree - ring analysis are available in r and adapting statistical or graphic functions is relatively straightforward . in the macro , the algorithm for detrending was borrowed from dplr ( bunn , 2008 ) . alternatively ,
detrend  can be called directly with the option to select one of several ways of detrending . linking sigmascan ,
excel and r provides the advantage that simple or more complex steps in tree - ring analysis can be automated and run immediately following measurement without the need of exporting and importing data in specified formats . for instance
, a few lines of code calculate and copy the detrended series to the spreadsheet . in the code
 runs r code from the vba macro and  getarray  copies values from r to excel . in principle
, the statistical and graphic analysis of tree ring series can be run entirely in r without the need of a spreadsheet .
apart from the fact that more people are familiar with excel than r and may find it easy to adapt a spreadsheet with graphs to their need , an important advantage of excel is that dependencies between cells are constantly monitored and the value of a cell or a graph is updated as soon as the value of another cell it depends on is changed . with rexcel r functions can be called directly from an excel cell .
for instance , the first line of the sheet  detr  calculates the correlation coefficient ( r2 ) of the correlation between an individual series and the mean series ( or any other series selected by the user ) .
a correlation coefficient could also be calculated with excel , but there is no excel function for the gleichlufikeit ( gl ) , which is often used to evaluate the correlation between ring series . to calculate gl , an r function  gl 
was written to the sheet  setup  and this function is called from the second line of the sheet  detr  .
sometimes this is rather unimportant , sometimes the distance to the pith needs to be know to estimate the age of the tree .
this can be done by looking at the curvature of the inner rings ( duncan , 1989 ) , but measuring ring - width as described above allows to estimate the missing distance to the pith without any extra measurements .
if ring boundaries are marked along straight lines parallel to the rays , the extension of these lines should intersect at the pith .
typically , the first lines will be parallel to the core and the last lines will be almost perpendicular , passing the pith at a certain distance . of course rings
are neither perfectly circular nor will marked ring - boundaries be on a perfect line , thus more than two lines are very unlikely to intersect at a single point ( fig .
however , a good estimate is obtained by selecting the three innermost lines but one , calculating the three points where pairs of these lines intersect , and taking the mean distance from these points to the innermost marked ring .
currently , the distances of the three points where lines intersect are written to the spreadsheet  eval  .
ring boundaries are defined by various anatomical characteristics such as vessel size , wood density or the distribution of cell types that can be easy to recognize by an experienced eye but are often hard to detect automatically .
an important exception is conifer wood , where , due to the uniform cell type , the main defining feature is wood density , with denser latewood generally reflected in darker colours .
thus , plotting the darkness from the bark to the pith will show regular changes with an increase from lighter early - wood to darker late - wood followed by an abrupt drop in darkness with the new early - wood .
sigmascan measures the intensity ( greyscale ) of pixels along user - defined lines , together with the x and y position of the points along the line .
the width of the line can be set , so that typically the intensity at any point will not be a single pixel but the average of all pixels across the line . in the current simple version of the macro  autodetection  , ring boundaries are detected as an abrupt change from high to low intensity , defined as the steepest negative slopes in the intensity - curve from bark to pith . to reduce noise ,
the greyscale curve is first smoothed , with the degree of smoothing and the slope of the greyscale that defines a transition being set by the user . to evaluate results , a graph in r
shows the original , the smoothed and the first order differential of the greyscale curve with identified boundaries marked ( fig .
sobel filters and more sophisticated edge detectors have been used to automatically identify tree rings ( conner et al . , 1998 ;
this was not included in the autodetection macro as we want to retain the information on greyscales .
however the potential to do this is shown in a small third macro (  filter  ) that reduces noise , applies a sobel - filter for the detection of vertical edges , copies highlighted pixels to an overlay , removes edges that are < 5 pixels , and copies the overlay onto the original picture ( fig .
the program was written in part to optimize an image analysis system for the requirements of our project , in part because of the high costs of some specialized software ( table 1 ) .
i did not intend to expand the options for statistical evaluation of results , as routines are being developed in r and can be included at any time .
of the three software packages required , r is free and excel is installed on most computers .
sigmascan is used in many academic departments , but is not free and has not been updated or expanded for the last years .
free image analysis software is available , but to my knowledge not ( yet ) suitable for the application described .
scionimage ( http://www.scioncorp.com/ ) is a windows - version of the popular nih image for mac ( http://rsb.info.nih.gov/nih-image/ ) and can also be linked to other programs using visualbasic .
embimage ( http://www.bioconductor.org/packages/devel/bioc/html/ebimage.html ) is a free image processing and image analysis toolkit for r. in both cases it appears currently not possible to interactively mark or draw onto image using overlays that do not modify the image .
if such features become available , modifying the macros to run on a free platform should be straightforward .
i appreciate feedback from users and will try to provide support , add some useful features and update the manual to include upcoming questions .
if the program is found useful , however , it is hoped that others will contribute additional useful features .
the program was written in part to optimize an image analysis system for the requirements of our project , in part because of the high costs of some specialized software ( table 1 ) .
i did not intend to expand the options for statistical evaluation of results , as routines are being developed in r and can be included at any time .
of the three software packages required , r is free and excel is installed on most computers .
sigmascan is used in many academic departments , but is not free and has not been updated or expanded for the last years .
free image analysis software is available , but to my knowledge not ( yet ) suitable for the application described .
scionimage ( http://www.scioncorp.com/ ) is a windows - version of the popular nih image for mac ( http://rsb.info.nih.gov/nih-image/ ) and can also be linked to other programs using visualbasic .
embimage ( http://www.bioconductor.org/packages/devel/bioc/html/ebimage.html ) is a free image processing and image analysis toolkit for r. in both cases it appears currently not possible to interactively mark or draw onto image using overlays that do not modify the image .
if such features become available , modifying the macros to run on a free platform should be straightforward .
i appreciate feedback from users and will try to provide support , add some useful features and update the manual to include upcoming questions .
if the program is found useful , however , it is hoped that others will contribute additional useful features .
 i present a new software that links a program for image analysis ( sigmascan ) , one for spreadsheets ( excel ) and one for statistical analysis ( r ) for applications of tree - ring analysis . 
 the first macro measures ring width marked by the user on scanned images , stores raw and detrended data in excel and calculates the distance to the pith and inter - series correlations . 
 a second macro measures darkness along a defined path to identify latewood  earlywood transition in conifers , and a third shows the potential for automatic detection of boundaries . written in visual basic for applications , the code makes use of the advantages of existing programs and is consequently very economic and relatively simple to adjust to the requirements of specific projects or to expand making use of already available code . 
Introduction
Handling
Measuring ring width
Calculation of distance to pith
Automatic detection of ring boundaries
Outlook