Learn R Programming

imager (version 0.14)

as.cimg.function: Create an image by sampling a function

Description

Similar to as.im.function from the spatstat package, but simpler. Creates a grid of pixel coordinates x=1:width,y=1:height and (optional) z=1:depth, and evaluates the input function at these values.

Usage

## S3 method for class 'function':
as.cimg(obj, width, height, depth = 1,
  normalise.coord = FALSE, ...)

Arguments

obj
a function with arguments (x,y) or (x,y,z). Must be vectorised.
width
width of the image (in pixels)
height
height of the image (in pixels)
depth
depth of the image (in pixels)
normalise.coord
coordinates are normalised so that x,y,z are in (0,1) (default FALSE)
...
ignored

Value

  • an object of class cimg

Examples

Run this code
im = as.cimg(function(x,y) cos(sin(x*y/100)),100,100)
plot(im)
im = as.cimg(function(x,y) cos(sin(x*y/100)),100,100,normalise.coord=TRUE)
plot(im)

Run the code above in your browser using DataLab