View source: R/transformquantiles.R
transformquantiles | R Documentation |
Apply a transformation to the quantiles of a vector, or to the quantiles of the pixel values in a pixel image.
transformquantiles(X, uniform = FALSE, reverse = FALSE, ...)
X |
A numeric vector, matrix, array, or a pixel image
(object of class |
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. |
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 k
th
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 k
th smallest
value will be swapped with the k
th 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.
Another object of the same type as X
.
.
To apply an arbitrary function f
to the pixel values in an image,
use the idiom X[] <- f(X[])
.
X <- c(3, 5, 1, 2, 4)
transformquantiles(X, reverse=TRUE)
transformquantiles(X, uniform=TRUE)
transformquantiles(X, uniform=TRUE, reverse=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.