Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion about gauss_f #3

Open
roflmaostc opened this issue Aug 2, 2022 · 8 comments
Open

Discussion about gauss_f #3

roflmaostc opened this issue Aug 2, 2022 · 8 comments

Comments

@roflmaostc
Copy link
Member

roflmaostc commented Aug 2, 2022

Hi!
See:

function gaussf(img::AbstractArray{T}, sigma=1.0; dtype=Float32) where (T <: Real)

I would probably implement it like:

function filter_gauss(img::AbstractArray{T}, sigma=one(T), dims=1:ndims(img)) where (T <: Real)
    shiftdims = dims[2:end]
    f = rfft(img, dims)
    return irfft(f .* ifftshift(gaussian(T, size(f), 
                                                     offset=CtrRFT, 
                                                     sigma=size(img) ./ (T(2π) .*sigma)),
                                      shiftdims), 
                     size(img, dims[1]), dims)
end
@RainerHeintzmann
Copy link
Member

Hi. Strictly speaking a Gaussian filter is seperable. So ideally it should be implemented as a separable convolution. Why did you rename it and why did you remove the dtype argument, which should however be a dispatch type in my code to be fast. The user should be able to call gaussf on an Int array type and obtain a Float32 arraytype.

@roflmaostc
Copy link
Member Author

Keywords don't participate in dispatch unfortunately.

For me the new name is more clear.

@roflmaostc
Copy link
Member Author

rfft of an int array already throws an error, so this works anyway only for floating

@RainerHeintzmann
Copy link
Member

The name gaussf stems from the name in DipImage and has now been used already by some other packages. I would therefore recommend to stick to it. As for the dispatch, we could make two versions, one with and one without the type dispatch. I vaguely remember that some other functions also have a named dtype argument. I wonder, how they deal with the dispatch problem.
The fact that rfft throws an error is good, but I thought that is may be a nice feature that Gaussian filtering by default casts to Float32. But I guess one could require the user to write gaussf(Float32.(image)). So do we move this function to FourierTools.jl?

@roflmaostc
Copy link
Member Author

Any objections to this implementation?

function filter_gauss(img::AbstractArray{T}, sigma=one(T), dims=1:ndims(img)) where (T <: Real)
    shiftdims = dims[2:end]
    f = rfft(img, dims)
    return irfft(f .* ifftshift(gaussian(T, size(f), 
                                                     offset=CtrRFT, 
                                                     sigma=size(img) ./ (T(2π) .*sigma)),
                                      shiftdims), 
                     size(img, dims[1]), dims)
end

@RainerHeintzmann
Copy link
Member

If you really want to rename it, I suggest "filter_gaussian" to be more in agreemend with the English term "Gaussian filter" and with the function "gaussian" which the implementation uses.

The IndexFunArrays.jl function needs a named argument sigma, whereas this one is not named. Would it be more compatible (nargs... forwarding) and more explicit to leave it named also for this implementation?

As for the implementation, it is good. It would break compatibility with the previous version where I up-casted, but that can be tolerated, especially since the name changes and it is moved to FourierTools.jl.

@roflmaostc
Copy link
Member Author

roflmaostc commented Aug 13, 2022

function filter_gaussian(img::AbstractArray{T};
                              sigma=one(T), dims=1:ndims(img)) where (T <: Real)
    shiftdims = dims[2:end]
    f = rfft(img, dims)
    return irfft(f .* ifftshift(gaussian(T, size(f), 
                                                     offset=CtrRFT, 
                                                     sigma=size(img) ./ (T(2π) .*sigma)),
                                      shiftdims), 
                     size(img, dims[1]), dims)
end

@RainerHeintzmann
Copy link
Member

great!. Should one also include the option for Gaussian low-pass (this one), high-pass and band-pass?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants