Learn R Programming

hsdar (version 0.5.1)

smoothSpeclib: Smooth spectra

Description

Smooth spectra using Savitzky-Golay filtering, lowess-, spline-functions or mean filter.

Usage

smoothSpeclib(x, method = "mean", ...)

Arguments

x
Object of class Speclib.
method
Character string giving the method to be used. Predefined valid options are "sgolay", "lowess", "spline" and "mean". However, method can also be the (character) name of any other filter function (see examples).
...
Further arguments passed to filter functions. See examples.

Value

Object of class Speclib.

Details

This function allows filtering using four different methods:
  • Savitzky-Golay: Smoothing applying Savitzky-Golay-Filter. See sgolayfilt for details.
  • Lowess: Smoothing applying lowess-Filter. See lowess for details.
  • Spline: Smoothing applying spline-Filter. See spline for details.
  • Mean: Smoothing applying mean-Filter. See meanfilter for details.

References

Tsai, F. & Philpot, W. (1998): Derivative analysis of hyperspectral data. Remote Sensing of Environment 66/1. 41-51.

See Also

sgolayfilt, lowess, spline, meanfilter

Examples

Run this code
data(spectral_data)

## Example of predefined filter functions
## Savitzky-Golay
sgolay <- smoothSpeclib(spectral_data, method="sgolay", n=25)

## Spline
spline <- smoothSpeclib(spectral_data, method="spline", 
                         n=round(nbands(spectral_data)/10,0))

## Lowess
lowess <- smoothSpeclib(spectral_data, method="lowess", f=.01)

## Mean
meanflt <- smoothSpeclib(spectral_data, method="mean", p=5)

par(mfrow=c(2,2))
plot(spectral_data, FUN=1, main="Savitzky-Golay")
plot(sgolay, FUN=1, new=FALSE, col="red", lty="dotted")
plot(spectral_data, FUN=1, main="Spline")
plot(spline, FUN=1, new=FALSE, col="red", lty="dotted")
plot(spectral_data, FUN=1, main="Lowess")
plot(lowess, FUN=1, new=FALSE, col="red", lty="dotted")
plot(spectral_data, FUN=1, main="Mean")
plot(meanflt, FUN=1, new=FALSE, col="red", lty="dotted")

## Example of a not predefined filter function (Butterworth filter)
bf <- butter(3, 0.1)
bf_spec <- smoothSpeclib(spectral_data, method="filter", filt=bf)
plot(spectral_data, FUN=1, main="Butterworth filter")
plot(bf_spec, FUN=1, new=FALSE, col="red", lty="dotted")

Run the code above in your browser using DataLab