New improved release of `LocalFilters`

A new release (2.1.0) of the LocalFilters package is available. The API has been improved to make it clearer, more facilities (localmap and localreduce) are provided for local filtering operations, forward filtering is favoured (e.g. discrete correlation instead of discrete convolution) for faster computations.

Release notes:

  • New methods localmap(f, A, B) and localmap!(f, dst, A, B) yield the result of applying the function f to the values of A taken in a neighborhood defined by B around each position in A for localmap or in dst for localmap!.

  • Methods to locally reduce along given dimensions with an associative operator and using the van Herk-Gil-Werman algorithm have been renamed localreduce and localreduce!. Calling localfilter and localfilter! for that purpose is deprecated.

  • LocalFilters.ball(DimS{N}, r) now yields a centered N-dimensional ball where values are set according to whether the distance to the center is ≤ r. Compared to the previous versions, add 1//2 to r to get a similar shape. The algorithm is faster and has been fixed for N > 2. The result is identical whether r is integer or floating-point.

  • In localfilter!, argument initial may be a function to compute the state variable from the value of the source array at the current destination index. This imposes that the source and destination arrays have the same axes. This fixes issue#3.

  • In localfilter, an optional first argument, T, may be specified to provide the element type of the result.

  • Morphological methods have a slow keyword (false by default) to force not using the the van Herk-Gil-Werman algorithm.

  • localmean and localmean! accept a null keyword to specify the value of the result when the sum of weights in a neighborhood is zero.

  • Macro @public to declare public methods even though they are not exported. This concept was introduced in Julia 1.11, for older Julia versions, nothing change.

  • The algorithm to infer the result type is now based on Julia’s arithmetic rules and can cope with arguments that have units.

  • Non-exported public aliases LocalFilters.Kernel{N} and LocalFilters.Window{N}for union of types suitable to define N-dimensional kernels or windows in LocalFilters. A kernel is an array of weights implementing a local filter or an array of Booleans representing a local neighborhood. A window is an array of Booleans representing a local neighborhood. As an optimization, a box is an hyper-rectangular neighborhood with axes aligned with the Cartesian axes. Thus, a window whose values are all true is also a box and a kernel with Boolean values is also a window. The function kernel(Dims{N},B) yields an N-dimensional array for any B::LocalFilters.Kernel{N}, with Boolean values for any B::LocalFilters.Window{N}.

  • Non-exported public type LocalFilters.Box{N} is now an alias to an efficient type to represent N-dimensional boxes, that is uniformly true windows or hyper-rectangular neighborhoods. Currently, instances of this type are fast uniformly true arrays with offset axes from the StructuredArrays package and LocalFilters.Box{N} is just FastUniformArray{Bool,N,true}.

  • In local filtering operations, small integers arguments are automatically promoted to a wider integer type to avoid overflows. This is similar to what is done by base reduction methods such as sum and prod.

  • Exported method B = reverse_kernel(args...) yields a reversed kernel such that correlation by B is identical to convolution by A = kernel(args...) and conversely.

  • Building a structuring element with B = strel(T, args...) accepts args... like kernel.

  • Constants for filter ordering follow more general naming rules: FORWARD_FILTER and REVERSE_FILTER instead of ForwardFilter and ReverseFilter.

  • Filter ordering is always specified by the keyword order and is FORWARD_FILTER by default.

5 Likes