Releases: emmt/LocalFilters.jl
v2.1.0
LocalFilters v2.1.0
-
New methods
localmap(f, A, B)andlocalmap!(f, dst, A, B)yield the result of applying the functionfto the values ofAtaken in a neighborhood defined byBaround each position inAforlocalmapor indstforlocalmap!. -
Methods to locally reduce along given dimensions with an associative operator and using the van Herk-Gil-Werman algorithm have been renamed
localreduceandlocalreduce!. Callinglocalfilterandlocalfilter!for that purpose is deprecated. -
LocalFilters.ball(DimS{N}, r)now yields a centeredN-dimensional ball where values are set according to whether the distance to the center is≤ r. Compared to the previous versions, add1//2torto get a similar shape. The algorithm is faster and has been fixed forN > 2. The result is identical whetherris integer or floating-point. -
In
localfilter!, argumentinitialmay 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
slowkeyword (falseby default) to force not using the the van Herk-Gil-Werman algorithm. -
localmeanandlocalmean!accept anullkeyword to specify the value of the result when the sum of weights in a neighborhood is zero. -
Macro
@publicto 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}andLocalFilters.Window{N}for union of types suitable to defineN-dimensional kernels or windows inLocalFilters. 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 functionkernel(Dims{N},B)yields anN-dimensional array for anyB::LocalFilters.Kernel{N}, with Boolean values for anyB::LocalFilters.Window{N}. -
Non-exported public type
LocalFilters.Box{N}is now an alias to an efficient type to representN-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 theStructuredArrayspackage andLocalFilters.Box{N}is justFastUniformArray{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
sumandprod. -
Exported method
B = reverse_kernel(args...)yields a reversed kernel such that correlation byBis identical to convolution byA = kernel(args...)and conversely. -
Building a structuring element with
B = strel(T, args...)acceptsargs...likekernel. -
Constants for filter ordering follow more general naming rules:
FORWARD_FILTERandREVERSE_FILTERinstead ofForwardFilterandReverseFilter. -
Filter ordering is always specified by the keyword
orderand isFORWARD_FILTERby default.
Merged pull requests:
- Bump julia-actions/cache from 1 to 2 (#10) (@dependabot[bot])
v2.0.1
LocalFilters v2.0.1
- Fix import of unused function that has been removed (see PR #9).
Merged pull requests:
- Remove unused import of to_int (#9) (@Octogonapus)
v2.0.0
LocalFilters v2.0.0
This is a major release.
Version 2 of LocalFilters better integrates in the Julia ecosystem as fewer
custom types are introduced:
-
To represent hyper-rectangular Cartesian sliding windows, former type
RectangularBoxhas been replaced byCartesianIndices. -
Kernels with values or neighborhoods with more complex shape than
hyper-rectangular Cartesian sliding windows are all represented by abstract
arrays (with boolean entries to define a neighborhood). The former type
LocalFilters.Kernelis no longer provided. To account for offsets in the
indexing, it is recommended to use the
OffsetArrayspackage. The
methodLocalFilters.centered(B)can be called to yield a kernel or a
neighborhood whose index ranges are approximately centered. This method is
not exported to avoid conflicts (for instance, it has a slightly different
semantic inOffsetArrays).
Version 2 of LocalFilters provides more general, more consistent, and better
optimized methods:
-
Most filtering operations take an optional ordering argument
ordright
before the argument, sayB, specifying the kernel or the neighborhood. If
ordisForwardFilter,Bis indexed as in discrete correlations;
otherwise, ifordisReverseFilter,Bis indexed as in discrete
convolutions. The default ordering isForwardFilteras this is the most
natural for many filters (except discrete convolutions of course) and as it
yields faster code. For symmetric kernels and neighborhoods, the ordering has
no incidence on the result. InLocalFiltersversion 1, indexing as in
discrete convolutions was the only rule. -
The API of
localfilters!have changed a bit, the syntax is
localfilters!(dst,A,ord=ForwardFilter,B,initial,update,final=identity)with
dstthe destination,Athe source,ordthe direction of the filter,B
the kernel or neighborhood of the filter,initialthe value of the initial
state variable,updatea method to update the state variable, andfinala
method to yield the result to store in the destinationdstgiven the value
of the state variable at the end of visiting the neighborhood. -
Constructor
LocalFilters.Indicesand helper method
LocalFilters.localindicesmay be used as an alternative tolocalfilters!
to build custom filters. -
In all filters, a simple neighborhood that is a hyper-rectangular Cartesian
sliding window can be specified in many different ways. Such a neighborhood
is represented by an instance ofCartesianIndiceswith unit step ranges.
MethodLocalFilters.kernel(Dims{N},args...)can be called to build such a
N-dimensional neighborhood from argument(s)args.... -
Non-exported
LocalFilters.ballmethod is now type stable. Call
LocalFilters.ball(Dims{N},r)instead ofLocalFilters.ball(N,r). -
The
strelmethod uses uniform arrays from package
StructuredArraysto
represent structuring elements with the same value for all valid indices. -
In out-of-place filters, the destination array needs not be of the same size
as the source array. The local filtering operation is applied for all indices
of the destination, using boundary conditions to extract the corresponding
value in the source array. Currently only flat boundary conditions are
implemented but this may change in the future.
Guidelines for porting code from version 1 to version 2
If the high level API was used, there should be almost no changes, except for
non-symmetric kernels or neighborhoods for which ReverseFilter ordering must
be specified to mimic the former behavior.
At a lower level, the following changes should be done:
-
Non-exported union
LocalFilters.IndexIntervalhas been replaced by
LocalFilters.Axisto represent the type of any argument that can be used to
define a sliding window axis: an integer length or an integer-valued index
range. -
Non-exported method
LocalFilters.ismmboxhas been replaced by
LocalFilters.is_morpho_math_box. -
Non-exported method
LocalFilters.cartesian_regionhas been replaced by the
more general and better designed exported methodkernel. -
Replace
Neighborhood{N}(args...)bykernel(Dims{N}, args...)and
Neighborhood{N}orRectangularBox{N}byLocalFilters.Box{N}. -
Replace
LocalFilters.KernelbyOffsetArrays.OffsetArray. -
Update the arguments of
localfilters!:initialis no longer a method but
the initial state value,updatehas the same semantics, andfinaljust
yields the result of the local filter given the last state value. By default,
finalisidentity. -
Replace
LocalFilters.ball(N,r)byLocalFilters.ball(Dims{N},r)which is
type-stable.
Release 1.2.0 of LocalFilters
- Scalar and array element type restrictions have been relaxed for most filter methods. This is to let users apply these methods to non-standard types.
- Some optimizations.
- Syntax
Kernel(T,G,B)has been deprecated in favor ofKernel{T}(G,B). - Rename some unexported methods.
v1.1.0
Release 1.0.0 of LocalFilters
New features and changes:
-
Compatibility with Julia 0.6 to 1.1 without loss of efficiency (thanks to the
newcartesianregionmethod). -
Add van Herk / Gil & Werman algorithm. Some filters have a huge speed-up
when this algorithm can be used. -
Add the bilateral filter.
-
Provide the
strelmethod to build structuring elements. -
Method
cartesianregionis provided to return either aCartesianIndices{N}
or aCartesianRange{CartesianIndex{N}}(whichever is the most efficient
depending on Julia version) to loop over theN-dimensional indices of
anything whose type belongs toCartesianRegion{N}. Type
CartesianRegion{N}is an union of the types of anything suitable to define
a Cartesian region of indices. -
Method
anchorhas been removed because its result depends on the indexing
of the embedded array of kernel coefficients.
First official release of LocalFilters.jl
This package implements multi-dimensional local filters for Julia (convolution, mathematical morphology, etc.). Local filters are defined by specific operations combining each value of a source array with the values in a local neighborhood which may have any size, shape and dimensionality. Predefined local filters are provided as well as means to simply implement custom filters.