Manual registration using elastix

96 views
Skip to first unread message

ibtissam Essadik

unread,
Nov 19, 2020, 10:30:10 AM11/19/20
to elastix-imageregistration

Hello,

I'm trying to use elastix Tool for the registration (Affine transformation ) of the two 3D images.

After used elastix  command line, I obtain a parameter file and a Registered image generated by elastix.

My aim is to use this matrix transformation & center of rotation existed in the parameter file to register the moving image and get a Registered image similar to the one obtained by elastix.  However, my manually registration results were always a little bit different from elastix generated. 

I am wondering if I missed something in  the transformation matrix or i didn't apply it correctly. 

Any suggestions are greatly appreciated.

My Python script:


import numpy as np

import pandas as pd 

import matplotlib.pyplot as plt

import SimpleITK as sitk

import cv2

import nibabel as nib


from scipy.spatial import distance

from statistics import mean

from pandas import DataFrame

path_vol1 = "C:/Users/Essadik/Desktop/DATA_IRMs/TOF_BET/Vol1_bet.nii"

vol = sitk.GetArrayFromImage(sitk.ReadImage(path_vol1))

img_transformed = np.zeros((vol.shape[0],vol.shape[1],vol.shape[2])) 

img_transformed.shape

matrice=np.array([[1.026340 ,-0.075878 ,0.019792,6.766561], 

                   [0.019973 ,1.058883 ,0.128099,-4.116563 ],

                   [-0.067282 ,-0.205729 ,1.053152 ,6.330935],

                   [0, 0, 0,1]])

center = np.array([[1, 0,0, -0.3606814668], [0, 1,0, 12.8406273633] ,[0, 0,1, 0.2839643048], [0, 0, 0,1]] )

center_inverse = np.array([[1, 0,0, 0.3606814668], [0, 1,0, -12.8406273633], [0, 0,1, -0.2839643048], [0, 0, 0,1]] )

total_matrix = center @ matrice @ center_inverse

for i  in range(vol.shape[0]): 

    for j in range(vol.shape[1]): 

        for k in range(vol.shape[2]):

            k_xfm,j_xfm,i_xfm, _ = total_matrix @ np.array([k,j, i,1]) 

            pixel_data = 0

            if( k_xfm >= 0 and k_xfm < vol.shape[2] and j_xfm >=0 and j_xfm < vol.shape[1] and i_xfm >=0 and i_xfm < vol.shape[0] ):

                pixel_data = vol[int(i_xfm), int(j_xfm),int(k_xfm)]

            img_transformed[i, j,k] = pixel_data


new_img=img_transformed.astype(np.uint16)

img_recal = sitk.GetImageFromArray(new_img)

sitk.WriteImage(img_recal, "vol1_manual_reg1.mha")


The transform file:

(Transform "AffineTransform")

(NumberOfParameters 12)

(TransformParameters 1.026340 -0.075878 0.019792 0.019973 1.058883 0.128099 -0.067282 -0.205729 1.053152 6.766561 -4.116563 6.330935)

(InitialTransformParametersFileName "NoInitialTransform")

(HowToCombineTransforms "Compose")


// Image specific

(FixedImageDimension 3)

(MovingImageDimension 3)

(FixedInternalImagePixelType "float")

(MovingInternalImagePixelType "float")

(Size 512 512 192)

(Index 0 0 0)

(Spacing 0.3515625000 0.3515625000 0.5000032187)

(Origin -96.0032653809 -73.2788696289 -42.7602081299)

(Direction 0.9979060389 -0.0646703700 -0.0011317127 0.0645305101 0.9966330591 -0.0505802205 0.0043989440 0.0504012784 0.9987193602)

(UseDirectionCosines "true")


// AdvancedAffineTransform specific

(CenterOfRotationPoint -0.3606814668 12.8406273633 0.2839643048)


// ResampleInterpolator specific

(ResampleInterpolator "FinalBSplineInterpolator")

(FinalBSplineInterpolationOrder 3)


// Resampler specific

(Resampler "DefaultResampler")

(DefaultPixelValue 0.000000)

(ResultImageFormat "mhd")

(ResultImagePixelType "short")

(CompressResultImage "false")


Best regards, 

ESSADIK Ibtissam



M.St...@lumc.nl

unread,
Nov 25, 2020, 4:23:48 AM11/25/20
to elastix-imag...@googlegroups.com

Dear Ibtissam,


You could inspect the source code of this transformation to know what happens precisely:


https://github.com/SuperElastix/elastix/blob/develop/Common/Transforms/itkAdvancedMatrixOffsetTransformBase.hxx


With kind regards,

Marius Staring







From: elastix-imag...@googlegroups.com <elastix-imag...@googlegroups.com> on behalf of ibtissam Essadik <ibti....@gmail.com>
Sent: 19 November 2020 4:26 PM
To: elastix-imageregistration
Subject: [elastix-imageregistration] Manual registration using elastix
 

Hello,

I'm trying to use elastix Tool for the registration (Affine transformation ) of the two 3D images.

After used elastix  command line, I obtain a parameter file and a Registered image generated by elastix.

My aim is to use this matrix transformation & center of rotation existed in the parameter file to register the moving image and get a Registered image similar to the one obtained by elastix.  However, my manually registration results were always a little bit different from elastix generated. 

I am wondering if I missed something in  the transformation matrix or i didn't apply it correctly.

My Python script:

--
You received this message because you are subscribed to the Google Groups "elastix-imageregistration" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elastix-imageregis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elastix-imageregistration/2f29f71c-8108-4d9d-a44a-07cdcaebaa50n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages