Learn R Programming

imager (version 0.42.19)

as.cimg.data.frame: Create an image from a data.frame

Description

This function is meant to be just like as.cimg.data.frame, but in reverse. Each line in the data frame must correspond to a pixel. For example, the data fame can be of the form (x,y,value) or (x,y,z,value), or (x,y,z,cc,value). The coordinates must be valid image coordinates (i.e., positive integers).

Usage

# S3 method for data.frame
as.cimg(obj, v.name = "value", dims, ...)

Value

an object of class cimg

Arguments

obj

a data.frame

v.name

name of the variable to extract pixel values from (default "value")

dims

a vector of length 4 corresponding to image dimensions. If missing, a guess will be made.

...

ignored

Author

Simon Barthelme

Examples

Run this code
#Create a data.frame with columns x,y and value
df <- expand.grid(x=1:10,y=1:10) %>% dplyr::mutate(value=x*y)
#Convert to cimg object (2D, grayscale image of size 10*10
as.cimg(df,dims=c(10,10,1,1)) %>% plot

Run the code above in your browser using DataLab