Homogeneous Transforms


In [1]:
import numpy as np

from menpo.shape import PointCloud
from menpo.transform import Homogeneous

If you know the form of a basic homogeneous transform (like here a mirror along y=x) it's trivial to build a Homogeneous to use this operation in Menpo


In [2]:
# mirror along y=x
xy_yx = Homogeneous(np.array([[0, 1, 0], 
                              [1, 0, 0], 
                              [0, 0, 1]]))

In [3]:
s = np.linspace(0, 1)
len(s)
p = np.ones([len(s), 2])
p[:, 1] = s
pc = PointCloud(p)
print(pc)


PointCloud: n_points: 50, n_dims: 2

In [4]:
%matplotlib inline
pc.view(axes_y_limits=(0.5, 1.5));


Let's take a look at what our homogeneous transform is exactly


In [5]:
print(xy_yx)


Homogeneous
[[0 1 0]
 [1 0 0]
 [0 0 1]]

Applying this Transform to a PointCloud has the desired effect


In [6]:
pc_flipped = xy_yx.apply(pc)

In [7]:
pc_flipped.view(axes_x_limits=(0.5, 1.5));


Homogeneous transforms support native composition


In [8]:
no_op = xy_yx.compose_before(xy_yx)
print(no_op)


Homogeneous
[[1 0 0]
 [0 1 0]
 [0 0 1]]

In [9]:
no_op = xy_yx.compose_after(xy_yx)
print(no_op)


Homogeneous
[[1 0 0]
 [0 1 0]
 [0 0 1]]

In [10]:
xy_yx.compose_before_inplace(xy_yx)
print(xy_yx)


Homogeneous
[[1 0 0]
 [0 1 0]
 [0 0 1]]