DIPlib / diplib

Quantitative Image Analysis in C++, MATLAB and Python
https://diplib.org
Apache License 2.0
211 stars 48 forks source link

Polar coordinate bilateral filter #155

Open davidedelvento opened 2 months ago

davidedelvento commented 2 months ago

Component DIPlib

Describe the problem that this feature would solve Create a bilateral filter in polar coordinates, allowing automatic filtering images of the solar corona, to achieve results similar to http://www.zam.fme.vutbr.cz/~druck/Eclipse/index.htm (done with proprietary software) or https://www.astropix.com/html/eclipse/2017_total_solar_eclipse_hdr_corona.html (and many others, done with a tedious and error-prone approach in Photoshop or other similar program). Of course that would require preliminary alignment and other things which are out of scope for this issue request (but we can still discuss them if appropriate)

Describe your suggested solution to the problem AdaptiveGauss already allows for use of polar coordinates (or other image transformation approaches), however for this purpose the BilateralFilter is much better suited -- if it had polar coordinates. I have only given a high-level review of the code, but it appears that I can simply use the already-written AdaptiveGauss image transformations in BilaterFilter and be done with it? And just to be clear, I am proposing to do this work myself.

Additional context Do you think this is something that you'd accept a PR for? If so, and knowing the internal details which I have only cursory looked at so far, do you think it'd be better to put the AdaptiveGausse image transformation in a dedicated nonlinear source file to share them between AdaptiveGauss and BilaterFilter, or do you think the two would need to be substantially different that such a share is not worth it?

Kind-of-related: somebody pointed me to https://arxiv.org/abs/1811.02308 which I have not read yet. Could it be something worth incorporating at this stage, or would it be better do it before, after or at a completely orthogonal time?

crisluengo commented 2 months ago

Yes, we'd be very happy with a PR for this. How to organize the code depends on how much can be shared. But it's definitely good to share code where possible.

Do also take a look at dip::CoherenceEnhancingDiffusion, it might fill the role you're looking for.

Oh, the dip_ArcFilter mentioned in #20 is a bilateral filter applied along a line whose orientation and curvature are controlled independently for each pixel. This one probably does exactly what you're after. A colleague from my PhD days, Tuan Pham, wrote it in 2003... We never ported it to the new DIPlib because I was unsure how to share code between it and dip::AdaptiveGauss and dip::AdaptiveBanana -- on the outside they look similar, but the implementations are quite different. But it is the basis for a bunch of interesting functionality that he implemented, including a filter to remove JPEG compression artefacts.

So, if you're interested in this functionality, maybe you're willing to port this old C code over? I'm happy to help, since you're likely not familiar with all of the infrastructure available in DIPlib, and also the old C code can sometimes be a bit hard to read...

davidedelvento commented 2 months ago

This sounds great, thanks Cris! I've been busy with personal matters this weekend, but I will dig with more details into the old C code and the various discussed options and get back to you with my plan.