Commit de13e976 authored by Matt Clarkson's avatar Matt Clarkson

Merge branch '10-validate-4x4'

parents 4e7d7170 9e4cbf97
......@@ -27,9 +27,10 @@ scikit-surgerycore is part of the `SNAPPY`_ software project, developed at the `
Features
--------
* Configuration manager
* Transform manager
* Proscurtes point based registration
* A Configuration Manager to load parameters from a .json file
* A Transform Manager to manage combinations of 4x4 transformation matrices
* Corresponding point (i.e Landmark) based registration, based on `Arun et al., 1987`_.
* Validation functions, checking a numpy array is a camera matrix, rotation matrix, rigid transform etc.
Installing
----------
......@@ -99,4 +100,5 @@ Supported by `Wellcome`_ and `EPSRC`_.
.. _`EPSRC`: https://www.epsrc.ac.uk/
.. _`contributing guidelines`: https://weisslab.cs.ucl.ac.uk/WEISS/SoftwareRepositories/SNAPPY/scikit-surgerycore/blob/master/CONTRIBUTING.rst
.. _`license file`: https://weisslab.cs.ucl.ac.uk/WEISS/SoftwareRepositories/SNAPPY/scikit-surgerycore/blob/master/LICENSE
.. _`Arun et al., 1987`: http://doi.ieeecomputersociety.org/10.1109/TPAMI.1987.4767965
......@@ -14,12 +14,12 @@ setup(
name='scikit-surgerycore',
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
description='scikit-surgerycore contains commonly used Image Guided Surgery algortihms and tools',
description='scikit-surgerycore contains commonly used Image Guided Surgery algorithms and tools',
long_description=long_description,
long_description_content_type='text/x-rst',
url='https://weisslab.cs.ucl.ac.uk/WEISS/SoftwareRepositories/SNAPPY/scikit-surgerycore',
author='Matt Clarkson',
author_email='YOUR-EMAIL@ucl.ac.uk',
author_email='m.clarkson@ucl.ac.uk',
license='BSD-3 license',
classifiers=[
'Development Status :: 3 - Alpha',
......@@ -53,7 +53,6 @@ setup(
install_requires=[
'six>=1.10',
'numpy>=1.11',
'pillow',
],
entry_points={
......
......@@ -105,3 +105,22 @@ def validate_translation_column_vector(matrix):
if matrix.shape[1] != 1:
raise ValueError("Translation matrix should have 1 column.")
return True
def validate_rigid_matrix(matrix):
"""
Validates that a matrix is a 4x4 rigid transform.
:param matrix: rigid transform
:raises: TypeError, ValueError if not
:return: True
"""
if not isinstance(matrix, np.ndarray):
raise TypeError('Rigid matrix is not an np.ndarray')
if len(matrix.shape) != 2:
raise ValueError("Rigid matrix should have 2 dimensions.")
if matrix.shape[0] != 4:
raise ValueError("Rigid matrix should have 4 rows.")
if matrix.shape[1] != 4:
raise ValueError("Rigid matrix should have 4 columns.")
validate_rotation_matrix(matrix[0:3, 0:3])
......@@ -138,3 +138,27 @@ def test_translation_matrix_invalid_because_too_few_rows():
def test_translation_matrix_valid():
translation_matrix = np.zeros((3, 1))
assert vm.validate_translation_column_vector(translation_matrix)
def test_rigid_matrix_invalid_because_wrong_type():
with pytest.raises(TypeError):
vm.validate_rigid_matrix(None)
def test_rigid_matrix_invalid_because_wrong_dimensions():
with pytest.raises(ValueError):
vm.validate_rigid_matrix(np.ones((2, 1, 2)))
def test_rigid_matrix_invalid_because_wrong_rows():
with pytest.raises(ValueError):
vm.validate_rigid_matrix(np.ones((2, 2)))
def test_rigid_matrix_invalid_because_wrong_columns():
with pytest.raises(ValueError):
vm.validate_rigid_matrix(np.ones((4, 2)))
def test_rigid_matrix_valid_because_identity():
vm.validate_rigid_matrix(np.eye(4))
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