birl.utilities.registration module

Image registration tools

Copyright (C) 2016-2019 Jiri Borovec <jiri.borovec@fel.cvut.cz>

birl.utilities.registration.estimate_affine_transform(points_0, points_1)[source]

estimate Affine transformations and warp particular points sets to the other coordinate frame

Parameters
  • points_0 (ndarray) – set of points of shape (N, 2)

  • points_1 (ndarray) – set of points of shape (N, 2)

Return tuple(ndarray,ndarray,ndarray,ndarray)

transform. matrix & inverse and warped point sets

>>> pts0 = np.array([[4., 116.], [4., 4.], [26., 4.], [26., 116.]], dtype=int)
>>> pts1 = np.array([[61., 56.], [61., -56.], [39., -56.], [39., 56.]])
>>> mx, mx_inv, pts0_w, pts1_w = estimate_affine_transform(pts0, pts1)
>>> np.round(mx, 2) + 0.  # eliminate negative zeros
array([[ -1.,   0.,  65.],
       [  0.,   1., -60.],
       [  0.,   0.,   1.]])
>>> pts0_w
array([[ 61.,  56.],
       [ 61., -56.],
       [ 39., -56.],
       [ 39.,  56.]])
>>> pts1_w
array([[   4.,  116.],
       [   4.,    4.],
       [  26.,    4.],
       [  26.,  116.]])
birl.utilities.registration.get_affine_components(matrix)[source]

get the main components of Affine transform

Parameters

matrix (ndarray) – affine transformation matrix for 2d

Return dict

dictionary of float values

>>> mtx = np.array([[ -0.95,   0.1,  65.], [  0.1,   0.95, -60.], [  0.,   0.,   1.]])
>>> import  pandas as pd
>>> aff = get_affine_components(mtx)
>>> aff["scale"] = tuple(aff["scale"])  # fix for version compatibility
>>> pd.Series(aff).sort_index()  
rotation                           173.9...
scale                    (0.95..., 0.95...)
shear                              -3.14...
translation                   (65.0, -60.0)
dtype: object
birl.utilities.registration.norm_angle(angle, deg=True)[source]

normalize angles to be in range -half -> +half

Parameters
  • angle (float) – input angle

  • deg (bool) – using degree or radian

Return float

>>> norm_angle(60)
60
>>> norm_angle(200)
-160
>>> norm_angle(-540)
180
birl.utilities.registration.transform_points(points, matrix)[source]

transform points according to given transformation matrix

Parameters
  • points (ndarray) – set of points of shape (N, 2)

  • matrix (ndarray) – transformation matrix of shape (3, 3)

Return ndarray

warped points of shape (N, 2)