Algorithmic emoji style transfer

Transform an emoji into a given contour of another one

Initial source of the idea: OpenCV transform image shape transformation into a given contour

The core solution is to align points from one image contour to another one. But how to do it without manual operations? That was the main question I tried to solve. As a result, I wrote three methods to tackle the task:

  1. Contour points sampling, CPS
    1. Get images of the equal size
    2. Extract object mask
    3. Extract object contour
    4. Sample contour for each image
    5. Calculate distance matrix & perform linear sum alignment to get the proper points pairs
    6. Split images into triangles and perform affine transformations and warping to fit triangles to the primary image.
  2. Contour areas stratification, CASv1
    1. Get images of the equal size
    2. Extract object mask
    3. Extract object contour
    4. Extract bbox of a contour
    5. Find closest contour points to bbox vertices
    6. Split contour points based on closest vertices to areas: top, bottom, left, right. Combine sorted areas.
    7. Split images into triangles and perform affine transformations and warping to fit triangles to the primary image.
  3. Contour areas stratification v2, CASv2
    1. Get images of the equal size
    2. Extract object mask
    3. Extract object contour
      1. Get contour of a mask
      2. Get convex hull of the previously extracted contour
      3. Create a new mask from the resulting convex hull
      4. Get final contour from the new mask
    4. Extract bbox of a contour
    5. Find closest contour points to bbox vertices
    6. Split contour points based on closest vertices to areas: top, bottom, left, right. Combine sorted areas.
    7. Split images into triangles and perform affine transformations and warping to fit triangles to the primary image.

Examples:

img-1

img-2 img-3 img-4 img-5 img-6 img-7

Link to the GitHub repository