Skip to contents

Apply a custom an fx expression to the image.

Usage

image_fx(image, expression = "p", channel = NULL)

image_fx_sequence(image, expression = "p")

Arguments

image

magick image object returned by image_read() or image_graph()

expression

string with an fx expression

channel

a value of channel_types() specifying which channel(s) to set

Details

There are two different interfaces. The image_fx function simply applies the same fx to each frame in the input image. The image_fx_sequence function on the other hand treats the entire input vector as a sequence, allowing you to apply an expression with multiple input images. See examples.

Examples

# Show image_fx() expression
img <- image_convert(logo, colorspace = "Gray")
gradient_x <- image_convolve(img, kernel = "Prewitt")
gradient_y <- image_convolve(img, kernel = "Prewitt:90")
gradient <- c(image_fx(gradient_x, expression = "p^2"),
                image_fx(gradient_y, expression = "p^2"))
gradient <- image_flatten(gradient, operator = "Plus")
#gradient <- image_fx(gradient, expression = "sqrt(p)")
gradient
#> # A tibble: 1 × 7
#>   format width height colorspace matte filesize density
#>   <chr>  <int>  <int> <chr>      <lgl>    <int> <chr>  
#> 1 GIF      640    480 RGB        FALSE        0 72x72  

# \donttest{
image_fx(img, expression = "pow(p, 0.5)")
#> # A tibble: 1 × 7
#>   format width height colorspace matte filesize density
#>   <chr>  <int>  <int> <chr>      <lgl>    <int> <chr>  
#> 1 GIF      640    480 Gray       FALSE        0 72x72  
image_fx(img, expression = "rand()")
#> # A tibble: 1 × 7
#>   format width height colorspace matte filesize density
#>   <chr>  <int>  <int> <chr>      <lgl>    <int> <chr>  
#> 1 GIF      640    480 Gray       FALSE        0 72x72  
# }
# Use multiple source images
# \donttest{
input <- c(logo, image_flop(logo))
image_fx_sequence(input, "(u+v)/2")
#> # A tibble: 1 × 7
#>   format width height colorspace matte filesize density
#>   <chr>  <int>  <int> <chr>      <lgl>    <int> <chr>  
#> 1 GIF      640    480 sRGB       FALSE        0 72x72  
# }