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

as.cimg.data.frameR Documentation

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 class 'data.frame'
as.cimg(obj, v.name = "value", dims, ...)

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

Value

an object of class cimg

Author(s)

Simon Barthelme

Examples


#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

imager documentation built on May 29, 2024, 1:38 a.m.