Learn R Programming

SpatialVx (version 0.1-2)

FeatureAxis: Calculate the major (and minor) axis of a feature

Description

Calculate the major and minor axes of a feature and various other properties such as the aspect ratio.

Usage

FeatureAxis(x, fac = 1, flipit = FALSE, twixt = FALSE)
## S3 method for class 'FeatureAxis':
plot(x, ...)
FeatureProps(x, Im = NULL, which.props=c("centroid", "area", "axis", "intensity"), areafac=1, q = c(0.25, 0.9), ...)

Arguments

x
For FeatureAxis this is an object of class "owin" containing a binary image matrix defining the feature. In the case of plot.FeatureAxis, this is the value returned from FeatureAxis.
Im
Matrix giving teh original values of the field from which the feature was extracted. Only needed if the feature intensity is desired.
fac,areafac
numeric, in determining the lengths of the axes, they are multiplied by a factor of fac (e.g., if the grid points are k X k km each, then one could set this to k so that the resulting lengths are in terms of km rather than grid points.
q
numeric vector of values between 0 and 1 inclusive giving the quantiles for determining the intensity of the feature.
flipit
logical, should the objects be flipped over x and y? The disjointer function results in images that are flipped, this would flip them back.
twixt
logical, should the major axis angle be forced to be between +/- 90 degrees?
which.props
character vector giving one or more of "centroid", "area", "axis" and "intensity". If "axis" is given, then a call to FeatureAxis is made.
...
For plot.FeatureAxis these are additional arguments to the plot function. For FeatureProps, these are additional arguments to FeatureAxis.

Value

  • FeatureAxis: A list object of class "FeatureAxis" is returned with components:
  • zsame as the argument x passed in.
  • MajorAxis,MinorAxisa psp object with one segment that is the major (minor) axis.
  • OrientationAnglelist with two components: MajorAxis (the angle in degrees of the major axis wrt the abscissa), MinorAxis (the angle in degrees wrt the abscissa).
  • aspect.rationumeric giving teh ratio of teh length of the minor axis to that of the major axis (always between 0 and 1).
  • MidPointan object of class "ppp" giving the mid point of the major (minor) axis.
  • lengthslist object with components: MajorAxis giving the length (possibly multiplied by a factor) of the major axis, and MinorAxis same as MajorAxis but for the minor axis.
  • sma.fitThe fitted object returned by the sma function. This is useful, e.g., if confidence intervals for the axis are desired. See the sma help file for more details.
  • No value is returned from plot.FeatureAxis, a plot is created.

    For FeatureProps, a list object with components depending on the which.props argument. One or more of:

  • centroidlist with components x and y giving the centroid of the object.
  • areanumeric giving the area of the feature.
  • axislist object of class FeatureAxis as returned by the same-named function.

Warning

The length of the minor axis is determined by the clipping of an infinite line with a bounding box. Therefore, it will be slightly longer than it should be. In practice, this does not seem to be horrible. Note, however, that for circular shaped features, this may lead to a minor axis that is apparently longer than the major axis (i.e., aspect ratio will be greater than 1). Perhaps this will be improved in the future.

Details

This function attempts to identify the major and minor axes for a pre-defined feature (sometimes referred to as an object). This function relies heavily on the spatstat and smatr packages. First, the convex hull of the feature is determined using the convexhull function from the spatstat package. The major axis is then found using the sma funciton from package smatr, which is then converted into a psp object (see as.psp from spatstat) from which the axis angle and length are found (using angles.psp and lengths.psp, resp., from spatstat).

The minor axis anlge is easily found after rotating the major axis 90 degrees using rotate.psp from spatstat. The length of the minor axis is more difficult. Here, it is found by rotating the convex hull of the feature by the major axis angle (so that it is upright) using rotate.owin from spatstat, and then computing the bounding box (using bounding.box from spatstat). An infinite line (using infline from spatstat) is created, and then clipped (using clip.infline from spatstat) by the upright bounding box. This seems to give a reasonable value for the length of the minor axis. A psp object is then created using the mid point of the major axis (which should be close to the centroid of the feature) using as.psp and midpoints.psp from spatstat along with the length and angle already found for the minor axis.

See the help files for the above mentioned functoins for references, etc.

See Also

owin, convexhull, sma, as.psp, angles.psp, rotate.owin, rotate.psp, bounding.box, midpoints.psp, lengths.psp, infline, clip.infline, deltamm, FeatureSuite, FeatureSuitePrep, convthresh, disjointer, connected, tiles, tess, solutionset

Examples

Run this code
grid<- list( x= seq( 0,5,,100), y= seq(0,5,,100)) 
obj <- stationary.image.cov( grid=grid, V=cbind(c(0.25,0.15),c(0.45,0.75)), setup=TRUE)
look<- sim.rf( obj)
look <- disk2dsmooth(look,5)
u <- quantile(look,0.99)
sIx <- matrix(0, 100, 100)
sIx[ look > u] <- 1
look2 <- disjointer(sIx)[[1]]
look2 <- flipxy(look2)
tmp <- FeatureAxis(look2)
plot(tmp)
tmp$OrientationAngle
tmp$lengths

data(pert000)
data(pert004)
hold <- FeatureSuitePrep("pert004", "pert000")
look <- convthresh( hold, smoothpar=10.5)
par( mfrow=c(2,2))
image.plot(look$X.labeled)
image.plot(look$Y.labeled)

look2 <- deltamm( look, verbose=TRUE)
image.plot(look2$X.labeled)
image.plot(look2$Y.labeled)

look2$mm.new.labels # the first seven features are matched.

ang1 <- FeatureAxis(look2$X.feats[[1]])
ang2 <- FeatureAxis(look2$Y.feats[[1]])
plot(ang1)
plot(ang2)

ang3 <- FeatureAxis(look2$X.feats[[4]])
ang4 <- FeatureAxis(look2$Y.feats[[4]])
plot(ang3)
plot(ang4)

Run the code above in your browser using DataLab