This function is used to automatically detect tree ring borders along the user-defined path.
ring_detect(ring.data, seg = 1, auto.path = TRUE, manual = FALSE, method = "canny", incline = FALSE, sample.yr = NULL, watershed.threshold = "auto", watershed.adjust = 0.8, struc.ele1 = NULL, struc.ele2 = NULL, marker.correction = FALSE, default.canny = TRUE, canny.t1, canny.t2, canny.smoothing = 2, canny.adjust = 1.4, path.dis = 1, origin = 0, border.color = "black", border.type = 16, label.color = "black", label.cex = 1.2)
A magick image object produced by
An integer specifying the number of image segments.
A logical value. If
A logical value indicating whether to skip the automatic
A character string specifying how ring borders are detected.
It requires one of the following characters:
A logical value indicating whether to correct ring widths.
The threshold used for producing the marker image, either a numeric from 0 to 1, or the character "auto" (using the Otsu algorithm), or a character of the form "XX%" (e.g., "58%").
A numeric used to adjust the Otsu threshold.
The default is 1 which means that the threshold will not be adjusted.
The sizes of early-wood regions in the marker image will reduce along
with the decrease of
A logical value indicating whether to relabel early-wood regions by comparing the values of their left-side neighbours.
A logical value. If
A numeric giving the threshold for weak edges.
A numeric giving the threshold for strong edges.
An integer specifying the degree of smoothing.
A numeric used as a sensitivity control factor for the Canny edge detector. The default is 1 which means that the sensitivity will not be adjusted. The number of detected borders will reduce along with the increase of this value.
A numeric specifying the perpendicular distance between
two paths when the argument
A numeric specifying the origin in smoothed gray to find
ring borders. See
Color for ring borders.
Symbol for ring borders. See
Color for years and border numbers.
The magnification to be used for years and border numbers.
A matrix (grayscale image) or array (color image) representing the tree-ring image.
auto.path = FALSE, the user can create a rectangular sub-image
and a horizontal path by interactively clicking on the tree ring image.
The automatic detection will be performed within this rectangular
To create a sub-image and a path, follow these steps.
Step 1. Select the left and right edges of the rectangle
The user can point the mouse at any desired locations and click the left mouse button to add each edge.
Step 2. Select the top and bottom edges of the rectangle
The user can point the mouse at any desired locations and click the left mouse button to add each edge. The width of the rectangle is defined as the distance between the top and bottom edges, and should not be unnecessarily large to reduce time consumption and memory usage. Creating a long and narrow rectangle if possible.
Step 3. Create a path
After creating the rectangular sub-image, the user can add a horizontal
path by left-clicking on the sub-image (generally at the center of the
sub-image, try to choose a clean defect-free area). Ring borders and
other markers are plotted along this path. If
incline = TRUE,
two paths are added simultaneously.
After creating the sub-image and the path, this function will open several
graphics windows and plot detected ring borders on image segments. The
number of image segments is controlled by the argument
method determines how ring borders are identified.
method = "watershed", this function uses the watershed algorithm
to obtain ring borders (Soille and Misson, 2001).
method = "canny", this function uses the Canny algorithm
to detect borders.
method = "lineardetect", a linear detection algorithm from the
measuRing is used to identify ring borders (Lara
et al., 2015). Note that
incline = TRUE is not supported in this
mode, and path will be automatically created at the center of the image.
If the argument
method = "watershed" or
"canny", the original
image is processed by morphological openings and closings using rectangular
structuring elements of increasing size before detecting borders. The first
small structuring element is used to remove smaller dark spots in early
wood regions, and the second large structuring element is used to remove
light strips in late wood regions. More details about morphological
processing can be found at Soille and Misson (2001).
This function uses
locator to record mouse
positions so it only works on "X11", "windows" and "quartz" devices.
Soille, P., Misson, L. (2001) Tree ring area measurements using morphological image analysis. Canadian Journal of Forest Research 31, 1074-1083. doi: 10.1139/cjfr-31-6-1074
Lara, W., Bravo, F., Sierra, C.A. (2015) measuRing: An R package to measure tree-ring widths from scanned images. Dendrochronologia 34, 43-50. doi: 10.1016/j.dendro.2015.04.002
img.path <- system.file("001.png", package = "MtreeRing") ## Read a tree ring image: t1 <- ring_read(img = img.path, dpi = 1200, plot = FALSE) ## Split a long core sample into 3 pieces to ## get better display performance and use the ## watershed algorithm to detect ring borders: t2 <- ring_detect(t1, seg = 3, method = 'watershed', border.color = 'green')#> Warning: The sampling year is set to the current year#>#>#>