Learn R Programming

imager (version 0.31)

imeval: Pixel-wise evaluation of a CImg expression

Description

This function provides experimental support for CImg's "math expression parser", a byte-compiled mini-language.

Usage

imeval(im, expr)

Arguments

im
an image
expr
an expression (as string)

Examples

Run this code
imfill(10,10) %>% imeval('x+y') %>% plot
# Box filter
boxf = "v=0;for(iy=y-3,iy<y+3,iy++,for(ix=x-3,ix< x+3,ix++,v+=i(ix,iy)));v"
imeval(boats,boxf) %>% plot
# Example by D. Tschumperle: Julia set
julia <-  "
   zr = -1.2 + 2.4*x/w;
   zi = -1.2 + 2.4*y/h;
   for (iter = 0, zr^2+zi^2<=4 && iter<256, iter++,
     t = zr^2 - zi^2 + 0.5;
     (zi *= 2*zr) += 0.2;
     zr = t
   );
   iter"
imfill(500,500) %>% imeval(julia) %>% plot

Run the code above in your browser using DataLab