quatrope / astroalign

A tool to align astronomical images based on asterism matching
MIT License
140 stars 44 forks source link

Use Lanczos interpolation for affine warp #97

Open Messier-16 opened 6 months ago

Messier-16 commented 6 months ago

The Bicubic interpolation algorithm is not great for astronomy image subtraction; Lanczos is better. However, scikit does not support this, so I used the OpenCV implementation.

In any case, there should also be an option to pass in an argument to change the interpolation method (even to nearest neighbors instead of bicubic).

martinberoiz commented 6 months ago

Hello,

Thanks for your PR I am currently out of town for a conference. I will look into it next week.

In the meantime, it seems that your PR introduces a new dependency (OpenCV). While I'm all for adding interpolation options (see #58) I'm very reluctant to introduce new dependencies to the package. Maybe I can consider OpenCV as an optional dependency.

Messier-16 commented 6 months ago

Got it -- let me know what you think once you get to it! I'm not sure that Lanczos is flux-preserving either.

martinberoiz commented 6 months ago

Hi, I checked up on scikit-image to see if they had a Lanczos option and they don't. But in the warp method, the inverse_map argument accepts a function that does the mapping. This gives enough flexibility to inject there an exact or Lanczos interp. It has the caveat that it will be slower than providing a matrix but I think it's worth a try.

There are several projects on GitHub with implementations of Lanczos interp.

Do you have any reference where I can read more on why bi-cubic is not good for astronomy image subtraction? or why Lanczos is better?

Messier-16 commented 5 months ago

https://pixinsight.com/doc/tools/StarAlignment/StarAlignment.html

This tool might have some insight for that, as they use it. The reason I believe it is because I personally did some empirical testing on my own data and the alignment was better.