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
# mirror along y=x
xy_yx = Homogeneous(np.array([[0, 1, 0],
[1, 0, 0],
[0, 0, 1]]))
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
%matplotlib inline
pc.view()
<menpo.visualize.viewmatplotlib.MatplotlibPointCloudViewer2d at 0x138352b0>
Applying this Transform to a PointCloud
has the desired effect
pc_flipped = xy_yx.apply(pc)
pc_flipped.view()
<menpo.visualize.viewmatplotlib.MatplotlibPointCloudViewer2d at 0x13e1ae48>
Homogeneous transforms support native composition
no_op = xy_yx.compose_before(xy_yx)
print(no_op.h_matrix)
[[1 0 0] [0 1 0] [0 0 1]]
no_op = xy_yx.compose_after(xy_yx)
print(no_op.h_matrix)
[[1 0 0] [0 1 0] [0 0 1]]
xy_yx.compose_before_inplace(xy_yx)
print(xy_yx.h_matrix)
[[1 0 0] [0 1 0] [0 0 1]]