image2data: Turn an image into data

Description Usage Arguments Value Examples

View source: R/image2data.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
image2data(
  path,
  type = "fill",
  scaling = TRUE,
  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

Scale the data to a standardized form, μ = 0, σ = 1 (default is TRUE).

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 α. 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.

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

1
2
3
4
5
6
7
8
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)

pocaron19/image2data documentation built on Dec. 22, 2021, 8:51 a.m.