The localfilt-file incorporates the two different filters, namely a median filter and a mean filter. They filter velocities based on the squared difference between individual velocity vectors and the median or the mean of their surrounding neighbors.
This filter is called with the following parameters:
[mu,mv]=localfilt(u,v,threshold,method,kernelsize,mask,x,y);
Typically we consider a region kernelsize * kernelsize large and compare the vector in the middle with the remaining vectors using one of the two methods 'median' or 'mean'. The threshold determines wich vectors are thrown out. In the following example we'll use a 3*3 kernel and a threshold of 2.5:
>> [lu,lv]=localfilt(gu,gv,2.5,'median',3);
In a vector field, let us consider vector number
and compare it to
the 8 vectors surrounding it (3*3 kernelsize) using the median-option.
Then the vector is rejected if it is larger than the median of all the 9
vectors plus the threshold times the standard deviation of all the
vectors, or if it is smaller than the median minus the threshold times
the standard deviation. Mathematically we can say that a vector is
considered an outlier if
This filter implies that any vector can not be ``too different'' from
its neighbors. The value of the threshold will determine exactly how different. A value between
will usually be sufficient
but users should keep in mind that large values here will result in
fewer outliers than a small number.
The kernelsize may be chosen as any odd number, but practically speaking a value of 3 (meaning a 3*3 kernel) or 5 will do just fine for most users.
Finally the input to localfilt can also include the name of the mask-file in order to save some time. If this is not specified, localfilt will loop through all the elements in the velocity matrices, even if they have already been classified as outliers by earlier filters. In this case it is vital that also the coordinate matrices, x and y, are included. Here's an example:
>> [lu,lv]=localfilt(gu,gv,2.5,'median',3,'polymask.mat',x,y);
The median of the vectors can easily be replaced with the mean value, although the former is the default method since it is more robust to other outliers in the neighborhood (see Westerweel et al. (1997)).