fx_morph_layers batch outputs

I’m trying to morph a series of images, e.g., image1 with image2, image2 with image3 etc, using the fx_morph_layers filter.
How can I batch the process so the outputs are numbered sequentially? For example, running gmic image_00000.jpg image_00001.jpg fx_morph_layers 5,1.2,0.57 o out.jpg - gives outputs from ‘out_000000.jpg’ to ’
‘out_000006.jpg’. If we were to run the next command, gmic image_00001.jpg image_00002.jpg fx_morph_layers 5,1.2,0.57 o out.jpg - gmic overwrites the previous outputs. I need continuous numbering across commands. Any advice?

Furthermore, if I try the apply files route, say gmic apply_files \"input_*.png input_*(+1).png\",\"fx_morph_layers 12,0.4,0.25,0\",0,-1,1,out.png I’d be barking up the wrong tree. Or for instance (with separate image sequences) - gmic apply_files \"input_*.png image2_*.png\",\"fx_morph_layers 12,0.4,0.25,0\",0,-1,1,out.png - that simply doesn’t work and anyhow i would want it to alternate between sequences - so a bit stuck. I could knock up a batch file to do each command for separate image pairs, somehow renaming them along the way so they don’t conflict, but that’s beyond my ken unfortunately… and don’t get me started on ChatGPT. :face_with_symbols_over_mouth: Lol.

You probay want to wrap this in a shell script so you can manipulate the file names.

1 Like

I guess you could try to make a command to name those images all at once before exporting. Too occupied with my things for now.

Pinging @David_Tschumperle as he can help more I think.

1 Like

I have been incredibly busy myself.

Tips:

  1. Use gmic run "commands" to avoid having to escape everything in one-liners.
  2. No need to do a shell script. Create a custom commands within an user.gmic or *.gmic file. By now @Mushy, you should start exploring that. As much as I love one liners, they are not good for complex lines of code or processing.
  3. Building on #2, I like the user.gmic approach because I can make simple yet effective helper commands, such as changing image names.

I have not told you how exactly to do all this, but a planned approach saves time and from head scratching.

1 Like

Thanks for all the suggestions, not too familiar with shell scripts even though I should be, seeing as it would make my life easier, up until now, I’ve been reliant on little python scripts for batch gmic jobs (only to produce shell scripts of various sequential commands, rather than using gmic-py).
Anyway…
I got as far as ‘Hello world’

#@cli hello_world:
hello_world :
  echo "Hello, G'MIC World!"
gmic -m user.gmic hello_world
[gmic]./ Start G'MIC interpreter (v.3.4.2).
[gmic]./ Import commands from file 'user.gmic', with debug info (1 new, total: 4818).
Hello, G'MIC World!
[gmic]./ End G'MIC interpreter.

Yay…! I have no idea what I’m doing which, although unhelpful, is true.

(EDIT):
I’ve slightly revised what I want to do, now, I have two image sequences image2_.png and ah2_.png
i want to intersperse the morphing. so the basic pattern of input pairs is:
image2_0000.png + ah2_000.png
ah2_000.png + image2_0001.png
image2_0001.png + ah2_001.png
ah2_001.png + image2_0002.png
And so on…

And somehow I need to rename the outputs as they are executed, maybe using the mv command or similar, eventuating in the outputs from the chronological processing of inputs having continuous sequential ordering.

Now, examine and learn from the *.gmic here: afre.gmic is simplistic if not outdated: likely a good starting point for you.

There is also

1 Like

It’s not that simple looking.

A better starting point is to read the tutorial and develop your own coding style. Something to note about gmic-community, there is no standard.

1 Like

Try this:
gmic run "sp tiger,flower ind=0 foreach o batch{$>+$ind}.jpg done"

  • run saves you the trouble from having to use escapes or having issues with substitution rules (for the most part)
  • foreach loops each image in image buffer; close with done
  • batch is just text you can replace
  • $> increments from 0
  • {$>+$ind} will count from $ind, which you can adjust to offset the filenames and avoid overwriting your last output
  • { } indicate the math interpreter; other times for substitution or to control flow if you want to use shortcut code

Of course, this is not the most clever way of doing it. I am sure we/you can develop something more suitable for your use case.

Ok, thanks @afre and @Reptorian for the suggestions and tips. I have downloaded the gmic_stdlib text file and split it into about 12 parts (as my phone text editor of choice cannot deal adequately with anything above 300kb!)
Will peruse those and see what happens, cheers.