Documentation: https://scikit-image.org/docs/stable/api/skimage.transform.html
Source and destination points are given as NxD
arrays,
with the points given in (x, y)
coordinates, not in
(row, column)
.
So for instance, we could have:
= np.array([[100, 100],
src_points 300, 400],
[500, 300]])
[
= np.array([[100, 200],
dst_points 20, 470],
[250, 500]])
[
= AffineTransform()
tx
tx.estimate(src_points, dst_points)print(tx.rotation, tx.translation, tx.scale, tx.shear)
Which will give us a rotation of 0.53
radians, a
translation of x=101.25, y=95
, a scale factor of
sx=0.88, sy=0.91
, and a shear angle of
0.38
.
The warp
function allows us to apply the transform to an
image:
= warp(im, tx.inverse) im_
Note that we have to use tx.inverse
, not
tx
: the transform in warp
is from the
destination to the source.
The transform object is callable, and can be used to compute transformed coordinates:
= tx(src_points)
warped_points print(warped_points)
Will give us the same coordinates as the dst_points
in
return.
Shear is a bit weird. We can specify shear along x
and
y
axis with a tuple, or just along x
axis.
= AffineTransform(shear=(math.pi/6, 0))
tx_shear_x = AffineTransform(shear=(0, math.pi/6))
tx_shear_y = AffineTransform(shear=(math.pi/6, math.pi/6)) tx_shear_xy
For x
shear, the angle is the rotation of the y-axis,
with 0 as “down” and going clockwise, etc. It’s weird.