JuliaImages / ImageFiltering.jl

Julia implementations of multidimensional array convolution and nonlinear stencil operations
Other
99 stars 49 forks source link

off-by-1 bug in freqkernel #206

Closed JeffFessler closed 3 years ago

JeffFessler commented 3 years ago

The wrapindex function in freqkernel has an off-by-1 bug that incorrectly embeds the kernel into the array that one uses with FFT to get the frequency response. MWE illustration:

h = centered(reshape([1], 1, 1)) # 2D Kronecker impulse whose frequency response should be uniform "1"
freqkernel(h, (4,4)) # complex output :(

4×4 Array{Complex{Float64},2}:
  1.0+0.0im   0.0+1.0im  -1.0+0.0im   0.0-1.0im
  0.0+1.0im  -1.0+0.0im   0.0-1.0im   1.0+0.0im
 -1.0+0.0im   0.0-1.0im   1.0+0.0im   0.0+1.0im
  0.0-1.0im   1.0+0.0im   0.0+1.0im  -1.0+0.0im

(The magnitude is correct, but not the phase.)

In contrast, that "other software framework" that uses psf2otf has the correct frequency response:

psf2otf(1, [4 4])

ans =

     1     1     1     1
     1     1     1     1
     1     1     1     1
     1     1     1     1

I plan to submit a PR with both a correction and this MWE as a test case.