# menpo/menpo

Merged
merged 4 commits into from Sep 20, 2016

## Conversation

Projects
None yet
3 participants
Member

### nontas commented Sep 7, 2016 • edited by patricksnape

This PR adds a general function for transforming about an image's centre. In general, this probably only makes sense for Affine transforms - though any transform is supported via the transform chain.

It also adds a new 2D shear transform. The shear transform has the following formulation:

``````array([[1,        tan(phi), 0],
[tan(psi), 1,        0],
[0,        0,        1]])
``````

This can be useful for data perturbation (distortions).

#### Example

The following code:

``````%matplotlib inline
import matplotlib.pyplot as plt
import menpo.io as mio
from menpo.transform import Affine, Rotation, shear_about_centre

im = mio.import_builtin_asset.lenna_png()
shear_tr = Affine.init_from_2d_shear(25, 10)
shear_tr = Rotation.init_from_2d_ccw_angle(45)

plt.subplot(141)
im.view_landmarks(render_axes=True)
plt.title('Original')

plt.subplot(142)
plt.title('Sheared - No Retain Shape')

plt.subplot(143)
plt.title('Sheared - Retain Shape')

plt.subplot(144)
bbox = im.landmarks['LJSON'].lms.bounding_box()
bbox.view(line_width=2, line_colour='b', render_markers=False)
render_markers=False,
figure_size=(17, 17))
plt.title('Example')
``````

generates the following result:

### nontas added some commits Sep 7, 2016

``` adds shear method in menpo.transform and Image ```
``` 7e92601 ```
``` adds shear_about_centre to docs ```
``` 0e67328 ```

Contributor

### patricksnape commented Sep 8, 2016 • edited

 OK - what if we add something like `affine_around_centre` that applies some `Affine` transform around the centre and we abstract out the whole `-translation, affine, translation` step? Shearing seems a tad specific to me.

### patricksnape reviewed Sep 11, 2016

 @@ -2257,6 +2258,101 @@ def rotate_ccw_about_centre(self, theta, degrees=True, retain_shape=False, shape, trans.pseudoinverse(), order=order, warp_landmarks=True, cval=cval, return_transform=return_transform) def shear_about_centre(self, phi, psi, degrees=True, retain_shape=False,

#### patricksnape Sep 11, 2016

Contributor

I think this is better (more general) as `transform_about_centre` where we just make sure that we apply the translation and then the translation back?

### patricksnape reviewed Sep 11, 2016

 raise ValueError('Shearing can only be applied on 2D objects') # Create shearing and translation transforms a = create_2d_shear_transform(phi, psi, degrees=degrees) t = Translation(-obj.centre(), skip_checks=True)

#### patricksnape Sep 11, 2016

Contributor

I think we should abstract this logic out.

### patricksnape changed the title from Shear (skew) transform to Transform about centreSep 14, 2016

``` Refactor to transform_about_centre ```
`Shearing remains, though it is not it's own function`
``` f810c91 ```

Contributor

### patricksnape commented Sep 14, 2016

 I have refactored the PR for a more general transform about centre - maintaining the shear logic.
``` adds example in transform_about_centre of Image ```
``` fb1e952 ```
Member

### nontas commented Sep 19, 2016

 Good change @patricksnape ! I tried this and it works. I simply added two usage examples in the `Image.transform_about_centre()` doc. +1

### patricksnape merged commit `c0952cb` into menpo:master Sep 20, 2016 1 check passed

#### 1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details