Author Topic: How to apply transformation matrix to an image?  (Read 2877 times)

Offline vogelito

  • Newcomer
  • Posts: 10
How to apply transformation matrix to an image?
« on: 2017 November 09 18:05:38 »
Hi, does anyone know a way to apply a given transformation matrix to an image?  Sort of like running the last part of the StarAlignment process, but providing the transformation matrix as an *input* rather than letting the actual alignment process happen.

Or... I see a Rotate process- is there something like a Translate process to go along with that?

I know there's PixelMath, but that seems like I might have to reinvent the wheel as far as interpolation algorithms (at least, if I wanted sub-pixel translations).

Thanks,
Mike

Offline vogelito

  • Newcomer
  • Posts: 10
Re: How to apply transformation matrix to an image?
« Reply #1 on: 2017 November 09 18:22:24 »
Maybe DynamicCrop would be an option to Rotate plus "Translate" by a small sub-pixel amount (by cropping off the edge, assuming DynamicCrop shifts the image back to a corner), and then PixelMath to make any larger translations and get back to original dimensions.

Not the prettiest option, though.  Any other ideas?
Thanks

Offline oldwexi

  • PixInsight Guru
  • ****
  • Posts: 627
    • Astronomy Pages G.W.
Re: How to apply transformation matrix to an image?
« Reply #2 on: 2017 November 10 03:36:20 »
The process Crop allows incremental x and y movements of the Image in positive and/or negative directions.
In process Crop  insert -10 for left- and +10 for right move the Image moves 10 Pixel to the left and keeps the size.

So, Resample, Crop and Rotation can give you subpixel translations.

Gerald

Offline vogelito

  • Newcomer
  • Posts: 10
Re: How to apply transformation matrix to an image?
« Reply #3 on: 2017 November 10 04:38:07 »
Ah, Resample! So Resample up 10x, then transform, and then resample back down to get sub-pixel accurate to 0.1 px.  That should work. I may have to find a balance between sub-pixel resolution and computation resources. 

Thanks for that and for pointing out Crop usage, Gerald!

Browsing through pcl/PixelInterpolation.h really put me to sleep last night! Probably overkill to go that route...

Mike

Offline oldwexi

  • PixInsight Guru
  • ****
  • Posts: 627
    • Astronomy Pages G.W.
Re: How to apply transformation matrix to an image?
« Reply #4 on: 2017 November 10 09:35:34 »
Hi Mike!
If you want to go into subpixel without Resample
you could uses ChannelMatch.
if You enter in all 3 channels the same  delta the whole image is translated.
Image size stays the same also.

Gerald

Offline vogelito

  • Newcomer
  • Posts: 10
Re: How to apply transformation matrix to an image?
« Reply #5 on: 2017 November 10 11:20:32 »
Ah, that's so much better. Thanks!

I'm in grayscale, so I first have to ConvertToRGBColor, then run ChannelMatch, and then do a ChannelExtraction of one color to get back to grayscale.  Excellent!  (ConvertToGrayscale seems to rescale the data, so that's why I'm not using that for the final step.)

Offline vogelito

  • Newcomer
  • Posts: 10
Re: How to apply transformation matrix to an image?
« Reply #6 on: 2017 November 10 12:43:00 »
Just a note on this approach in case anyone is interested in the future:

I ended using DynamicCrop to rotate the image instead of Rotation since the result is the same size as the original (didn't see any options in either process to control the output size).

Also, regarding the transformation data output from StarAlignment ("rotation", "dx", "dy"): note that the rotation seems to be performed about the top-left corner of the image (0,0) rather than the image center.  Rotation process doesn't seem to allow for setting the rotation center, and I couldn't get that feature to work properly in DynamicCrop.  So I ended up padding the image (Crop process, adding ImageWidth to the left and ImageHeight to the top) to get a new image (2x original size) where the original top-left is now in the center so that DynamicCrop gives the rotation I'm after.  Then Crop back off the extra ImageWidth and ImageHeight for the result.  Quite convoluted, but seems to work! 

The final result isn't quite pixel-for-pixel identical to the image that StarAlignment produces, but I think it'll work for what I'm after.

Always happy to share my obscure adventures that no one probably cares about!  Cheers!
Mike

Offline vogelito

  • Newcomer
  • Posts: 10
Re: How to apply transformation matrix to an image?
« Reply #7 on: 2017 November 11 06:35:23 »
Now I see Image.rotate and Image.translate in Object Explorer. But looking through Object Explorer and PCL/PJSR documentation and I can't find a method to apply the full homography matrix. Am I missing it, or does it just not exist?

edit 11/14/17 so as to not be a nuisance to the forum:
solution found at:  https://pixinsight.com/forum/index.php?topic=6113.0
« Last Edit: 2017 November 14 06:15:20 by vogelito »