Learn R Programming

spatstat.geom (version 2.3-1)

owin2mask: Convert Window to Binary Mask under Constraints

Description

Converts a window (object of class "owin") to a binary pixel mask, with options to require that the inside, outside, and/or boundary of the window should be completely covered.

Usage

owin2mask(W,
         op = c("sample", "notsample",
                "cover", "inside",
                "uncover", "outside", "boundary"),
         …)

Arguments

W

A window (object of class "owin").

op

Character string (partially matched) specifying how W should be converted to a binary pixel mask.

Optional arguments passed to as.mask to determine the pixel resolution.

Value

A mask (object of class "owin" of type "mask" representing a binary pixel mask).

Details

This function is similar to, but more flexible than, as.mask. It converts the interior, exterior, or boundary of the window W to a binary pixel mask.

  • If op="sample" (the default), the mask consists of all pixels whose centres lie inside the window W. This is the same as using as.mask.

  • If op="notsample", the mask consists of all pixels whose centres lie outside the window W. This is the same as using as.mask followed by complement.owin.

  • If op="cover", the mask consists of all pixels which overlap the window W, wholly or partially.

  • If op="inside", the mask consists of all pixels which lie entirely inside the window W.

  • If op="uncover", the mask consists of all pixels which overlap the outside of the window W, wholly or partially.

  • If op="outside", the mask consists of all pixels which lie entirely outside the window W.

  • If op="boundary", the mask consists of all pixels which overlap the boundary of the window W.

See Also

as.mask

Examples

Run this code
# NOT RUN {
  W <- Window(chorley)
  opa <- par(mfrow=c(2,4))
  plot(as.mask(W, dimyx=16), col="grey", main="as.mask")
  plot(W, add=TRUE, lwd=3, border="red")  
  plot(owin2mask(W, "i", dimyx=16), col="grey", main="inside")
  plot(W, add=TRUE, lwd=3, border="red")
  plot(owin2mask(W, "c", dimyx=16), col="grey", main="cover")
  plot(W, add=TRUE, lwd=3, border="red")
  plot(owin2mask(W, "b", dimyx=16), col="grey", main="boundary")
  plot(W, add=TRUE, lwd=3, border="red")
  plot(as.mask(complement.owin(W), dimyx=16), col="grey",
       main="as.mask(complement.owin)")
  plot(W, add=TRUE, lwd=3, border="red")  
  plot(owin2mask(W, "o", dimyx=16), col="grey", main="outside")
  plot(W, add=TRUE, lwd=3, border="red")
  plot(owin2mask(W, "u", dimyx=16), col="grey", main="uncover")
  plot(W, add=TRUE, lwd=3, border="red")
  plot(owin2mask(W, "b", dimyx=16), col="grey", main="boundary")
  plot(W, add=TRUE, lwd=3, border="red")
  par(opa)
# }

Run the code above in your browser using DataLab