Image to layout alignment using 3 landmarks registrartion

Hello Matthias-

This question is more of a geometric question but I'm sure you will have a very short and simple code that can help a lot:
Say I want to align an image to a layout. Both the image and the layout have a set of 3 matching respective landmarks.
So the image landmarks set is: (Im1x,Im1y) (Im2x,Im2y) (Im3x,Im3y) and the layout landmark set is (La1x,La1y) (La2x,La2y) (La3x,La3y)

Can you suggest a code that will transpose the image to the layout using above landmarks coordinates?

Thanks for your time and effort! Itamar


  • edited February 2020

    Hi Itamar,

    The method which achieves this is "Matrix3d.adjust". Here is a sample:

    # Landmarks image (in pixel coordinates)
    landmarks_img = [
      pya.DPoint(100, 100),
      pya.DPoint(200, 200),
      pya.DPoint(200, 101)
    # Landmarks layout (in micrometers)
    landmarks_layout = [
      pya.DPoint(105.0, 25.0),
      pya.DPoint(110.0, 30.0),
      pya.DPoint(110.0, 25.0)
    matrix = pya.Matrix3d()
    matrix.adjust(landmarks_img, landmarks_layout, pya.Matrix3d.AdjustAll, -1)

    The output is (beautified):

    (0.05,      0,      100) 
    (-0.000505, 0.0505, 20) 
    (0,         0,      1)

    which is a displacement of 100, 20 plus a scaling by 0.05 plus a small shear I have induced because I used a y value of 101 for the third image point instead of 100.

    This matrix you can then put into the "matrix" property of your pya.Image object to place it according to the landmark mapping.


  • Thank you so much for it Matthias

Sign In or Register to comment.