Commit b14dc3c1 authored by Björn Reineking's avatar Björn Reineking

Add helper functions for rasters

parent dab0599d
Package: vigratools
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R:
Authors@R:
person(given = "First",
family = "Last",
role = c("aut", "cre"),
......@@ -10,12 +10,13 @@ Description: What the package does (one paragraph).
License: What license it uses
Encoding: UTF-8
LazyData: true
Imports:
Imports:
vigRa,
Rcpp
Rcpp,
raster
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.0
SystemRequirements: C++11
LinkingTo:
LinkingTo:
Rcpp,
vigRa
......@@ -5,6 +5,8 @@ export(gaussian_gradient_magnitude)
export(gaussian_smoothing)
export(hessian_of_gaussian_eigenvalues)
export(laplacian_of_gaussian)
export(raster_apply)
export(raster_mapply)
export(structure_tensor_eigenvalues)
export(structure_tensor_eigenvalues_2)
importFrom(Rcpp,sourceCpp)
......
#' Apply function to raster from package raster
#'
#' Apply function to raster from package raster
#' @param x Raster
#' @param fun function to apply
#' @param ... Further arguments to fun
#' @return Raster, after application of function fun
#' @export
#'
raster_apply <- function(x, fun, ...) {
res <- x
m <- raster::as.matrix(x)
res[] <- fun(m, ...)
names(res) <- paste(deparse(substitute(fun)), ..1, sep="_")
res
}
#' Apply multiple functions to raster from package raster
#'
#' Apply functions to raster from package raster
#' @param x Raster
#' @param sigma Scale on which to do the analysis
#' @return Rasterstack, after application of multiple functions: gaussian_smoothing, laplacian_of_gaussian, gaussian_gradient_magnitude, structure_tensor_eigenvalues, hessian_of_gaussian_eigenvalues
#' @export
#'
raster_mapply <- function(x, sigma) {
layer <- x
m <- raster::as.matrix(x)
layer[] <- gaussian_smoothing(m, sigma)
result <- layer
layer[] <- laplacian_of_gaussian(m, sigma)
result <- raster::stack(result, layer)
layer[] <- gaussian_gradient_magnitude(m, sigma)
result <- raster::stack(result, layer)
ste <- structure_tensor_eigenvalues(m, sigma)
layer[] <- ste[[1]]
result <- raster::stack(result, layer)
layer[] <- ste[[2]]
result <- raster::stack(result, layer)
ste <- hessian_of_gaussian_eigenvalues(m, sigma)
layer[] <- ste[[1]]
result <- raster::stack(result, layer)
layer[] <- ste[[2]]
result <- raster::stack(result, layer)
names(result) <- c(paste0("G_", sigma),
paste0("LG_", sigma),
paste0("GGM_", sigma),
paste0("Struct.1_", sigma),
paste0("Struct.2_", sigma),
paste0("HOG.1_", sigma),
paste0("HOG.2_", sigma))
result
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/raster_apply.R
\name{raster_apply}
\alias{raster_apply}
\title{Apply function to raster from package raster}
\usage{
raster_apply(x, fun, ...)
}
\arguments{
\item{x}{Raster}
\item{fun}{function to apply}
\item{...}{Further arguments to fun}
}
\value{
Raster, after application of function fun
}
\description{
Apply function to raster from package raster
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/raster_apply.R
\name{raster_mapply}
\alias{raster_mapply}
\title{Apply multiple functions to raster from package raster}
\usage{
raster_mapply(x, sigma)
}
\arguments{
\item{x}{Raster}
\item{sigma}{Scale on which to do the analysis}
}
\value{
Rasterstack, after application of multiple functions: gaussian_smoothing, laplacian_of_gaussian, gaussian_gradient_magnitude, structure_tensor_eigenvalues, hessian_of_gaussian_eigenvalues
}
\description{
Apply functions to raster from package raster
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment