New command `match_icp`: Iterative Closest Point algorithm

I’ve implemented the Iterative Closest Point algorithm in G’MIC, with a new command match_icp.
I think you may be interested by this one, as it provides another way to make two sets of N-D vectors match together, by applying a linear transformation.

Here is an example to register two 2D shapes:

foo :

  # Create two distincts silhouettes to match.
  shape_cupid 400 shape_cupid 300 rotate. 65 deform. 5 gt. 50%

  # Convert silhouette contours as set of 2D points.
  foreach {
    (0,1,0;1,1,1;0,1,0) +erode.. . rm.. -
    1,1,1,2 eval.. ">i?da_push(#-1,[x,y])" k. da_freeze
  }

  # Match the two sets of points.
  +match_icp. ..

  # Draw result.
  400,400,1,3
  eval[0] "I(#-1,i0,i1) = [ 255,0,0 ]" # Red: reference contour
  eval[1] "I(#-1,i0,i1) = [ 0,0,255 ]" # Blue: contour we want to match the reference
  eval[2] "I(#-1,i0,i1) = [ 0,255,0 ]" # Green: blue contour linearly transformed to match red contour
  k.

Result:
match_icp

I had the idea of using this for doing color transfer, but so far, it doesn’t work that well.
Anyway, still cool to have this integrated into G’MIC !

2 Likes

What did it look like?

Good stuff.

Perhaps you meant: “# Green: blue contour linearly transformed to match red contour”

1 Like
$ gmic sp david,colorful,64 +match_icp[0] [1] +match_icp[1] [0]