quatrope / astroalign

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

Add "inverse" on affine transform in Astroalign #78

Closed lcx366 closed 2 years ago

lcx366 commented 2 years ago

The inverse operation on affine transform is very common in practice, however, Astroalign lacks that functionality. I thought of two ways for implementing the inverse transform. The first way is by adding a method on class 'transf', such as transf_inverse = transf.inverse(); the second way is by adding an argument to the function matrix_tranfform, such as pixel_coord2 = aa.matrix_transform(pixel_coord1,transf.params,inverse=True). I think the second way is slightly simpler and can be achieved by simply computing the inverse matrix.

martinberoiz commented 2 years ago

Hi,

Actually the transform returned class is a scikit-image's SimilarityTransform. Your intuition was actually right, it does come with an inverse method.

Here is some tutorial on how to use it: https://scikit-image.org/docs/stable/auto_examples/transform/plot_geometric.html#basics

In scikit-image's parlance, if you want to apply the inverse to an image you would warp it with the inverse:

target = transform.warp(source, transf.inverse)

Is this what you were referring to?

If not you can always call astroalign with source and target interchanged to get the inverse, although I understand is not practical in many cases, or even desirable to re-do the calculation.

martinberoiz commented 2 years ago

I'll close this but feel free to continue the conversation if needed.