@@ -36,6 +36,14 @@ function product2d(kf)
3636 k1[1 ]. * k1[2 ], k2[1 ]. * k2[2 ]
3737end
3838
39+ """
40+ kern = box(m, n)
41+ kern = box((m, n, ...))
42+
43+ Return a box kernel computing a moving average. `m, n, ...` specify the size of the kernel, which is centered around zero.
44+ """
45+ box(sz:: Dims ) = broadcast(* , KernelFactors. box(sz). .. )
46+
3947"""
4048```julia
4149 diff1, diff2 = sobel()
@@ -380,6 +388,40 @@ function Base.convert(::Type{AbstractArray}, L::Laplacian{N}) where N
380388end
381389_reshape(L:: Laplacian{N} , :: Val{N} ) where {N} = L
382390
391+ """
392+ laplacian2d(alpha::Number)
393+
394+ Construct a weighted discrete Laplacian approximation in 2d. `alpha` controls the weighting of the faces
395+ relative to the corners.
396+
397+ # Examples
398+
399+ ```jldoctest
400+ julia> Kernel.laplacian2d(0) # the standard Laplacian
401+ 3×3 OffsetArray(::Matrix{Float64}, -1:1, -1:1) with eltype Float64 with indices -1:1×-1:1:
402+ 0.0 1.0 0.0
403+ 1.0 -4.0 1.0
404+ 0.0 1.0 0.0
405+
406+ julia> Kernel.laplacian2d(1) # a corner-focused Laplacian
407+ 3×3 OffsetArray(::Matrix{Float64}, -1:1, -1:1) with eltype Float64 with indices -1:1×-1:1:
408+ 0.5 0.0 0.5
409+ 0.0 -2.0 0.0
410+ 0.5 0.0 0.5
411+
412+ julia> Kernel.laplacian2d(0.5) # equal weight for face-pixels and corner-pixels.
413+ 3×3 OffsetArray(::Matrix{Float64}, -1:1, -1:1) with eltype Float64 with indices -1:1×-1:1:
414+ 0.333333 0.333333 0.333333
415+ 0.333333 -2.66667 0.333333
416+ 0.333333 0.333333 0.333333
417+ ```
418+ """
419+ function laplacian2d(alpha:: Number = 0 )
420+ lc = alpha/ (1 + alpha)
421+ lb = (1 - alpha)/ (1 + alpha)
422+ lm = - 4 / (1 + alpha)
423+ return centered([lc lb lc; lb lm lb; lc lb lc])
424+ end
383425
384426"""
385427 gabor(size_x,size_y,σ,θ,λ,γ,ψ) -> (k_real,k_complex)
0 commit comments