get_measures()computes object measures (area, perimeter, radius) by using either a known resolution (dpi) or an object with known measurements.plot_measures()draws the object measures given in an object to the current plot. The object identification ("id") is drawn by default.
Usage
get_measures(
object,
measure = NULL,
id = NULL,
dpi = NULL,
sep = "\\_|-",
verbose = TRUE,
digits = 5
)
plot_measures(
object,
measure = "id",
id = NULL,
hjust = NULL,
vjust = NULL,
digits = 2,
size = 0.9,
col = "white",
...
)Arguments
- object
An object computed with
analyze_objects().- measure
For
plot_measures(), a character string; forget_measures(), a two-sided formula, e.g.,measure = area ~ 100indicating the known value of objectid. The right-hand side is the known value and the left-hand side can be one of the following.areaThe known area of the object.perimeterThe known perimeter of the object.radius_meanThe known radius of the object.radius_minThe known minimum radius of the object. If the object is a square, then theradius_minof such object will beL/2whereLis the length of the square side.radius_maxThe known maximum radius of the object. If the object is a square, then theradius_maxof such object according to the Pythagorean theorem will beL x sqrt(2) / 2whereLis the length of the square side.
- id
An object in the image to indicate a known value.
- dpi
A known resolution of the image in DPI (dots per inch).
- sep
Regular expression to manage file names. The function combines in the
mergeobject the object measures (sum of area and mean of all the other measures) of all images that share the same filename prefix, defined as the part of the filename preceding the first hyphen (-) or underscore (_) (no hyphen or underscore is required). For example, the measures of images namedL1-1.jpeg,L1-2.jpeg, andL1-3.jpegwould be combined into a single image information (L1). This feature allows the user to treat multiple images as belonging to a single sample, if desired. Defaults tosep = "\\_|-".- verbose
If
FALSE, runs the code silently.- digits
The number of significant figures. Defaults to
2.- hjust, vjust
A numeric value to adjust the labels horizontally and vertically. Positive values will move labels to right (hjust) and top (vjust). Negative values will move the labels to left and bottom, respectively.
- size
The size of the text. Defaults to
0.9.- col
The color of the text. Defaults to
"white".- ...
Further arguments passed on to
graphics::text().
Value
For
get_measures(), ifmeasureis informed, the pixel values will be corrected by the value of the known object, given in the unit of the right-hand side ofmeae. Ifdpiis informed, then all the measures will be adjusted to the knosurwndpi.
If applied to an object of class
anal_obj, returns a data frame with the objectidand the (corrected) measures.If applied to an object of class
anal_obj_ls, returns a list of classmeasures_ls, with two objects: (i)results, a data frame containing the identification of each image (img) and object within each image (id); and (ii)summarya data frame containing the values for each image. If more than one object is detected in a given image, the number of objects (n), total area (area_sum), mean area (area_mean) and the standard deviation of the area (area_sd) will be computed. For the other measures (perimeter and radius), the mean values are presented.
plot_measures()returns aNULLobject, drawing the text according to the x and y coordinates of the objects inobject.
Author
Tiago Olivoto tiagoolivoto@gmail.com
Examples
if (interactive() && requireNamespace("EBImage")) {
library(pliman)
img <- image_pliman("objects_300dpi.jpg")
plot(img)
# Image with four objects with a known resolution of 300 dpi
# Higher square: 10 x 10 cm
# Lower square: 5 x 5 cm
# Rectangle: 4 x 2 cm
# Circle: 3 cm in diameter
# Count the objects using the blue band to segment the image
results <-
analyze_objects(img,
index = "B",
lower_noise = 0.1)
plot_measures(results, measure = "id")
# Get object measures by declaring the known resolution in dots per inch
(measures <- get_measures(results, dpi = 300))
# Calculated diagonal of the object 1
# 10 * sqrt(2) = 14.14
# Observed diagonal of the object 1
measures[1, "radius_max"] * 2
# Get object measures by declaring the known area of object 1
get_measures(results,
id = 1,
area ~ 100)
}
