transformix -def movingPoints.txt -out outFolder -tp outFolder/TransformParameters.0.txt -m FixedImage.nrrdtransformix -in MovingImage.nrrd -out outFolder -tp outFolder/TransformParameters.0.txt -m FixedImage.nrrd
import numpy as npimport sys, math print("******************************************************")print (" Transform Points ")print("******************************************************")np.set_printoptions(precision=2)np.set_printoptions(suppress=True)print("---------------------------------------------------")print(" Define input ")
print("---------------------------------------------------")# Input Points
p=np.array([[-1.1499 , 4.96146 ,-3.73897 ],[ 1.12107 , 6.15124 ,-4.09615 ], [ 2.56265 , 7.01562 ,-4.0416 ], [ 4.1089 , 7.87024 ,-3.37502 ], [ 5.23609 , 8.08297 ,-1.92341 ], [ 5.37945 , 7.84559 , 0.0562932], [ 4.72791 , 6.72648 , 1.12291 ], [ 3.17306 , 5.88972 , 1.40773 ], [ 2.09212 , 5.46035 , 0.298082], [ 1.39364 , 5.93 ,-0.860716], [ 1.80359 , 6.98823 ,-1.9811 ], [ 2.79237 , 8.16489 ,-1.89504 ], [ 3.54371 , 8.4603 ,-0.688138], [ 3.18755 , 8.01944 , 0.458005], [ 1.99834 , 7.59242 , 0.468096], [ 1.50188 , 7.8538 ,-0.489043], [ 2.28302 , 8.5749 ,-0.594259]])print(p)#elastix parameters
ep=np.array([ -0.369236, -0.074973, 0.177428, -0.895437, -7.486193, -9.989277])print("---------------------------------------------------")print(" elastixParameters to Rotation Matrix ")print("---------------------------------------------------")[rx,ry,rz]=ep[0:3];
[tx,ty,tz]=ep[3:6];Ms = []
cosx = math.cos(rx)sinx = math.sin(rx)Ms.append(np.array([[1, 0 , 0 ], [0, cosx, -sinx], [0, sinx, cosx]]))cosy = math.cos(ry)siny = math.sin(ry)Ms.append(np.array( [[cosy , 0, siny], [0 , 1, 0 ], [-siny, 0, cosy]]))cosz = math.cos(rz)sinz = math.sin(rz)Ms.append(np.array([[cosz, -sinz, 0], [sinz, cosz, 0], [0 , 0 , 1] ]))if Ms: mt = reduce(np.dot, Ms[::-1]) # convert to 4x4 m= np.zeros((4,4)) ; m[3,3]=1 ; m[0:3,0:3]=mt # add translations m[0:3,3]=[tx,ty,tz]else: m= np.eye(3)print("---------------------------------------------------")print(" displacement field ")print("---------------------------------------------------")# get the displacement vector = len(p) d=np.zeros((len(p),4))#print(p_dis)for i in range(0,len(p)): dt=np.ones(4); dt[0:3] = dt[0:3] * p[i] #print(dt) np.matmul(m,dt,d[i]) print(d[i])print("---------------------------------------------------")print(" new transformed points ")
print("---------------------------------------------------")# get the new points locations pn=np.zeros((len(p),3))for i in range(0,len(p)):
pn[i]= p[i] + d[i][0:3] print(pn[i]) --
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-imageregistration+unsubsc...@googlegroups.com.
Visit this group at https://groups.google.com/group/elastix-imageregistration.
To view this discussion on the web visit https://groups.google.com/d/msgid/elastix-imageregistration/afba5081-14b3-4861-a9b9-877e03967246%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
FixedIm Dtype = 32-bit floatMovingIm Dtype = 32-bit float
FixedIm Size = (212, 256, 30)MovingIm Size = (192, 256, 35)
FixedIm Spacing = (0.8984375, 0.8984375, 5.0)
MovingIm Spacing = (0.9375, 0.9375, 5.0)
FixedIm Origin = (-104.92378234863281, -152.4906463623047, -9.22148609161377)
MovingIm Origin = (-115.14457702636719, -124.83148193359375, -10.8151273727417)
I also have a DICOM-RTSTRUCT file containing contour points belonging to FixedIm. I've already transformed the contour points to physical coordinates taking into account the ImagePositionPatient, ImageOrientationPatient, PixelSize, etc. I registered MovingIm to FixedIm and I’m satisfied with the results.

The plot above shows the result at one slice location. It may be difficult to see them, but Fixedm and RegIm have contours (in red) overlaid. The contour points are those belonging to FixedIm as described above.
I wanted to then transform the contour points so they can be overlaid onto MovingIm. I created a file called inputpoints.pcs with the contour points in the required format:
point
number_of_points
point1_x point1_y point1_z
point2_x point2_y point2_z
…
Then I transformed the contour points:
TransformixImFilt = sitk.TransformixImageFilter()
TransformixImFilt.SetTransformParameterMap(ElastixImFilt.GetTransformParameterMap())
TransformixImFilt.SetFixedPointSetFileName(FixedContourPtsFname)
# Need to explicitely tell elastix that the image is 3D since by default it will
# only transform to 2D:
TransformixImFilt.SetMovingImage(MovingIm)
TransformixImFilt.Execute()
But when I opened the outputpoints.txt file it became apparent that something is wrong (including perhaps my interpretation) - the x and y indices exceed the dimensions of the images themselves. Following was the first line of outputpoints.txt:
Point 0 ; InputIndex = [ 252 359 14 ] ; InputPoint = [ 126.344037 171.830275 -54.501356 ] ; OutputIndexFixed = [ 248 353 26 ] ; OutputPoint = [ 126.638100 184.489069 3.193988 ] ; Deformation = [ 0.294064 12.658794 57.695343 ] ; OutputIndexMoving = [ 220 356 4 ]
As for the z indices, although they do not exceed the z-dimension, the input and output indices differ by ~10, whereas the reality they should differ by a few slice positions.
Does anyone have any idea why the x and y values of InputIndex, OutputIndexFixed and OutputIndexMoving exceed the x and y dimensions of FixedIm, FixedIm and MovingIm respectively? Likewise, InputPoint and OutputPoint exceed the physical dimensions of the FixedIm and MovingIm.
Has something gone wrong or have I completely misinterpretted what the indices and points in outputpoints.txt represent?
If the latter, can someone please direct me to a source of info since I've been unable to find any level of detail from the manual that covers the output file.
Best regards,
Cristiano
To unsubscribe from this group and stop receiving emails from it, send an email to elastix-imageregistration+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to elastix-imageregis...@googlegroups.com.
Visit this group at https://groups.google.com/group/elastix-imageregistration.
To view this discussion on the web visit https://groups.google.com/d/msgid/elastix-imageregistration/afba5081-14b3-4861-a9b9-877e03967246%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "elastix-imageregistration" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elastix-imageregistration/zMs_jA3YZ9w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elastix-imageregis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elastix-imageregistration/46328d8f-7db2-4af8-afe4-6f651151cc0f%40googlegroups.com.
I'm curious to know what led you to take that approach? Did you find Elastix/SimpleElastix too difficult to get to work?
Regards,
Cristiano