placegrainsfromlib: Place grains randomly on a point pattern

View source: R/placegrainsfromlib.R

placegrainsfromlibR Documentation

Place grains randomly on a point pattern


Places subsets (grains) of two dimension space randomly on a given point pattern. This is useful for simulating germ-grain models such as Boolean models. Also described here are functions for computing summary properties of the a list of grains.


  replace = TRUE,
  prob = NULL,
  w = NULL,
  xy = NULL

  weights = rep(1/length(grainlib), length(grainlib))

  weights = rep(1/length(grainlib), length(grainlib)),

covar.grainlib(lambda, grainlib, weights, xy)



A point pattern (in ppp format).


A list of grains as owin objects in a solist.


passed directly to sample. When TRUE grains are chosen from library with replacement.


A list of probability weights for each grain in the library. Passed directly to sample. If NULL the grains are selected with equal probability.


Optional desired observation window. If this is non-null then any grains with Frame outside the Frame of w will be ignored. This reduces polygonal intersection calculations for very large buffer distances


An im or binary mask object that is used to specify the pixel array of objects.


Probability of selecting each grain in the library


Intensity of germs of a Boolean model - for computing the covariance of a Boolean model that has grain distribution given by grainlib and weights.


Germ-grain models have two components, a point process (called germs) and a process that creates grains that are centred on the germs. The point process of germs can be easily simulated using a number of spatstat functions (e.g. rpoispp for Boolean models). To simulate a germ-grain model in a window W the germ process must be simulated in a larger window because grains centred outside W can intersect W. The result must then be cropped to W to achieve a realisation of the germ-grain process within W.

placegrainsfromlib randomly samples from a library of grains (grainlib) and places these on the points in pp. Sampling of the grain is independent of the location of the point in pp. It can be used to simulate the grain process in some germ-grain models.


Returns an owin object.


  • placegrainsfromlib(): Place grains randomly from a list of grains.

  • meanarea.grainlib(): Compute mean area of a random grain given by the library

  • meansetcov.grainlib(): Computes the mean of the set covariance of the grains in grainlib. xy is required because the set covariance function must rasterise the owin objects.

  • covar.grainlib(): Compute the covariance of a Boolean model with random grain given by the library


Kassel Liam Hingee


# Simulate a germ-grain model where germs are a Poisson point process
# and grains are randomly selected from 3 different disc sizes.
grainlib <- solist(disc(radius = 1), disc(radius = 1.9), disc(radius = 0.2))
bufferdist <- 2 #chosen to be larger than the largest radius in library
w <- owin(xrange = c(0, 10), yrange = c(0, 10))

# Simulate the germ process in the window plus a buffer region around window
pp <- rpoispp(lambda = 0.1, win = dilation(w, bufferdist), nsim = 1, drop = TRUE)
xi_withbuffer <- placegrainsfromlib(pp, grainlib)

# Simulation of germ-grain model is the part within the window
xi <- intersect.owin(xi_withbuffer, w)

# Computation of properties from parameters 
lambda <- 0.1
discr <- 10
weights <- c(0.9999, 0.0001)
grainlib <- solist(disc(r = discr), disc(r = 2*discr))
meanarea.grainlib(grainlib, weights)
truecovar <- covar.grainlib(lambda, grainlib, weights, xy = as.mask(w, eps = 2))

lacunaritycovariance documentation built on Nov. 2, 2023, 6:08 p.m.