Skip to content

Add Butterworth Filter#242

Open
ashwinn-v wants to merge 5 commits intoJuliaImages:masterfrom
ashwinn-v:butter
Open

Add Butterworth Filter#242
ashwinn-v wants to merge 5 commits intoJuliaImages:masterfrom
ashwinn-v:butter

Conversation

@ashwinn-v
Copy link
Copy Markdown

In response to feature request #240
Please let me know if there are any fixes to be done on the code.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 17, 2022

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.17%. Comparing base (424523c) to head (a848ed0).
⚠️ Report is 36 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #242      +/-   ##
==========================================
+ Coverage   91.86%   92.17%   +0.30%     
==========================================
  Files          12       12              
  Lines        1647     1648       +1     
==========================================
+ Hits         1513     1519       +6     
+ Misses        134      129       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ashwinn-v ashwinn-v changed the title Butter Add Butterworth Filter Jan 17, 2022
Copy link
Copy Markdown
Member

@johnnychen94 johnnychen94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs and tests are needed.

Some docstrings in ImageFiltering are written in Julia pre-1.0 age, so you can follow the guideline in https://docs.julialang.org/en/v1/manual/documentation/#man-documentation. I personally prefer a verbose docstring, e.g., the docstring for Gabor in #235. You can also follow how unit tests are written in that PR.

ashwinn-v and others added 3 commits January 17, 2022 20:01
Style fix

Co-authored-by: Johnny Chen <johnnychen94@hotmail.com>
#Citation
Selesnick, Ivan W., and C. Sidney Burrus. "Generalized digital Butterworth filter design." IEEE Transactions on signal processing 46.6 (1998): 1688-1694.
"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line here would cause ?Kernel.butterworth giving nothing.

Suggested change

end

"""
butterworth(n,Wn,ls{tuple}) -> k
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation, and :: for type annotation.

Suggested change
butterworth(n,Wn,ls{tuple}) -> k
butterworth(n, Wn, ls::Dims) -> k


"""
butterworth(n,Wn,ls{tuple}) -> k
Returns a multidimensional dimensional Butterworth kernel contained in an OffsetArray(::Matrix{Float64})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one extra new line after the signature.

Suggested change
Returns a multidimensional dimensional Butterworth kernel contained in an OffsetArray(::Matrix{Float64})
Returns a multidimensional dimensional Butterworth kernel contained in an OffsetArray(::Matrix{Float64})

Comment on lines +516 to +518
- `n` is the order of the filter
- `Wn` is the normalized cutoff frequency
- `ls` is the size of the kernel
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need indentation for the markdown list

Suggested change
- `n` is the order of the filter
- `Wn` is the normalized cutoff frequency
- `ls` is the size of the kernel
- `n` is the order of the filter
- `Wn` is the normalized cutoff frequency
- `ls` is the size of the kernel


- `n` is the order of the filter
- `Wn` is the normalized cutoff frequency
- `ls` is the size of the kernel
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you use ls for kernel size instead of sz? The former seems to come from the math equation of butterworth kernel. Can you also add the equation to the docstring so that people immediately knows what n, Wn, ls means and how they affects the results?

@. 1/(1+(sqrt(2)-1)*(df(R)/Wn)^nn)
end

butterworth(n::Real, Wn::Real, ls::Integer) = butterworth(n, Wn, (ls,ls))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This convenient method only makes sense when butterworth is 2D only; otherwise, we should not add it.

Comment on lines +245 to +246
@test Kernel.butterworth(a,b,(3,3)) == Kernel.butterworth(a,b,3)
@test Kernel.butterworth(a,b,(4,4)) == Kernel.butterworth(a,b,4)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need some numerical tests here, can you test against one or two results generated from other frameworks that has butterworth implemented or manual calculated results? Also do remember to add a comment on how the references are generated.

We also need to test that the kernel axis are "centered". For instance, the axes should be (-1:1, -1:1) when kernel size is (3, 3). Also need to test the even case as well.

Selesnick, Ivan W., and C. Sidney Burrus. "Generalized digital Butterworth filter design." IEEE Transactions on signal processing 46.6 (1998): 1688-1694.
"""

function butterworth(n::Real, Wn::Real, ls::Tuple{Integer,Integer})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like if we do

Suggested change
function butterworth(n::Real, Wn::Real, ls::Tuple{Integer,Integer})
function butterworth(n::Real, Wn::Real, ls::NTuple{N,Integer}) where N

we immediately get a N-dimensional implementation as the docstring says: "multidimensional dimensional Butterworth kernel". Can you check this and if it works, add 1d and 3d tests? Also don't forget to update the docstring OffsetArray(::Matrix{Float64}).

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

Successfully merging this pull request may close these issues.

2 participants