Skip to content

Commit 7d4f60b

Browse files
committed
Type alias Kernel{N}
1 parent 4b25097 commit 7d4f60b

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

src/linear.jl

+4-9
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,10 @@ for (f, order) in ((:correlate, :FORWARD_FILTER),
219219
(:convolve, :REVERSE_FILTER))
220220
f! = Symbol(f,"!")
221221
@eval begin
222-
function $f(A::AbstractArray{<:Any,N},
223-
B::Union{Window{N},AbstractArray{<:Any,N}}) where {N}
224-
return sumprod(A, kernel(Dims{N}, B); order = $order)
225-
end
226-
function $f!(dst::AbstractArray{<:Any,N},
227-
A::AbstractArray{<:Any,N},
228-
B::Union{Window{N},AbstractArray{<:Any,N}}) where {N}
229-
return sumprod!(dst, A, kernel(Dims{N}, B); order = $order)
230-
end
222+
$f(A::AbstractArray{<:Any,N}, B::Kernel{N}) where {N} =
223+
sumprod(A, kernel(Dims{N}, B); order = $order)
224+
$f!(dst::AbstractArray{<:Any,N}, A::AbstractArray{<:Any,N}, B::Kernel{N}) where {N} =
225+
sumprod!(dst, A, kernel(Dims{N}, B); order = $order)
231226
end
232227
end
233228

src/morphology.jl

+7-13
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ for f in (:closing, :opening)
359359
@eval begin
360360
# Provide destination and workspace.
361361
function $f(A::AbstractArray{<:Any,N},
362-
B::Union{Window{N},AbstractArray{<:Any,N}} = 3; kwds...) where {N}
362+
B::Kernel{N} = 3; kwds...) where {N}
363363
return $f!(similar(A), similar(A), A, B; kwds...)
364364
end
365365

@@ -411,7 +411,7 @@ See also [`top_hat`](@ref) for more details.
411411
function top_hat!(dst::AbstractArray{<:Any,N},
412412
wrk::AbstractArray{<:Any,N},
413413
A::AbstractArray{<:Any,N},
414-
B::Union{Window{N},AbstractArray{<:Any,N}}; kwds...) where {N}
414+
B::Kernel{N}; kwds...) where {N}
415415
opening!(dst, wrk, A, B; kwds...)
416416
@inbounds for i in eachindex(dst, A)
417417
dst[i] = A[i] - dst[i]
@@ -453,10 +453,8 @@ different arrays. The destination `dst` is returned.
453453
See also [`bottom_hat`](@ref) for more details.
454454
455455
"""
456-
function bottom_hat!(dst::AbstractArray{<:Any,N},
457-
wrk::AbstractArray{<:Any,N},
458-
A::AbstractArray{<:Any,N},
459-
B::Union{Window{N},AbstractArray{<:Any,N}}; kwds...) where {N}
456+
function bottom_hat!(dst::AbstractArray{<:Any,N}, wrk::AbstractArray{<:Any,N},
457+
A::AbstractArray{<:Any,N}, B::Kernel{N} = 3; kwds...) where {N}
460458
closing!(dst, wrk, A, B; kwds...)
461459
@inbounds for i in eachindex(dst, A)
462460
dst[i] -= A[i]
@@ -471,13 +469,9 @@ for (f, pf!) in ((:top_hat, :(closing!)),
471469
@eval begin
472470
# Provide destination and workspace. Out-of-place top/bottom hat filters require 2
473471
# allocations without a pre-filtering, 3 allocations with a pre-filtering.
474-
function $f(A::AbstractArray{<:Any,N},
475-
B::Union{Window{N},AbstractArray{<:Any,N}} = 3; kwds...) where {N}
476-
return $f!(similar(A), similar(A), A, B; kwds...)
477-
end
478-
function $f(A::AbstractArray{<:Any,N},
479-
B::Union{Window{N},AbstractArray{<:Any,N}},
480-
C::Union{Window{N},AbstractArray{<:Any,N}};
472+
$f(A::AbstractArray{<:Any,N}, B::Kernel{N} = 3; kwds...) where {N} =
473+
$f!(similar(A), similar(A), A, B; kwds...)
474+
function $f(A::AbstractArray{<:Any,N}, B::Kernel{N}, C::Kernel{N};
481475
order::Union{FilterOrdering,NTuple{2,FilterOrdering}} = FORWARD_FILTER,
482476
kwds...) where {N}
483477
B_order = order isa FilterOrdering ? order : order[1]

src/types.jl

+18-3
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,29 @@ struct Indices{S<:IndexStyle} <: Function end
2929
"""
3030
LocalFilters.Window{N}
3131
32-
is the union of types of arguments suitable to define a simple `N`-dimensional
33-
hyper-rectangular sliding window and that can be converted into a kernel by the
34-
[`LocalFilters.kernel`](@ref) method.
32+
is the union of types for an argument `B` to be suitable to define a simple
33+
`N`-dimensional hyper-rectangular sliding window and that can be converted into a
34+
`Box{N}`, that is a `N`-dimensional uniformly true kernel array by [`kernel(Dims{N},
35+
B)`](@ref LocalFilters.kernel).
36+
37+
38+
a kernel
39+
by the [`LocalFilters.kernel`](@ref) method.
3540
3641
"""
3742
const Window{N} = Union{Axis,NTuple{N,Axis},NTuple{2,CartesianIndex{N}},
3843
CartesianIndices{N}}
3944

45+
"""
46+
LocalFilters.Kernel{N}
47+
48+
is the union of types for an argument `B` to be suitable to define a `N`-dimensional
49+
kernel or filter that can be converted into a `N`-dimensional kernel array by
50+
[`kernel(Dims{N}, B)`](@ref LocalFilters.kernel).
51+
52+
"""
53+
const Kernel{N} = Union{Window{N},AbstractArray{<:Any,N}}
54+
4055
"""
4156
const LocalFilters.Box{N} = FastUniformArray{Bool,N,true}
4257

0 commit comments

Comments
 (0)