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