Learn R Programming

imagine (version 1.3.1)

meanFilter: Make a 2D filter calculations from numeric matrix

Description

This functions take a matrix object, and for each cell multiplies its neighborhood by the squared matrix of dimension \(radius*radius\). Finally and according to the type of function, they return for each cell the mean, median or the quantile of the weighted sum.

Usage

meanFilter(dataMatrix, radius, times = 1)

quantileFilter(dataMatrix, radius, x, times = 1)

medianFilter(dataMatrix, radius, times = 1)

Arguments

dataMatrix

A numeric matrix object used for apply filters.

radius

Size of squared kernel to apply median.

times

How many times do you want to apply the filter?

x

numeric vector of probabilities with values in [0,1].

Value

meanFilter returns a matrix object with the same dimensions of dataMatrix.

quantileFilter don't use a kernel but, for each cell, it returns the position of quantile 'x' (value between 0 and 1).

medianFilter is a wrapper of quantileFilter with x = 0.5.

Details

Functions use C++ algorithms. More details are shown in vignette.

Examples

Run this code
# NOT RUN {
# Generate example matrix
nRows <- 50
nCols <- 100

myMatrix <- matrix(runif(nRows*nCols, 0, 100), nrow = nRows, ncol = nCols)
radius <- 3

# Make convolution
myOutput1 <- meanFilter(myMatrix, radius)
myOutput2 <- quantileFilter(myMatrix, radius, 0.1)
myOutput3 <- medianFilter(myMatrix, radius)

# Plot results
image(myMatrix, zlim = c(0, 100))
image(myOutput1, zlim = c(0, 100))
image(myOutput2, zlim = c(0, 100))
image(myOutput3, zlim = c(0, 100))
# }

Run the code above in your browser using DataLab