pychubby.actions module

Definition of actions.

Note that for each action (class) the first line of the docstring as well as the default parameters of the constructor are used by the CLI.

class pychubby.actions.AbsoluteMove(x_shifts=None, y_shifts=None)

Bases: pychubby.actions.Action

Absolute offsets of any landmark points.

Parameters:
  • x_shifts (dict or None) – Keys are integers from 0 to 67 representing a chosen landmark points. The values represent the shift in the x direction to be made. If a landmark not specified assumed shift is 0.
  • y_shifts (dict or None) – Keys are integers from 0 to 67 representing a chosen landmark points. The values represent the shift in the y direction to be made. If a landmark not specified assumed shift is 0.
perform(lf)

Perform absolute move.

Specified landmarks will be shifted in either the x or y direction.

Parameters:lf (LandmarkFace) – Instance of a LandmarkFace.
Returns:
  • new_lf (LandmarkFace) – Instance of a LandmarkFace after taking the action.
  • df (DisplacementField) – Displacement field representing the transformation between the old and new image.
class pychubby.actions.Action

Bases: abc.ABC

General Action class to be subclassed.

perform(lf, **kwargs)

Perfom action on an instance of a LandmarkFace.

Parameters:
  • lf (LandmarkFace) – Instance of a LandmarkFace.
  • kwargs (dict) – Action specific parameters.
Returns:

new_lf – Instance of a LandmarkFace after a specified action was taken on the input lf.

Return type:

LandmarkFace

static pts2inst(new_points, lf, **interpolation_kwargs)

Generate instance of LandmarkFace via interpolation.

Parameters:
  • new_points (np.ndarray) – Array of shape (N, 2) representing the x and y coordinates of the new landmark points.
  • lf (LandmarkFace) – Instance of a LandmarkFace before taking any actions.
  • interpolation_kwargs (dict) – Interpolation parameters passed onto scipy.
Returns:

  • new_lf (LandmarkFace) – Instance of a LandmarkFace after taking an action.
  • df (DisplacementField) – Displacement field representing per pixel displacements between the old and new image.

class pychubby.actions.Chubbify(scale=0.2)

Bases: pychubby.actions.Action

Make a chubby face.

Parameters:scale (float) – Absolute shift size in the reference space.
perform(lf)

Perform an action.

Parameters:lf (LandmarkFace) – Instance of a LandmarkFace.
class pychubby.actions.Lambda(scale, specs, reference_space=None)

Bases: pychubby.actions.Action

Custom action for specifying actions with angles and norms in a reference space.

Parameters:
  • scale (float) – Absolute norm of the maximum shift. All the remaining shifts are scaled linearly.
  • specs (dict) –

    Dictionary where keyrs represent either the index or a name of the landmark. The values are tuples of two elements:

    1. Angle in degrees.
    2. Proportional shift. Only the relative size towards other landmarks matters.
  • reference_space (None or ReferenceSpace) – Reference space to be used.
perform(lf)

Perform action.

Parameters:lf (LandmarkFace) – Instance of a LandmarkFace before taking the action.
Returns:
  • new_lf (LandmarkFace) – Instance of a LandmarkFace after taking the action.
  • df (DisplacementField) – Displacement field representing the transformation between the old and new image.
class pychubby.actions.LinearTransform(scale_x=1.0, scale_y=1.0, rotation=0.0, shear=0.0, translation_x=0.0, translation_y=0.0, reference_space=None)

Bases: pychubby.actions.Action

Linear transformation.

Parameters:
  • scale_x (float) – Scaling of the x axis.
  • scale_y (float) – Scaling of the y axis.
  • rotation (float) – Rotation in radians.
  • shear (float) – Shear in radians.
  • translation_x (float) – Translation in the x direction.
  • translation_y (float) – Translation in the y direction.
  • reference_space (None or pychubby.reference.ReferenceSpace) – Instace of the ReferenceSpace class.
perform(lf)

Perform action.

Parameters:lf (LandmarkFace) – Instance of a LandmarkFace before taking the action.
Returns:
  • new_lf (LandmarkFace) – Instance of a LandmarkFace after taking the action.
  • df (DisplacementField) – Displacement field representing the transformation between the old and new image.
class pychubby.actions.Multiple(per_face_action)

Bases: pychubby.actions.Action

Applying actions to multiple faces.

Parameters:per_face_action (list or Action) – If list then elements are instances of some actions (subclasses of Action) that exactly match the order of LandmarkFace instances within the LandmarkFaces instance. It is also posible to use None for no action. If Action then the same action will be performed on each available LandmarkFace.
perform(lfs)

Perform actions on multiple faces.

Parameters:lfs (LandmarkFaces) – Instance of LandmarkFaces.
Returns:
  • new_lfs (LandmarkFaces) – Instance of a LandmarkFaces after taking the action on each face.
  • df (DisplacementField) – Displacement field representing the transformation between the old and new image.
class pychubby.actions.OpenEyes(scale=0.1)

Bases: pychubby.actions.Action

Open eyes.

Parameters:scale (float) – Absolute shift size in the reference space.
perform(lf)

Perform action.

Parameters:lf (LandmarkFace) – Instance of a LandmarkFace before taking the action.
Returns:
  • new_lf (LandmarkFace) – Instance of a LandmarkFace after taking the action.
  • df (DisplacementField) – Displacement field representing the transformation between the old and new image.
class pychubby.actions.Pipeline(steps)

Bases: pychubby.actions.Action

Pipe multiple actions together.

Parameters:steps (list) – List of different actions that are going to be performed in the given order.
perform(lf)

Perform action.

Parameters:lf (LandmarkFace) – Instance of a LandmarkFace before taking the action.
Returns:
  • new_lf (LandmarkFace) – Instance of a LandmarkFace after taking the action.
  • df (DisplacementField) – Displacement field representing the transformation between the old and new image.
class pychubby.actions.RaiseEyebrow(scale=0.1, side='both')

Bases: pychubby.actions.Action

Raise an eyebrow.

Parameters:
  • scale (float) – Absolute shift size in the reference space.
  • side (str, {'left', 'right', 'both'}) – Which eyebrow to raise.
perform(lf)

Perform action.

Parameters:lf (LandmarkFace) – Instance of a LandmarkFace before taking the action.
Returns:
  • new_lf (LandmarkFace) – Instance of a LandmarkFace after taking the action.
  • df (DisplacementField) – Displacement field representing the transformation between the old and new image.
class pychubby.actions.Smile(scale=0.1)

Bases: pychubby.actions.Action

Make a smiling face.

Parameters:scale (float) – Absolute shift size in the reference space.
perform(lf)

Perform action.

Parameters:lf (LandmarkFace) – Instance of a LandmarkFace before taking the action.
Returns:
  • new_lf (LandmarkFace) – Instance of a LandmarkFace after taking the action.
  • df (DisplacementField) – Displacement field representing the transformation between the old and new image.
class pychubby.actions.StretchNostrils(scale=0.1)

Bases: pychubby.actions.Action

Stratch nostrils.

Parameters:scale (float) – Absolute shift size in the reference space.
perform(lf)

Perform action.

Parameters:lf (LandmarkFace) – Instance of a LandmarkFace before taking the action.
Returns:
  • new_lf (LandmarkFace) – Instance of a LandmarkFace after taking the action.
  • df (DisplacementField) – Displacement field representing the transformation between the old and new image.