utils_dpi {pliman} | R Documentation |
Utilities for image resolution
Description
Provides useful conversions between size (cm), number of pixels (px) and dots per inch (dpi).
-
dpi_to_cm()
converts a known dpi value to centimeters. -
cm_to_dpi()
converts a known centimeter values to dpi. -
pixels_to_cm()
converts the number of pixels to centimeters, given a known resolution (dpi). -
cm_to_pixels()
converts a distance (cm) to number of pixels, given a known resolution (dpi). -
distance()
Computes the distance between two points in an image based on the Pythagorean theorem. -
dpi()
An interactive function to compute the image resolution given a known distance informed by the user. See more information in the Details section. -
npixels()
returns the number of pixels of an image.
Usage
dpi_to_cm(dpi)
cm_to_dpi(cm)
pixels_to_cm(px, dpi)
cm_to_pixels(cm, dpi)
npixels(img)
dpi(img, viewer = get_pliman_viewer())
distance(img, viewer = get_pliman_viewer())
Arguments
dpi |
The image resolution in dots per inch. |
cm |
The size in centimeters. |
px |
The number of pixels. |
img |
An image object. |
viewer |
The viewer option. If not provided, the value is retrieved
using |
Details
dpi()
only run in an interactive section. To compute the image
resolution (dpi) the user must use the left button mouse to create a line
of known distance. This can be done, for example, using a template with
known distance in the image (e.g., la_leaves.jpg
).
Value
-
dpi_to_cm()
,cm_to_dpi()
,pixels_to_cm()
, andcm_to_pixels()
return a numeric value or a vector of numeric values if the input data is a vector. -
dpi()
returns the computed dpi (dots per inch) given the known distance informed in the plot.
Author(s)
Tiago Olivoto tiagoolivoto@gmail.com
Examples
library(pliman)
# Convert dots per inch to centimeter
dpi_to_cm(c(1, 2, 3))
# Convert centimeters to dots per inch
cm_to_dpi(c(1, 2, 3))
# Convert centimeters to number of pixels with resolution of 96 dpi.
cm_to_pixels(c(1, 2, 3), 96)
# Convert number of pixels to cm with resolution of 96 dpi.
pixels_to_cm(c(1, 2, 3), 96)
if(isTRUE(interactive())){
#### compute the dpi (dots per inch) resolution ####
# only works in an interactive section
# objects_300dpi.jpg has a known resolution of 300 dpi
img <- image_pliman("objects_300dpi.jpg")
# Higher square: 10 x 10 cm
# 1) Run the function dpi()
# 2) Use the left mouse button to create a line in the higher square
# 3) Declare a known distance (10 cm)
# 4) See the computed dpi
dpi(img)
img2 <- image_pliman("la_leaves.jpg")
# square leaf sample (2 x 2 cm)
dpi(img2)
}