transformquantiles: Transform the Quantiles

View source: R/images.R

transformquantilesR Documentation

Transform the Quantiles

Description

Apply a transformation to the quantiles of a vector, or to the quantiles of the pixel values in a pixel image.

Usage

transformquantiles(X, uniform = FALSE, reverse = FALSE, ...)

Arguments

X

A numeric vector, matrix, array, or a pixel image (object of class "im").

uniform

Logical value specifying whether each quantile value should be replaced by the corresponding cumulative probability (called histogram equalisation, transformation to uniformity or probability integral transformation).

reverse

Logical value specifying whether to swap the upper and lower quantiles.

...

Ignored.

Details

The argument X may be a vector, matrix, array, or a pixel image (object of class "im").

The algorithm will first extract the entries or pixel values of X as a vector, and sort the values into ascending order.

If uniform=TRUE, the entries in this vector will be replaced by the corresponding cumulative probabilities (the kth smallest value will be replaced by the number (k-0.5)/n where n is the total number of values).

If reverse=TRUE, the resulting vector will be reversed so that it is in descending order (so that the kth smallest value will be swapped with the kth largest value).

Finally the transformed values will be replaced into the original positions in the vector, matrix, array, or pixel image.

The case uniform=TRUE, reverse=FALSE is called transformation to uniformity, the probability integral transformation, histogram equalisation, or quantile transformation. The resulting values are uniformly distributed between 0 and 1; a histogram of the values in X is flat.

Value

Another object of the same type as X.

Author(s)

\spatstatAuthors

.

See Also

To apply an arbitrary function f to the pixel values in an image, use the idiom X[] <- f(X[]), or use eval.im.

Examples

  X <- c(3, 5, 1, 2, 4)
  transformquantiles(X, reverse=TRUE)
  transformquantiles(X, uniform=TRUE)
  transformquantiles(X, uniform=TRUE, reverse=TRUE)

  Z <- 100 * as.im(bei.extra$grad, dimyx=c(25,50))
  opa <- par(mfrow=c(2,2))
  plot(Z,main="original")
  plot(transformquantiles(Z, reverse=TRUE), main="reverse=TRUE")
  plot(transformquantiles(Z, uniform=TRUE),
  main="uniform=TRUE", col=grey.colors,zlim=c(0,1))
  plot(transformquantiles(Z, uniform=TRUE, reverse=TRUE),
                          main="uniform=TRUE, reverse=TRUE",
                          col=grey.colors, zlim=c(0,1))
  par(opa)

spatstat.geom documentation built on Oct. 20, 2023, 9:06 a.m.