-
-
Notifications
You must be signed in to change notification settings - Fork 668
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
FrequencyBandImageFilter accepts lambdas for filtering frequencies #149
Conversation
Should FrequencyBandImageFilter be derived from the UnaryGeneratorFilter? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great!!! Functors working with frequencies... the dream.
I wonder if we could refactor all the functor love into a base class.
And the old behavior (the boxFunctor), just out in its own header as a functor struct (a class with operator() and the options RadialBand etc, as members)
Modules/Filtering/ImageFrequency/test/itkFrequencyBandImageFilterTest.cxx
Outdated
Show resolved
Hide resolved
Modules/Filtering/ImageFrequency/test/itkFrequencyBandImageFilterTest.cxx
Outdated
Show resolved
Hide resolved
@blowekamp maybe it should. I was busy trying to get the functionality, It didn't even occur to me that I could derive it from UnaryGenerator. But since the functor should take the FrequencyIterator instead of just the pixel value, I am afraid deriving from UnaryGenerator might be more trouble than it is worth. Also, UnaryFunctor filter existed when FrequencyBandImageFilter was originally written. It must have made some sense not to derive it from UnaryFunctor. |
The great lambdas/functor work of @blowekamp in UnaryGenerator was posterior to the development of this filter. |
@phcerdan Do not confuse UnaryGenerator filter which is pretty new, and UnaryFunctor filter which is very old. |
@phcerdan If backwards compatibility is not a major issue, we could refactor the filter as you propose. What do others think? @thewtex @hjmjohnson @blowekamp |
+1 for separating the FrequencyBandImageFilter into a "Frequency Generator Filter" base class and a "Box Functor". They could come together into the current class similar to the "AddImageFilter" combines the BinaryGeneratorImageFilter and the AddFunctor. |
I think the only module using it (heaviliy) is ITKIsotropicWavelets, and I can fix that when needed. Also, to avoid breakage of backwards compatibility, we can create the functor, and then create a FrequencyBandImageFilter just plugging together the base class and the new |
It seems I agree with @blowekamp 😄 (submitted the comment almost at the same time) |
I don't think the frequency classes have been in a final release, so there should not be backwards compatibility concerns. 🆕 |
Great! Let me verify that this works as intended, then I can polish it per suggestions. |
By the way, |
A better name for what is now known as Edit: Butterworth is also a BandPassFunctor. |
A better name for And maybe we can change the name from |
Thanks all. This is good work. |
With the new GitHub workflow hopefully it is easier to manage topic branches. Please separate the nice documentation improvement in itkUnaryGeneratorFilter into separate commit to help keep a clear history. |
This is working as expected. I will refactor this patch to separate the box functor into its own class and add additional Butterworth functor. |
In the end I did not add Butterworth filter here, but as its implementation is short it can be defined in appropriately adjusted form by the user. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good!
Modules/Filtering/ImageFrequency/include/itkUnaryFrequencyDomainFilter.hxx
Outdated
Show resolved
Hide resolved
Modules/Filtering/ImageFrequency/include/itkUnaryFrequencyDomainFilter.h
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BoxFunctor should be changed to the more descriptive BandPassFunctor. Box is not describing what the functor is doing.
Modules/Filtering/ImageFrequency/include/itkFrequencyBandImageFilter.hxx
Outdated
Show resolved
Hide resolved
I think this is ready for merging. Can you re-review please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thanks!!
Looks good! Does this class of filters support streaming? If not then |
@blowekamp why should the OutputRequestedRegion be enlarged? |
The default behavior of the ITK pipeline (e.g. ImageToImageFilter) is to have the requested region of the output be copied to the inputs. This enables streaming for basic filters like the unary functors etc.. This filter operates with frequency space, I believe an output pixel needs more information than just the corresponding input pixel. One way to disable streaming is to overload Other options depend on if and how the filter can stream. |
This filter is templated over the frequency iterator. The iterator uses the meta-information to know the frequency of the currently iterated pixel. And a reference to this iterator is passed to the functor, so it can access the frequency etc. Which means that this filter should probably be able to stream. I haven't tested that, though. |
If the filter only has part of the input, then the boundary conditions would likely cause difference frequencies to be processes by the iterator. It may be that the filter can produce an arbitrary output but needs the full input. In that case the |
This is essentially a per-pixel filter. The only complication is that the iterator "knows" the frequency/index of the pixel, which is used as a criteria for modifying the value. I don't think the input's region needs to be expanded. |
Ok, I got how the iterator operate now. Thanks! |
For me, it helps to think that the input and output images are already in the frequency domain. The only role of the frequency iterators is to avoid the change of the algorithms depending on the Fourier transform or frequency layout. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some warnings identified by the macOS build:
https://open.cdash.org/viewBuildError.php?type=1&buildid=5622223
@thewtex I fixed that with the latest push. All checks are now passing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice @dzenanz !
Some minor issues noted inline.
Modules/Filtering/ImageFrequency/include/itkFrequencyBandImageFilter.hxx
Outdated
Show resolved
Hide resolved
} | ||
else // Cut-off box taking into account max absolute frequency. | ||
{ | ||
w = freqIt.GetFrequency(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
w
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wector frequency? uv? @phcerdan might give the answer 😄
Modules/Filtering/ImageFrequency/include/itkUnaryFrequencyDomainFilter.h
Outdated
Show resolved
Hide resolved
Modules/Filtering/ImageFrequency/include/itkUnaryFrequencyDomainFilter.h
Outdated
Show resolved
Hide resolved
* This filter is templated over a TFrequencyIterator depending on the | ||
* frequency layout of the input image. | ||
* Images in the dual space can be acquired experimentally, from scattering exaperiments or other techniques. | ||
* The layout of these images is the same as spatial domain images. Use \ref FrequencyImageRegionIteratorWithIndex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the meaning of this sentence? Can it be reworded to clarify that meaning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reworded it. @phcerdan could double-check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Modules/Filtering/ImageFrequency/include/itkUnaryFrequencyDomainFilter.h
Outdated
Show resolved
Hide resolved
UnaryFrequencyDomainFilter accepts lambdas for filtering frequencies. Functor setting is modeled after UnaryGeneratorImageFilter.
Sorry, I was unplugged on the weekend, sorry for not answering on time. But I would have approved, |
This filter should enable custom filtering via the functor, e.g. implementing Butterworth algorithm.