G'MIC - GREYC's Magic for Image Computing: A Full-Featured Open-Source Framework for Image Processing

A Full-Featured Open-Source Framework for Image Processing

Latest stable version: 3.1.6        Current pre-release: 3.2.0



16,16,1,2,'if(c==0,x,y)' +compose_channels[0] and +compose_channels[0] xor -compose_channels[0] or a c r2dx 256,1 n 0,255
This or that but not both
This command uses image channels as operands in an arithmetic or logical operation. The command's parameter specifies the operator, which defaults to add.

For example the underlined snippet in this pipeline:

gmic 16,16,1,2,'if(c==0,x,y)' -compose_channels and

is equivalent to:

gmic 16,16,1,2,'if(c==0,x,y)' -split c -and[-2,-1]

The first form bypasses split and its concomitant overhead, internally harnessing shared to avoid the image unroll and shuffling.

The top graphic arose from this pipeline:

gmic                               \
   -input 16,16,1,2,'if(c==0,x,y)' \
   +compose_channels[0] and        \
   +compose_channels[0] xor        \
   -compose_channels[0] or         \
   -append c                       \
   -resize2dx 256,1                \
   -normalize. 0,255               \
   -output. xormagick.png
Command reference
$ gmic -h compose_channels


Compose all channels of each selected image, using specified arithmetic operator (+,-,or,min,...).

Default value: '1=+'.

[#1] image.jpg +compose_channels and

Tutorial: https://gmic.eu/tutorial/compose_channels
operator: Any binary arithmetic, logical or comparison test operator that takes a pair of image operands and produces a single result.
One writes the operator without any leading hyphens as it is being passed as a parameter rather than being immediately invoked. Figuratively, the command inserts N − 1 copies of the operator between the N channels of an image, and then reduces the result pairwise from channel zero, accumulating the result in channel zero.

It is a harmless yet pointless exercise to employ a single channel image with compose_channels, a bit like the sound of one hand clapping. In this case, such an image is left unchanged by the command. On the other hand, the G'MIC command passed to compose_channels really must be a pairwise image operator that reduces a multi-spectral operand image to a single channel result. Unpredictable behavior can arise, though an inappropriate command usually results in a error.
G'MIC - GREYC's Magic for Image Computing: A Full-Featured Open-Source Framework for Image Processing

G'MIC is an open-source software distributed under the CeCILL free software licenses (LGPL-like and/or
GPL-compatible). Copyrights (C) Since July 2008, David Tschumperlé - GREYC UMR CNRS 6072, Image Team.