HSI Calibration Validation

Check if the computed soft-iron and hard-iron matrices correspond to the parametrization of an ellipsoid in the real numbers domain and if meet the positive definite condition for the soft-iron.

Conditions
  • cond1: The rank of matrix S should be 3.
  • cond2: The rank of matrix E should be 4.
  • cond3: The determinant of matrix E should be less than 0.
  • cond4: All eigenvalues of matrix S should be positive.
  • cond5: All eigenvalues of the soft-iron matrix should be positive.
Explanation
  • S: A matrix derived from the inverse of the soft-iron matrix. It is used to check the positive definite condition.
  • P: A matrix derived from the hard-iron matrix and the inverse of the soft-iron matrix. It represents the linear part of the ellipsoid equation.
  • d: A scalar value derived from the hard-iron matrix and the inverse of the soft-iron matrix. It represents the constant part of the ellipsoid equation.
  • E: A block matrix constructed from S, P, and d. It represents the full ellipsoid equation in matrix form.

Parameters:

Name Type Description Default
soft_iron ndarray

Soft-iron matrix as a (3, 3) numpy array.

required
hard_iron ndarray

Hard-iron matrix as a (3, 1) numpy array.

required

Returns:

Name Type Description
bool bool

Whether the soft-iron and hard-iron parametrize a ellipsoid in the

bool

real numbers domain.

Source code in magyc/utils/utils.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def hsi_calibration_validation(soft_iron: np.ndarray, hard_iron: np.ndarray) -> bool:
    """
    Check if the computed soft-iron and hard-iron matrices correspond to the
    parametrization of an ellipsoid in the real numbers domain and if meet
    the positive definite condition for the soft-iron.

    Conditions:
        - cond1: The rank of matrix S should be 3.
        - cond2: The rank of matrix E should be 4.
        - cond3: The determinant of matrix E should be less than 0.
        - cond4: All eigenvalues of matrix S should be positive.
        - cond5: All eigenvalues of the soft-iron matrix should be positive.

    Explanation:
        - S: A matrix derived from the inverse of the soft-iron matrix. It is
             used to check the positive definite condition.
        - P: A matrix derived from the hard-iron matrix and the inverse of the
             soft-iron matrix. It represents the linear part of the ellipsoid
             equation.
        - d: A scalar value derived from the hard-iron matrix and the inverse of
             the soft-iron matrix. It represents the constant part of the ellipsoid
             equation.
        - E: A block matrix constructed from S, P, and d. It represents the full
             ellipsoid equation in matrix form.

    Args:
        soft_iron (np.ndarray): Soft-iron matrix as a (3, 3) numpy array.
        hard_iron (np.ndarray): Hard-iron matrix as a (3, 1) numpy array.

    Returns:
        bool: Whether the soft-iron and hard-iron parametrize a ellipsoid in the
        real numbers domain.
    """
    soft_iron, hard_iron = soft_iron.reshape(3, 3), hard_iron.reshape(-1, 1)
    soft_iron_inv = np.linalg.inv(soft_iron)
    S = soft_iron_inv.T @ soft_iron_inv
    P = -hard_iron.T @ soft_iron_inv.T @ soft_iron_inv
    d = -(hard_iron.T @ soft_iron_inv.T @ soft_iron_inv @ hard_iron + 1)

    # Create block matrix with S, P and d
    E = np.block([[S, P.T], [P, d]])

    # Conditions
    try:
        cond1 = np.linalg.matrix_rank(S) == 3
        cond2 = np.linalg.matrix_rank(E) == 4
        cond3 = np.linalg.det(E) < 0
        cond4 = all([i > 0 for i in np.linalg.eigvals(S)])
        cond5 = all([i > 0 for i in np.linalg.eigvals(soft_iron)])
    except Exception as e:
        warn(f"An error occurred while validating the calibration matrices: {e}")
        return False

    return all([cond1, cond2, cond3, cond4, cond5])