Commit cf432cef authored by Thomas Dowrick's avatar Thomas Dowrick

Merge branch 'calculate_l2r_matrix' into 'master'

Calculate l2r matrix

See merge request !39
parents 0c9c0c4c 2337dd23
Pipeline #4541 passed with stages
in 8 minutes and 35 seconds
......@@ -79,3 +79,24 @@ def create_matrix_from_string(parameter_string):
]
return create_matrix_from_list(param_list)
def calculate_l2r_matrix(left_extrinsics: np.ndarray,
right_extrinsics: np.ndarray) -> np.ndarray:
""" Return the left to right transformation matrix:
l2r = L * R^-1 """
l2r = np.matmul(left_extrinsics, np.linalg.inv(right_extrinsics))
return l2r
def get_l2r_smartliver_format(l2r_matrix: np.ndarray) -> np.ndarray:
""" Convert 4x4 left to right matrix to smartliver l2r format:
R1 R2 R3
R4 R5 R6
R7 R8 R9
T1 T2 T3
"""
rot = l2r_matrix[:3, :3]
translation = l2r_matrix[:3, 3]
l2r_smartliver_format = np.vstack((rot, translation))
return l2r_smartliver_format
import pytest
import numpy as np
import sksurgeryvtk.utils.matrix_utils as mu
def test_get_l2r_matrix_smartliver_format():
l2r = np.array([[1, 2, 3, 1],
[4, 5, 6, 2],
[7, 8, 9, 3],
[0, 0, 0, 1]])
l2r_smartliver = \
mu.get_l2r_smartliver_format(l2r)
expected = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[1, 2, 3]])
assert(np.array_equal(l2r_smartliver, expected))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment