Getting Started | Documentation | Glish | Learn More | Programming | Contact Us |
Version 1.9 Build 1556 |
|
Package | utility | |
Module | mathematics |
include "image.g"
datafilter | Construct a Datafilter tool |
done | Destroy this tool |
filter | Filter a data array |
medianclip | Median clip a data array |
Summary
The Datafilter tool provides some simple filtering operations for Glish arrays.
Here is an example where we create a noisy sinusoid with outliers. First we filter the data; you can see how the median filter removes outliers (as well as compressing the noise). Then we also median clip the original data showing how the outliers are effectively removed.
# Generate Gaussian distribution - include 'randomnumbers.g' - n := 500 - r := randomnumbers(); - g := r.normal(0.0, 0.5, n); - r.done() # Generate data ; sin wave plus noise - x := (1:n) / 10 / pi - y := sin(x) + g # - include 'pgplotter.g' - p0 := pgplotter () - p0.plotxy (x, y, title='Sin + noise', plotlines=F) # Now add some outliers - ii := 1:n - for (i in ii[ii%50 == 0]) { y[i] *:= 20; } # - p1 := pgplotter() - p1.plotxy (x, y, title='Sin + noise + outliers', plotlines=F) # Generate Datafilter tool - include 'datafilter.g' - df := datafilter(); # Median filter returns filtered data - y2 := df.filter (y, method='median', width=10) # - p2 := pgplotter() - p2.plotxy (x, y2, title='Median filtered', plotlines=F) # Median clip returns a Boolean mask - m := df.medianclip (y, width=10, clip=5) # - p3 := pgplotter() - p3.plotxy (x, y, title='Median clipped', plotlines=F, mask=m)