About the image stack - GreycLab/gmic-community GitHub Wiki

1.Initial stack

When several images are loaded in G’mic, they are ordered in a stack. It is then possible to refer to them by using either positive (starting from the first image as [0]) or negative numbers (starting from the last image as [-1]).

For example, if 3 images A, B and C are loaded:

gmic A.png B.png C.png

It creates a stack that you can picture like that:

You can refer to A as image [0] or image [-3], B as [1] or [-2] and C as [2] or [-1]. So both commands below do exactly the same thing, they display B:

gmic A.png B.png C.png display[1]
gmic A.png B.png C.png display[-2]

2.Applying a command

If, in your command line, you add an instruction with an image selection, it replaces the images to which the instruction applies by the result. Thus, to split the different channels of B, the 2 commands below could be used :

gmic A.png B.png C.png split[1] c
gmic A.png B.png C.png split[-2] c

And they would modified the stack as shown below:

As you can see, the image A is still [0], but not [-3] anymore, it has become [-5].

3.Command with a plus

To keep the original image and create a new one, instructions are called using a plus symbol '+'. The original image is indeed kept in place and the result is added at the end of the stack. So commands below:

gmic A.png B.png C.png +split[1] c
gmic A.png B.png C.png +split[-2] c

would modify the stack as below:

4.Stack order matters, not invoking order

When you apply a command to several images, sometimes, order matters. But be careful, stack order matters, not invoking order. For example, both commands below have the same result:

gmic A.png B.png append[0,1] y
gmic A.png B.png append[1,0] y

If you want to apply your command in another order, you have to play with the image stack, such as:

gmic A.png B.png reverse[0,1] append[0,1] y

or

gmic A.png B.png move[1] 0 append[1,0] y

5.Shortcuts and names

In the more recent G'mic versions, there's a shorthand syntax for [-1], [-2] and [-3]. Instead, you may now use between one and three dots. A single dot refers to [-1] and so on:

gmic A.png B.png mirror.. x mirror. y

Another very useful feature is ability to assign and refer to images by name:

gmic A.png B.png name[0] first name[1] second mirror[first] x mirror[second] y