Function tv1d::tautstring
[−]
[src]
pub fn tautstring<T>(input: &[T], lambda: T) -> Vec<T> where
T: Num + FromPrimitive + PartialOrd + AddAssign<T> + SubAssign<T> + Float + ToPrimitive,
Denoises the input values based on a tautstring algorithm by Davies P. and Kovac A. in 2001 in the paper "Local extremes, runs, strings and multiresolution".
The algorithm was implemented by Condat L. in C, which was then implemented in Rust here. The algorithm can be understood as assuming the input values as a string of data points, which is transformed taut.
Note that this algorithm is based on the running sum of the input
values. Therefore, if the sum of inputs reaches infinity, which is
more likely if the input values are very large or the input has a
large length, this algorithm may not return meaningful denoised
output. Relatedly, the input must be a float, not an integer. If
the input is an integer or large, please consider using
tv1d::condat
.
A lambda
value may provide different degrees of denoising for
different inputs, except for lambda
that is 0
.
A positive lambda
closer to 0
will result in a denoised output
that will more closely resemble the input. As lambda
increases, the
denoised output values become closer to the average of the input
values.
Panics
Panics if input vector's length is 0
or lambda
is less than 0
.
Examples
With lambda
equal to 0
, the denoised output will be the same as the input:
use tv1d; let input = vec![1.0, 2.0, 3.0, 4.0, 5.0]; let lambda = 0.0; let denoised_with_zero_lambda = tv1d::tautstring(&input, lambda); assert_eq!(denoised_with_zero_lambda, vec![1.0, 2.0, 3.0, 4.0, 5.0])
With larger lambda
, the denoised output becomes closer to the average of the input:
use tv1d; let input = vec![1.0, 2.0, 3.0, 4.0, 5.0]; let lambda = 10.0; let denoised_with_larger_lambda = tv1d::tautstring(&input, lambda); assert_eq!(denoised_with_larger_lambda, vec![3.0, 3.0, 3.0, 3.0, 3.0]);
Same lambda
may provide a different degree of denoising for a different input:
use tv1d; let input = vec![100.0, 200.0, 300.0, 400.0, 500.0]; let lambda = 10.0; let denoised_larger_inputs = tv1d::tautstring(&input, lambda); assert_eq!(denoised_larger_inputs, vec![110.0, 200.0, 300.0, 400.0, 490.0]);