You. Yes. You. I do mean You.
|By default, commands operate on all images on the image list, aka the stack. Often that is not what we want. What we want, most times, is to operate on select images. In G'MIC the basis for such discriminations are image indices, reflecting images' positions on the stack.|
As we or otherwise conjure up images, G'MIC places them on the stack and assigns indices as it goes. These indices start from zero and increment by one.
That said, both positive and negative indices can address images:
1. Non-negative indices designate images from the beginning of the stack. 0, 1, 3 designate the first, second and fourth image.
2. Negative indices designate images from the end of the stack. –1, –2, –3 designate the last, penultimate and third from the last image. In a stack having four images, both –1 and 3 designate the last image on the stack; –4 and 0 designate the first image.
|Everything||-foo||Operates on every image on the stack.|
|Left Single||-foo[n]||Operates on image n+1, counting from the beginning of the stack.  is a common idiom demarking the first image on the stack. Example: -foo operates on the fourth image on the stack.|
|Right Single||-foo[–n]||Operates on image –n, counting from the end of the stack. [–1] is a common idiom demarking the last image on the stack. Example: -foo[–2] operates on the penultimate image in the stack.|
|Enumerated||-foo[a,–b,…z]||Comma separated indices. Operates on specific images. Indices may have negative signs and selections can be mixes of positive and negative indices. Example: -foo[0,2,–1] operates on the first, third and last image on the stack.|
|Range||-foo[a-b]||Hyphenated indices. Operates on images in the range from a to b inclusive. Example: -foo[3-5] operates on the fourth, fifth and sixth images. -foo[–3-–1] operates on the third from the last, next to the last and last images. Note that should a > b -foo[a-b] still works. -foo[5-3] still operates on the fourth, fifth and sixth images.|
|Relative Range||-foo[a%-b%]||Hyphenated percentages. Operates on image ranges specified through relative positions, with 100% designating the last position on the stack, however large it may be. Example: -foo[50%-100%] operates on images on the upper half of the stack.|
|Modulo n||-foo[<Range>:n]||Given a range of images, operates on every n-th image in the range. -foo[:n] is an error. Example: -foo[0-–1:3] operates on every third image on the stack. -foo[50%-100%:2] operates on every even-indexed image on the upper half of the stack.|
|Except||-foo[^<selection>]||Caret preceding a selection. Operates on all images except those in the selection. Example: -foo[^0] operates on all images except the first one. -foo[^0-–1:2] operates on every odd-indexed image on the stack.|
|Names||-foo[<label>]||Operates on images in the collection designated by the name <label>, an alphanumeric string which begins with a letter. Raises an error if <label> is not a defined collection. Use name[<selection>] <label> to establish an equivalence between <label> and the the collection of images chosen by <selection>. Observe that: (1) <selection> is significant only in enrolling images into collections; that selection has no lasting significance; and (2) an image can be enrolled in at most one collection. Images enrolled in one collection are removed from any others.|
|Enumerated Names||-foo[<label-1>,…]||Operates on the union of images enrolled in a series of collections. These collections must already be defined.|
|1.||-blur 20||Blur all images on the stack with a standard deviation of 20.|
|2.||-blur 10||Blur the first image on the stack with a standard deviation of 10.|
|3.||-blur[–1] 5||Blur the last image on the stack with a standard deviation of 5.|
|4.||-blur[0,2,5] 7||Blur the first, third, and sixth image on the stack with a standard deviation of 7.|
|5.||-blur[^3] 6||Blur all images on the stack except the fourth one with a standard deviation of 6.|
|1.||Transformative commands without hyphens or with single hyphens will replace the images they select with versions having transformed content.|
|2.||Transformative commands decorated with + on the lefthand side first copy the images they select, the copies go to the end of the stack in the same relative order as their antecedents. The command then operates on those copies.|
|3.||Non-transformative commands, such as name or flow control commands — administrative in nature — throw an error when prefixed with lefthand + decorations.|
|1.||256,256,1,3 conjures up a 256x256x1x3 pixel image with three channels, initially solid black, establishing a stack with one image. The command is implied.|
|2.||The noise[–1] command, no hyphen, two parameters, replaces this black image with a sparse, random scattering of red green and blue pixels ("Salt and Pepper Noise"), so the stack remains with one image.|
|3.||The +bandpass[–1] command, with a + left hand decorator, duplicates the image at the end of the stack and operates on that, leaving a new last image with the low-frequency components of the previous image. There are now two images on the stack.|
|4.||Similarly, +threshold[–1] copies the last image (+), then applies a bilevel reduction to each channel of what is now the last image. This leaves three images on the stack.|
|5.||+negate[–1] Again a copy-modify of the last image (+) inverting color-and-values. The stack now has four images.|
|6.||-thinning[–1] — with a - prefix — morphologically thins the last image, leaving behind the 'morphological spines' of the contiguous, non-black regions of the former version. Observe that the former version is gone, replaced by the thinned version now occupying the end of the stack. Four images remain on the stack. We could have done without the - prefix, but sometimes it helps to be reminded what pipeline items are.|
|7.||-normalize[^0], also with an optional (redundant) hyphen, replaces all images on the list, except the first one, with corresponding versions where the intensity range of each channel is remapped to the range 0 – 255, see . The image list still has four images. Had we decorated this command with +, the stack would have acquired seven images, the second, third and fourth images followed by their normalized versions in positions five, six and seven.|
|8.||o is shortcut for -output. Frequently-used G'MIC commands have shortcut spellings; most are one character. With accumulating experience, G'MIC scripters gravitate to shortcuts. But shortcuts perplex beginners. Through most tutorials, we will avoid shortcuts.|
With this shortcut, we save the entire stack vian output command to the file mystack.cimg, where files of type .cimg are of the native G'MIC format. Just prior to this output, however, the four images on the stack look like this: