Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reader for linear transforms in .lta files #10

Open
pieper opened this issue Nov 4, 2022 · 1 comment
Open

Add reader for linear transforms in .lta files #10

pieper opened this issue Nov 4, 2022 · 1 comment

Comments

@pieper
Copy link
Contributor

pieper commented Nov 4, 2022

Some freesurfer tools (e.g. robust register) output RAS to RAS transforms in .lta format, which is not supported by this extension.

This snippet of Slicer code loads the file and the result appears to be correct, but I don't know how much variability there is in the format or if it's even documented. I don't know if the other lines in the file have any particular meaning.

ltaPath = "/data/affine.lta"
lta = open(ltaPath).read().split("\n")
mat = vtk.vtkMatrix4x4()
for row in range(4):
    print(row, lta[8+row])
    elems = lta[8+row].split(" ")
    for col in range(4):
        mat.SetElement(row, col, float(elems[col]))
transform = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLLinearTransformNode")
transform.SetMatrixTransformToParent(mat)

Here's an example .lta file:

# transform file /mnt/c/Users/mbrudfors/Projects/neurosurgical-atlas/Data/Ture-028-2022-10-07-Scene/Data/affine.lta
# created by mbrudfors on Thu Oct 27 11:07:23 2022

type      = 1 # LINEAR_RAS_TO_RAS
nxforms   = 1
mean      = 80.0000 107.0000 116.0000
sigma     = 10000.0000
1 4 4
1.004464387893677e+00 6.770147383213043e-02 -1.217468529939651e-01 -1.079803466796875e+00 
-9.191786497831345e-02 9.181172251701355e-01 -1.942616552114487e-01 3.466661071777344e+01 
1.277457177639008e-01 1.542867422103882e-01 1.004784703254700e+00 3.302518463134766e+01 
0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 1.000000000000000e+00 
src volume info
valid = 1  # volume info valid
filename = /mnt/c/Users/mbrudfors/Projects/neurosurgical-atlas/Data/Ture-028-2022-10-07-Scene/Data/ss_Moving_Volume.nii.gz
volume = 160 220 220
voxelsize = 1.000000000000000e+00 1.000000000000000e+00 1.000000000000000e+00
xras   = 1.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00
yras   = 0.000000000000000e+00 1.000000000000000e+00 0.000000000000000e+00
zras   = -0.000000000000000e+00 -0.000000000000000e+00 1.000000000000000e+00
cras   = 1.167999267578125e+00 -1.290399932861328e+01 1.227996826171875e+00
dst volume info
valid = 1  # volume info valid
filename = /mnt/c/Users/mbrudfors/Projects/neurosurgical-atlas/Data/Ture-028-2022-10-07-Scene/Data/ss_Fixed_Volume.nii.gz
volume = 512 512 392
voxelsize = 5.077999830245972e-01 5.077999830245972e-01 5.000000000000000e-01
xras   = -1.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00
yras   = 0.000000000000000e+00 -1.000000000000000e+00 0.000000000000000e+00
zras   = 0.000000000000000e+00 0.000000000000000e+00 1.000000000000000e+00
cras   = -2.550689697265625e+00 2.907742309570312e+01 2.825936889648438e+01
@lassoan
Copy link
Contributor

lassoan commented Nov 5, 2022

The code snippet could be used to create a scripted file reader - see this example: https://github.com/Slicer/Slicer/blob/main/Modules/Scripted/ImportItkSnapLabel/ImportItkSnapLabel.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants