[ITK-users] Extracting image coordinate transform matrix

Yaniv, Ziv Rafael (NIH/NLM/LHC) [C] zivrafael.yaniv at nih.gov
Tue Aug 1 11:12:53 EDT 2017


Hello Ramana,

Curious what your use case is, as I can’t think of the reason to do the computation the way you want to.
In any case, the code below does what you want:

image_direction = image.GetDirection()
image_spacing = image.GetSpacing()
image_origin = image.GetOrigin()

dim = 3
matrix = [m*s for m,s in zip(image_direction, image_spacing*dim)]

index_2_physical = sitk.AffineTransform(dim)
index_2_physical.SetMatrix(matrix)
index_2_physical.SetTranslation(image_origin)

physical_2_continous_index = index_2_physical.GetInverse()


If you need the indexes as integers you will need to transform the point, round the result (np.rint) and then astype(int):
np.rint(physical_2_continous_index.TransformPoint([-82.76, 33.32, 101.5])).astype(int)

        hope this helps
                  Ziv
 

On 8/1/17, 8:22 AM, "Ramana C" <rc1515 at ic.ac.uk> wrote:

    Hi All,
    
    I am using SimpleITK in Python (but help for any ITK/SimpleITK version would
    be appreciated too!). 
    
    I am looking for a way to extract (or construct) the 4 by 4 transformation
    matrix from an image that lets me transform physical space coordinates to
    voxel coordinates of the image grid, and vice-versa.
    
    I know that the image class has methods such as
    image.TransformIndexToPhysicalPoint, but I was hoping that it would be
    possible to extract the transformation matrix itself.
    
    Any help with this would be greatly appreciated.
    
    -Ramana
    
    
    
    
    
    
    
    
    --
    View this message in context: http://itk-users.7.n7.nabble.com/Extracting-image-coordinate-transform-matrix-tp38537.html
    Sent from the ITK - Users mailing list archive at Nabble.com.
    _____________________________________
    Powered by www.kitware.com
    
    Visit other Kitware open-source projects at
    http://www.kitware.com/opensource/opensource.html
    
    Kitware offers ITK Training Courses, for more information visit:
    http://www.kitware.com/products/protraining.php
    
    Please keep messages on-topic and check the ITK FAQ at:
    http://www.itk.org/Wiki/ITK_FAQ
    
    Follow this link to subscribe/unsubscribe:
    http://public.kitware.com/mailman/listinfo/insight-users
    



More information about the Insight-users mailing list