G'MIC in NATRON interactive mode

I’d like to use effects like the interactive warp of G’MIC in NATRON. Is it possible ?
Maybe G’MIC syntax could be modified to pass the control points by script rather than manual interaction (this would allow to animate the control points over time)

I don’t have experience with Natron but it should be possible to script changing parameters.

I’m afraid it’s not because according to the docs:
https://gmic.eu/reference.shtml#x_warp
The x_warp function doesn’t receive key points as parameters.

That’s why I’m asking if the syntax of G’MIC could be extended with source/destination key points parameters

What I mean is that one could add to the x_warp script. For it to work, I believe:

1 Run x_warp. Select points (x_i0,y_j0), move them (x_i1,y_j1) and process.
2 Return (x_i1,y_j1), pass it to Natron and run x_warp again with new coordinates.
(Or no need to pass it to Natron if gmic has access to all of the frames…)
3 Do this for each frame.

Let’s see if @David_Tschumperle has time to make a “video” version of x_warp.

The x_warp command is indeed intended to be interactive only (as all commands as x_something). But writing a new specific command that warps an image according to a list of keypoints passed as arguments is definitely possible.
Anyway, it’s all a question of free time to implement it.

Unfortunately, free time is a resource I have less and less of. All I can do now is stack your request on my todo list and see if I can ever unstack it one day.
Other developers may be able to implement it in their own way (in G’MIC or elsewhere).

Thanks David. I clearly understand a new command would require a lot of work.

My understanding is it requires Delaunay triangulation which is not available in Gmic in a suitable form. Am I right.?.. OpenCV is probably part of the solution to my question.

No, the x_warp function does not use Delaunay triangulation.
The keypoints are not triangulated, but are used to define a RBF-based interpolation using the Thin Plate Spline function.

With the recent rbf command that have been introduced in G’MIC, this actually shouldn’t be too hard to reimplement a non-interactive version of x_warp. If I get some time, I’ll give a try during the week-end, but I can’t promise anything.

I’ve added a new command warp_rbf to the G’MIC stdlib. You should be able to access it after a

$ gmic update

Here is the documentation of this command:

    warp_rbf:
        xs0[%],ys0[%],xt0[%],yt0[%],...,xsN[%],ysN[%],xtN[%],ytN[%]

      Warp selected images using RBF-based interpolation.
      Each argument (xsk,ysk)-(xtk,ytk) corresponds to the coordinates of the
      source and target points that define the overall image deformation.
      
      Example: [#1]  image.jpg +warp_rbf 0,0,0,0,100%,0,\
                 100%,0,100%,100%,100%,100%,0,100%,0,100%,50%,50%,70%,50%,25%,25%,25%,75%

Basically, the arguments are grouped 4 by 4. Each group of 4 arguments define one keypoint and its displacement (coordinates of the old and new locations).

$ gmic sp lion +warp_rbf 0,0,0,0,100%,0,100%,0,100%,100%,100%,100%,0,100%,0,100%,50%,50%,70%,70%,40%,40%,25%,25%

gives:

I didn’t test exhaustively, because I wrote this quickly rather than having breakfast, so now I have to go eat :slight_smile:
Let me know if it seems useful to you.

Wow great! I’m sure it will be very helpful. I’ll test it very quickly to come back to you.
Thanks so much!