diff --git a/src/imfilter.jl b/src/imfilter.jl index 403bc86..0ef4850 100644 --- a/src/imfilter.jl +++ b/src/imfilter.jl @@ -858,7 +858,7 @@ function buffered_planned_irfft(a::AbstractArray{T}) where {T} end function planned_fft(A::AbstractArray{T,N}, - kernel::Tuple{AbstractArray,Vararg{AbstractArray}}, + kernel::ProcessedKernel, border::BorderSpecAny=Pad(:replicate) ) where {T,N} bord = border(kernel, A, Algorithm.FFT()) @@ -870,6 +870,8 @@ function planned_fft(A::AbstractArray{T,N}, bfp3 = buffered_planned_irfft(_A) return Algorithm.FFT(bfp1, bfp2, bfp3) end +planned_fft(A::AbstractArray, kernel, border::AbstractString) = planned_fft(A, kernel, borderinstance(border)) +planned_fft(A::AbstractArray, kernel::Union{ArrayLike,Laplacian}, border::BorderSpecAny) = planned_fft(A, factorkernel(kernel), border) function filtfft(A, krn, planned_rfft1::Function, planned_rfft2::Function, planned_irfft::Function) B = complex(planned_rfft1(A)) diff --git a/test/2d.jl b/test/2d.jl index e9db4c0..e9000dc 100644 --- a/test/2d.jl +++ b/test/2d.jl @@ -50,6 +50,7 @@ end # Dense inseparable kernel kern = [0.1 0.2; 0.4 0.5] kernel = OffsetArray(kern, -1:0, 1:2) + border = Inner() for img in (imgf, imgi, imgg, imgc) targetimg = zeros(typeof(img[1]*kern[1]), size(img)) targetimg[3:4,2:3] = rot180(kern) .* img[3,4] @@ -76,12 +77,12 @@ end @test_throws MethodError imfilter!(CPU1(Algorithm.FIR()), ret, img, kernel, border, Algorithm.FFT()) end targetimg_inner = OffsetArray(targetimg[2:end, 1:end-2], 2:5, 1:5) - @test @inferred(imfilter(img, kernel, Inner())) ≈ targetimg_inner - @test @inferred(imfilter(f32type(img), img, kernel, Inner())) ≈ float32.(targetimg_inner) + @test @inferred(imfilter(img, kernel, border)) ≈ targetimg_inner + @test @inferred(imfilter(f32type(img), img, kernel, border)) ≈ float32.(targetimg_inner) for alg in (Algorithm.FIR(), Algorithm.FIRTiled(), Algorithm.FFT(), planned_fft(img, kernel, border)) - @test @inferred(imfilter(img, kernel, Inner(), alg)) ≈ targetimg_inner - @test @inferred(imfilter(f32type(img), img, kernel, Inner(), alg)) ≈ float32.(targetimg_inner) - @test @inferred(imfilter(CPU1(alg), img, kernel, Inner())) ≈ targetimg_inner + @test @inferred(imfilter(img, kernel, border, alg)) ≈ targetimg_inner + @test @inferred(imfilter(f32type(img), img, kernel, border, alg)) ≈ float32.(targetimg_inner) + @test @inferred(imfilter(CPU1(alg), img, kernel, border)) ≈ targetimg_inner end end # Factored kernel diff --git a/test/nd.jl b/test/nd.jl index de29ece..d6fb0a7 100644 --- a/test/nd.jl +++ b/test/nd.jl @@ -129,7 +129,8 @@ end img = trues(10,10,10) kernel = centered(trues(3,3,3)/27) for border in ("replicate", "circular", "symmetric", "reflect", Fill(true)) - for alg in (Algorithm.FIR(), Algorithm.FIRTiled(), Algorithm.FFT(), planned_fft(img, kernel, border)) + # TODO: add support for boolean images in planned_fft + for alg in (Algorithm.FIR(), Algorithm.FIRTiled(), Algorithm.FFT()) @test imfilter(img, kernel, border) ≈ img end end diff --git a/test/runtests.jl b/test/runtests.jl index 2b9c343..955179d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,6 +6,12 @@ using ImageQualityIndexes import StaticArrays using Random +function typestring(::Type{T}) where T # from https://github.com/JuliaImages/ImageCore.jl/pull/133 + buf = IOBuffer() + show(buf, T) + String(take!(buf)) +end + @testset "ImageFiltering" verbose=true begin @testset "Project meta quality checks" begin # Ambiguity test @@ -27,12 +33,6 @@ using Random end end -function typestring(::Type{T}) where T # from https://github.com/JuliaImages/ImageCore.jl/pull/133 - buf = IOBuffer() - show(buf, T) - String(take!(buf)) -end - include("compat.jl") include("border.jl") include("nd.jl") @@ -50,7 +50,6 @@ include("models.jl") CUDA_INSTALLED = false try - global CUDA_INSTALLED # This errors with `IOError` when nvidia driver is not available, # in which case we don't even need to try `using CUDA` run(pipeline(`nvidia-smi`, stdout=devnull, stderr=devnull))