Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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

Image Processing Library Based on 'CImg'

v0.42.10
LGPL-3
Authors
Simon Barthelme [aut], David Tschumperle [ctb], Jan Wijffels [ctb], Haz Edine Assemlal [ctb], Shota Ochi [cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.