emmt / LocalFilters.jl

Multi-dimensional local filters (convolution, mathematical morphology, etc.) for Julia.
Other
36 stars 5 forks source link

Error with `bilateralfilter` #4

Closed JeffFessler closed 2 years ago

JeffFessler commented 2 years ago

Getting errors with basic bilateral filtering:

bilateralfilter(rand(10,10), 3., 4.)

ERROR: MethodError: no method matching bilateralfilter!(::Type{Float64}, ::Matrix{Float64}, ::Matrix{Float64}, ::LocalFilters.BilateralFilter.var"#7#8"{Float64}, ::Float64)
Closest candidates are:
  bilateralfilter!(::Type{T}, ::AbstractArray{Td, N}, ::AbstractArray{Ta, N}, ::Function, ::Real, ::Any) where {T<:AbstractFloat, Td<:Real, Ta<:Real, N} at /Users/fessler/.julia/packages/LocalFilters/uuKNH/src/bilateral.jl:119
  bilateralfilter!(::AbstractArray{Td, N}, ::AbstractArray{Ta, N}, ::Any...) where {Td<:Real, Ta, N} at /Users/fessler/.julia/packages/LocalFilters/uuKNH/src/bilateral.jl:58
  bilateralfilter!(::Type{T}, ::AbstractArray{Td, N}, ::AbstractArray{Ta, N}, ::Function, ::LocalFilters.Kernel{Tg, N, A} where A<:AbstractArray{Tg, N}) where {T<:AbstractFloat, Td, Ta, Tg<:Real, N} at /Users/fessler/.julia/packages/LocalFilters/uuKNH/src/bilateral.jl:67
  ...
Stacktrace:
 [1] bilateralfilter!(#unused#::Type{Float64}, dst::Matrix{Float64}, A::Matrix{Float64}, σr::Float64, args::Float64)
   @ LocalFilters.BilateralFilter ~/.julia/packages/LocalFilters/uuKNH/src/bilateral.jl:114
 [2] bilateralfilter(::Type{Float64}, ::Matrix{Float64}, ::Float64, ::Vararg{Float64, N} where N)
   @ LocalFilters.BilateralFilter ~/.julia/packages/LocalFilters/uuKNH/src/bilateral.jl:27
 [3] bilateralfilter(::Matrix{Float64}, ::Float64, ::Float64)
   @ LocalFilters.BilateralFilter ~/.julia/packages/LocalFilters/uuKNH/src/bilateral.jl:21
 [4] top-level scope
   @ REPL[5]:1

I've tried both the master branch and the tagged release.

BioTurboNick commented 2 years ago

8 months later - same issue

emmt commented 2 years ago

Sorry for the very late answer. The doc. is wrong, for the spatial filter, you must specify a function (or a number which is the standard deviation of a Gaussian used as this function) and a window (a RectangularBox or an odd integer interpreted as the width of the window in all dimensions). I will quickly fix the doc. and push an updated version. Following your example, you can do something like:

bilateralfilter(rand(10,10), 3., 4., 7)

to use a 7×7 window along the dimensions of the input array.

JeffFessler commented 2 years ago

It would be nice if there was a default rectangular window width (say, 4\sigma) but it's OK to require it too. Thanks!

emmt commented 2 years ago

Following your idea, I plan to have a default window width (an odd number) given by:

# Default window width for a given standard deviation σ.
default_width(σ::Real) = 2*round(Int, 3σ) + 1

I took instead of to avoid too large windows. Is that suitable to you?

JeffFessler commented 2 years ago

I would call that 6σ (because of the 2*) and that's actually what I had in mind originally. Thanks!

BioTurboNick commented 2 years ago

Looks great! I appreciate the changes coming.

emmt commented 2 years ago

@JeffFessler you're right, it's 6σ, I wrote "a window of size ±3σ" in the doc. and I sublitted a new version (1.2.1)

JeffFessler commented 2 years ago

Closed via https://github.com/emmt/LocalFilters.jl/commit/17edf70873cb81f32eb3f097fb179b10ff362a16 and related commits.