Ah, me. You have fallen down a rabbit hole. Welcome to the hutch.
Insofar as using a Git repository, SCM Introduction covers the Git part, but not GitHub, a web site that wraps a Web interface around Git. For help with that, see the GitHub documentation. You have forked the git-community repository into your own, from which you may make changes, commit them, then make pull requests to dtschump/gmic-community, where your changes may be considered and, perhaps, incorporated back into the source. Possibly this was not your aim, but it is what you happen to have done.
Insofar as gmic is concerned:
- Try giving Basics a read.
- While I’ve found using the gmic-qt →Various → Custom Code as a handy way to check gmic snippets while in Gimp, it is a bit too limited for script development. The gmic cli environment really works best in a shell.
-
<name> : <definition> commences the definition of a custom command, here, one called
"rep_count_number_of_transparent_pixel"
See 3D Bouncing Balls, a tutorial, then perhaps Adding Custom Commands (reference). The operand(s) upon which gmic commands operate are those images cited in the command’s selection decorator.
-
-check sets up any number of tests to examine if a custom command’s arguments are sane.
$!==1
stipulates that the number of images on the list must be one. $!
is the substitution sequence that resolves to the image count. -check
is not mandatory but almost always needed. How one might write -check
follows from what one might wish to test.
-
1,1,1,1
This is a form of the -input command. This particular example introduces a one pixel wide by one pixel high by one pixel deep with a one pixel channel. Since nothing else has been specified, this is a wholly black, wholly transparent (See EDIT) one pixel image. @Reptorian is testing ‘transparency’ against this minimal image.
-
sh[0]
is shortcut notation for the shared command, with an antique tutorial Shared. It is a means to declare contiguous parts of one image as if it was an image in its own right. The image being subjected to this surgery is the first image on the image list, per the selection decorator [0]
and — though it may not be obvious — is likely to represent the first (and only initial) item on the image list. At this juncture, it is worth counting the items on the image list: the first one, just subjected to surgery, selected by decorator [0], the second one, the one pixel transparent model image, selected by decorator [1], and the third image, an extracted portion of the first image, [2].
- The substitution sequence
{s#0-1}
invokes the math processor, a world unto its own. This snippet resolves to the last channel number: s
represents “spectrum” (channel) count, and its annotation #0
indicates the channel count of the first [0] image is being used in the expression. The overall computation indicates the enumeration of the last, usually ‘alpha’ channel. Overall, this means that it is the last channel of image [0] that is being shared out as the image in position [2].
-
eval. i?i(#-2,0,0,0,0)++
literally counts the number of pixels in the last image that exactly compare to the last channel in the transparency (See EDIT) model image. It is a pel processor that visits every pixel in the extracted transparency alpha (See EDIT) channel (i)
and compares it to the transparency channel of the (See EDIT) model image (i#-2)
. If they compare exactly, the script increments the intensity channel of the model image, the keeper of the count.
-
u {i(#-2,0,0,0,0)}
, u
shorthand for -status,
dumps the intensity statistics of the single pixel in the model image, which contains the count of transparent (opaque — see EDIT) pixels, this found through another math expression evaluation. The results of this math evaluation appears in the gmic log stream, which, when invoked in a shell, prints out in the shell’s standard output stream.
- `rm[-2,-1] removes the shared-out channel and the model transparency image. The former seems that it would injure the image from which the channel was shared, but by design this is non-destructive.
EDIT:
@Reptorian:
Step 8. On reflection, this seems to actually count opaque pixels, that’s when i
of the shared-out channel has a non-zero, ‘true’ value.
gosgood@bertha ~ $ gmic -v 3 -m ssub.gmic -input 5,5,1,4 set 1,2,2,0,3 rep_count_number_of_transparent_pixel.
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Set verbosity level to 3.
[gmic]-0./ Import commands from file 'ssub.gmic' (6 new, 2 replaced, total: 4397).
[gmic]-0./ Input black image at position 0 (1 image 5x5x1x4).
[gmic]-1./ Set value 1 in image [0], at coordinates (2,2,0,3).
[gmic]-1./rep_count_number_of_transparent_pixel/ Check condition '1==1' -> true.
[gmic]-1./rep_count_number_of_transparent_pixel/ Input black image at position 1 (1 image 1x1x1x1).
[gmic]-2./rep_count_number_of_transparent_pixel/ Insert shared buffer from channel 3 of image [0].
[gmic]-3./rep_count_number_of_transparent_pixel/ Evaluate expression 'i?i(#-2,0,0,0,0)++;' looped over image [2].
[gmic]-3./rep_count_number_of_transparent_pixel/ Set status to '1'.
[gmic]-3./rep_count_number_of_transparent_pixel/ Remove images [1,2] (1 image left).
[gmic]-1./ Display image [0] = '[unnamed]'.
[0] = '[unnamed]':
size = (5,5,1,4) [400 b of floats].
data = (0,0,0,0,0;0,0,0,0,0;0,0,(...),0,0;0,0,0,0,0;0,0,0,0,0).
min = 0, max = 1, mean = 0.01, std = 0.1, coords_min = (0,0,0,0), coords_max = (2,2,0,3).
[gmic]-1./ End G'MIC interpreter.