image2data: Image raster to data frame.

Description Usage Arguments Value See Also Examples

View source: R/image2data.R

Description

Transform a image raster to a data frame.

Usage

1
image2data(x, background = "white", x_range = NULL, y_range = NULL)

Arguments

x

It could be a rasterly object or a raster image.

background

The background of image raster.

x_range

The range represents image width.

y_range

The range represents image height.

Value

a data.table object

See Also

ggRasterly

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
x <- rnorm(1000, mean = 10)
y <- rnorm(1000, mean = 20)
color <- sample(1:5, 1000, replace = TRUE)
rastObj <- data.frame(x = x, y = y, color = color) %>%
       rasterly(mapping = aes(x = x, y = y, color = color)) %>%
       rasterly_points()
p <- rasterly_build(rastObj)
dt <- image2data(p)
if(requireNamespace("ggplot2")) {
  # Note that each point represents a single pixel in the image
  ggplot2::ggplot(dt, mapping = aes(x = x, y = y)) + 
    ggplot2::geom_point(color = dt$color, size = 0.5)
}

rasterly documentation built on July 2, 2020, 2:12 a.m.