Commit ded8fcf4 authored by Mian Asbat Ahmad's avatar Mian Asbat Ahmad

Issue #14: compute_fre function moved to errors.py

The function compute_fre is moved from  to a new file .
parent d4515bf2
# -*- coding: utf-8 -*-
"""Functions for point based registration using Orthogonal Procrustes."""
import numpy as np
from sksurgerycore.algorithms.procrustes import validate_procrustes_inputs
def compute_fre(fixed, moving, rotation, translation):
"""
Computes the Fiducial Registration Error, equal
to the root mean squared error between corresponding fiducials.
:param fixed: point set, N x 3 ndarray
:param moving: point set, N x 3 ndarray of corresponding points
:param rotation: 3 x 3 ndarray
:param translation: 3 x 1 ndarray
:returns: Fiducial Registration Error (FRE)
"""
# pylint: disable=assignment-from-no-return
validate_procrustes_inputs(fixed, moving)
transformed_moving = np.matmul(rotation, moving.transpose()) + translation
squared_error_elementwise = np.square(fixed
- transformed_moving.transpose())
square_distance_error = np.sum(squared_error_elementwise, 1)
sum_squared_error = np.sum(square_distance_error, 0)
mean_squared_error = sum_squared_error / fixed.shape[0]
fre = np.sqrt(mean_squared_error)
return fre
......@@ -41,32 +41,9 @@ def validate_procrustes_inputs(fixed, moving):
raise ValueError("fixed and moving should have "
+ "the same number of points (rows)")
def compute_fre(fixed, moving, rotation, translation):
"""
Computes the Fiducial Registration Error, equal
to the root mean squared error between corresponding fiducials.
:param fixed: point set, N x 3 ndarray
:param moving: point set, N x 3 ndarray of corresponding points
:param rotation: 3 x 3 ndarray
:param translation: 3 x 1 ndarray
:returns: Fiducial Registration Error (FRE)
"""
# pylint: disable=assignment-from-no-return
validate_procrustes_inputs(fixed, moving)
transformed_moving = np.matmul(rotation, moving.transpose()) + translation
squared_error_elementwise = np.square(fixed
- transformed_moving.transpose())
square_distance_error = np.sum(squared_error_elementwise, 1)
sum_squared_error = np.sum(square_distance_error, 0)
mean_squared_error = sum_squared_error / fixed.shape[0]
fre = np.sqrt(mean_squared_error)
return fre
# pylint: disable=invalid-name, line-too-long
# pylint: disable=invalid-name, line-too-long
def orthogonal_procrustes(fixed, moving):
"""
Implements point based registration via the Orthogonal Procrustes method.
......
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