| image2data {image2data} | R Documentation |
Turn an image into data
Description
Extract an image file ("png", "tiff", "jpeg", "bmp") and turn it into an enjoyable data set, pixels being rows (subjects) and columns (variables) being their coordinate positions (x and y axis) and their respective color (in hex codes).
Usage
image2data(
path,
type = "fill",
scaling = "standardized",
showplot = TRUE,
reduce = 1,
A = 1,
R = c(0, 0.05),
G = c(0, 0.05),
B = c(0, 0.05),
Grey = NULL,
precision = 1,
seed = NULL
)
Arguments
path |
Path to image file.
|
type |
Type of extraction of data. type = "fill" (default) returns the complete image as data whereas type = "line"
returns a specific range of color (default is black).
|
scaling |
Tranform the data to a specified scale. Three options are available : "standardized", "original", "normalized"). scaling = "standardized" converts data in a standardized form, \mu = 0, \sigma = 1 (default); scaling = "normalized" converts data in a normalized form (to unit vectors); and scaling = "original" keeps the data untransformed.
|
showplot |
Show a preliminary plot of the data (default is TRUE).
|
reduce |
reduce can be a number reduce > 0 or reduce = "unique". By default reduce = 1, so all pixels are returned. Specified values between 0 to 1 will return the corrresponding proportion of the pixels. Values over 1 will return the number of pixels (e.g., reduce = 3 returns 3 data). If the chosen number is over the number of pixels, then random duplicates are added. If reduce = "unique" only unique elements (given a certain precision) are returned.
|
A |
Transparency, otherwise known as \alpha. By default, only non transparent (A = 1) values are returned. Semi-transparent colors (0 < A < 1) are supported. Values between the A to 1 range will be return. If A = 0, all pixels are returned regardless of transparency.
|
R, G, B |
Color to return with type = "line" (the default range is c(0, .05) for each, i.e., black). A single "range" of color can be used.
|
Grey |
Grey range to be returned with type = "line". Grey overwrites R, G, B and behaves similarly. Default is NULL
|
precision |
Set precision of reduce = "unique". Default is 1. It can be any integer >0. Values closer to zero are less precised (less data), higher values are more precise (more data).
|
seed |
Set seed value for random pixel returned with reduce.
|
Value
A data frame with pixels as rows and columns are x and y coordinates and g is their color in hex (factors).
Examples
path <- system.file(file.path("extdata", "success.png"), package = "image2data")
image2data(path = path, type = "line")
image2data(path = path, type = "line", Grey = c(0,.50))
## Not run:
image2data(path = file.choose())
## End(Not run)
[Package
image2data version 1.0.1
Index]