R/tile_base_corr.R

Defines functions tile_base_corr

Documented in tile_base_corr

#' Baseline correction
#'
#' A function to substract the minimun of a pixel (vector) to have a minimal signal = 0, avoiding negative readings. Currently the only preprocessing method implemented.
#'
#' @param data Object of class \code{\link[=Tile-class]{Tile}}.
#'
#' @return 
#' An object of class \code{\link[=Tile-class]{Tile}} congruent with data, with the spectra modified.
#' 
#' @export
#' @examples
#' x <- tile_read(base::system.file("extdata/tile.bsp", package = "uFTIR"))
#' x <- tile_base_corr(x)
tile_base_corr <- function(data){
  stopifnot(length(dim(data@Spectra)) == 3)

  # minimal signal = 0
  out <- apply(data@Spectra, c(1,2), function(x){x-min(x)})
  out <- aperm(out, c(2,3,1))
  data@Spectra <- out
  data
}

Try the uFTIR package in your browser

Any scripts or data that you put into this service are public.

uFTIR documentation built on Oct. 25, 2021, 9:08 a.m.