You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the code filter_gaussian(zeros(5)) returns [NaN, NaN, NaN, NaN, NaN].
Not that it is too important to be able to filter zero arrays, but in my case I want to filter images column-wise and it could happen to have columns of zeros. For such cases I would prefer the package to return the correct result rather than work around this bug.
When I looked into the code, I found that the division by the sum might cause the error (its line 315 in src/fourier_filtering.jl) or line 5 in the following snippet.
function filter_gaussian!(arr, sigma=eltype(arr)(1); real_space_kernel=true, border_in=(real(eltype(arr)))(0), border_out=(real(eltype(arr))).(2 ./ (pi .* sigma)), kwargs...)
if real_space_kernel
mysum = sum(arr)
fourier_filter!(arr, gaussian; transform_win=true, sigma=sigma, kwargs...)
arr .*= (mysum/sum(arr))
return arr
else
return fourier_filter!(arr; border_in=border_in, border_out=border_out, kwargs...)
end
end
For this particular case a short check that sum(arr) != 0 should do the job, but I am not sure how this fits in the philosophy of the whole package and if there are functions having the same problems
The text was updated successfully, but these errors were encountered:
Thanks a lot for picking this up. The error actually goes a bit deeper. Using the sum of the data is just not the right way to normalize it. E.g. an array can be zero integral also by containing positive and negative values. I thus shifted the (optional) normalization to the kernel and introduced an optional argument, which seems more sensible.
Such a normalization is advantageous for real-space Gaussians which are first transformed and then used for filtering. This is the preferred mode for small kernel sizes. Here is the pull request.
the code
filter_gaussian(zeros(5))
returns [NaN, NaN, NaN, NaN, NaN].Not that it is too important to be able to filter zero arrays, but in my case I want to filter images column-wise and it could happen to have columns of zeros. For such cases I would prefer the package to return the correct result rather than work around this bug.
When I looked into the code, I found that the division by the sum might cause the error (its line 315 in src/fourier_filtering.jl) or line 5 in the following snippet.
For this particular case a short check that
sum(arr) != 0
should do the job, but I am not sure how this fits in the philosophy of the whole package and if there are functions having the same problemsThe text was updated successfully, but these errors were encountered: