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

by.im

Apply Function to Image Broken Down by Factor


Description

Splits a pixel image into sub-images and applies a function to each sub-image.

Usage

## S3 method for class 'im'
by(data, INDICES, FUN, ...)

Arguments

data

A pixel image (object of class "im").

INDICES

Grouping variable. Either a tessellation (object of class "tess") or a factor-valued pixel image.

FUN

Function to be applied to each sub-image of data.

...

Extra arguments passed to FUN.

Details

This is a method for the generic function by for pixel images (class "im").

The pixel image data is first divided into sub-images according to INDICES. Then the function FUN is applied to each subset. The results of each computation are returned in a list.

The grouping variable INDICES may be either

  • a tessellation (object of class "tess"). Each tile of the tessellation delineates a subset of the spatial domain.

  • a pixel image (object of class "im") with factor values. The levels of the factor determine subsets of the spatial domain.

Value

A list containing the results of each evaluation of FUN.

Author(s)

and Rolf Turner r.turner@auckland.ac.nz

See Also

Examples

W <- square(1)
  X <- as.im(function(x,y){sqrt(x^2+y^2)}, W)
  Y <- dirichlet(runifrect(12, W))
  # mean pixel value in each subset
  unlist(by(X, Y, mean))
  # trimmed mean
  unlist(by(X, Y, mean, trim=0.05))

spatstat.geom

Geometrical Functionality of the 'spatstat' Family

v2.1-0
GPL (>= 2)
Authors
Adrian Baddeley [aut, cre], Rolf Turner [aut], Ege Rubak [aut], Tilman Davies [ctb], Ute Hahn [ctb], Abdollah Jalilian [ctb], Sebastian Meyer [ctb], Suman Rakshit [ctb], Dominic Schuhmacher [ctb], Rasmus Waagepetersen [ctb]
Initial release
2021-04-15

We don't support your browser anymore

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