Cauldron, Anyone?

The G'MIC image has three spatial dimensions; it is mostly out of habit and custom that many people (this writer included) generally fuhgeddaboudit and only use single-slice, two dimensional images. That is a shame, as many G'MIC commands do their bidding in three dimensions as well as two. They are untapped sources of cheap (in terms of rendering time) animation.

The diagram on the left illustrates how the -blur command behaves when an image has more than one slice. An orange pixel affects neighbors along the z axis (depth) as well as along the x and y axes. Play these slices as an animation and the blurred pixel becomes a kind of a pop! explosion.

The -bandpass command also operates in three dimensions. In other places, we've harnessed this command for spectral filtering, eliding all but a subset of frequencies in the original image. Taking an image with such truncated spectral content back into spatial domain gives rise to a set of sine waves that do not quite reconstitute the original; we see patterns of constructive reinforcement and destructive interference that would not have been especially noticable had we not erased those parts of the spectrum needed to reconstitute the original.

The key idea in this Cookbook piece is this: -bandpass, like many G'MIC commands work in three dimensions. And when we think Animation, that extra dimension can be time. The following example happens to use the -bandpass command, but the techniques presented here aren't married to that command. They can be generalized to any other command which operates 'in the round' over slices as well as the width and height of images.

Pipeline

Here is a pipeline that produces a kind of a cauldron effect. The nice thing about clips produced by this pipeline is that they can be seamlessly looped without a 'pop' crossing from the end to the beginning of the loop. Details follow.

Distorted Title Walkthrough

1. We input our cauldron clip, making a large image stack. (-input cauldron.mov...)
2. G'MIC -repeat ... -done permits us to iterate a pipeline of commands over the image stack The notation '\$!' is one of G'MIC's substitution sequences, this particular one will be replaced with the number of images in the stack. With this substitution, we need not know before hand how many frames a video clip has.
3. G'MIC applies the mini-pipeline of commands between the -repeat...-done markers for each image in the pipeline. Here, our overall mode of operation is to derive a displacement field from whatever image happens to be at the beginning of the stack and use it to distort a copy of the title, placing the warped title at the end of the image stack.  Finally, we remove the first image from the stack. We then repeat. As we proceed, we consume frames from the clip, but leave the corresponding warped title slides at the end of the stack, preserving the original order of the clip. As we proceed, the original animation shapes the warping of the title image.
4. In each repetition, we split the current frame into its red, green and blue channels, then delete the blue channel as we only need two colors to make a displacement field. (...--split[0] c -rm[-1]...)
5. We compose the displacement field using the --append command and employ -normalize as a warping control. Increasing the second parameter magnifies the effect of the displacement field and the magnitude of the warp. Set to suit your taste; we think 30 is about right for a really dramatic warp. We insert a fresh, unwarped copy of the title image at the end of the stack and invoke a relative warp, using the displacement field, now in the penultimate slot on the stack, to control the warp. (...-normalize[-1] 0,30 -input cauldron_title.png -warp[-1] [-2],1,1...)
6. The last two commands in the mini-pipeline perform housekeeping. We first remove the displacement field and then the first image in the stack, as both have warped their corresponding title image in the output stream and are no longer needed. (-rm[-2] -rm[0])
7. Leaving the repeat loop, we have a sequence of warped title slides, ordered in the same manner as the frames of the original animation, to which they are related. Here, we write to a Quicktime container, but could also write a sequence of PNG files as well.

We used cinelerra to composite the title sequence onto the original cauldron clip.