Pull - commit - code trial

Hi,

I did fork gmic-community on github, (is it the way?)

screenshot_20210805-103100

never use github and i’m no programmer

I did change some code on tom_keil.gmic (un-commented code) , so which one should I use (see screenshot)

Also while I’m here, I would like to try some very simple things, like
echo “hello world”;
count the number of transparent pixel in an image, and or in a channel for example count the number of pixel where “G” second value (145) is >= 100 of RGBA(12, 145, 234, 0)

is there a “reference” doc with example like php.net about the extremely basics?

thanks for reading

A easier way to fork is to edit file from dtachump/gmic-community.

As for your questions pertaining to gmic language.

For first one:

hello_world:
echo “hello world!”

For second one:

rep_count_number_of_transparent_pixel:
check $!==1
1,1,1,1
sh[0] {s#0-1}
eval. i?i(#-2,0,0,0,0)++;
u {i(#-2,0,0,0,0)}
rm[-2,-1]

Didn’t eval use to print the last output? Why does that not happen anymore? Would be easier. Also, this command could use + for latest gmic (I still have to update).

FInally, I use this from time to time: https://gmic.eu/reference

First of all thanks a lot! I very much appreciated.

without debug on preview checked

without debug on preview checked

Both codes with debug on preview checked

many questions to try to understand the “grammar” behind your code
When you write

rep_count_number_of_transparent_pixel:

are you declaring a variable, a class, a function,…?

This

check $!==1

I saw that $! is the current number of images in the list. But still don’t understand if $ alone is an image in the reference below

what does “check” do exactly, is it mandatory? is it something like if($!==1){ more code } alike?

What are those numbers?

1,1,1,1

and then I got lost, I saw that [0] is the first image, not sure, but why sh (shared)?

I would really appreciate if you can comment each line of your code
the thing is that there is no search option in the reference page (although I use Ctrl+F but when I was searching for “u” on line 6… I got 294 matches > as I already click more than 100 time for previous searches, so I just gave up)

In all case thanks a lot.

The easiest way to learn and write commands is not from the plugin but from your custom commands user file where you placed Watercolor. The reference docs are good but also take a look into @grosgood’s excellent tutorials. As everything is open source, be sure to read the gmic_stdlib.gmic and community files for syntactic and stylistic cues.

Lastly, post your specific questions and problems in G'MIC exercises for us to explore G’MIC collaboratively. Placing everything on a single thread makes it easier to search when you want to review or remember something.

2 Likes

This part is a bug. @David_Tschumperle . I had wanted to get around reporting it before, but I almost never use the GUI tool for making script anymore because it is so much easier to know what’s going on with cli version.

On this. You should type in hello_world above hello_world: though only accessible with debug on as you can see status on. echo doesn’t do anything on GUI. But, you can see hello world output in the cli. In GUI, use status or u.

It would be most accurately resembling a function.

check checks whether conditions meet. If it does not meet, then throw a error.

These are the dimension of an array. {width},{height},{depth},{channels}. So, if you’re coming from a C# or C++ background, it would most resemble a 3D array with 1D array inside it and size of 1D array is dependent on channel count.

Because it is akin to alias of reference image rather than a copy, making the operation faster. You’d find that other prefer to use split channels or channels in this case.

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

C:\Windows\System32>gmic h u

  u (+):
      Shortcut for command 'status'.

  status (+):
      status_string

    Set the current status. Used to define a returning value from a function.
    (equivalent to shortcut command 'u').

Please help me reproducing the “bug” (definitely not sure it is one), by providing minimal information, so that I can fix it ASAP.

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:

  1. Try giving Basics a read.
  2. 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.
  3. <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.
  4. -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.
  5. 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.
  6. 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].
  7. 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].
  8. 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.
  9. 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.
  10. `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.
2 Likes

Yep, it does. Conditions matter actually. Generally alpha are assumed to be in either the second channel in GRAYA mode or the fourth channel (exception in cmyka mode(which is why I added cmyka_mode option to my filters as rare as it would be)).

Here’s the new code:

rep_count_number_of_transparent_pixel:
$!,1,1,1 #Create an 3D array that has the dimension of the total amount of images for width, and 1 for everything else.#
repeat $!-1 #Repeat as much as the initial image count. -1 is because we added a image#
 num_of_channels={s#$>} #Self-Explained#
 if $num_of_channels==2||$num_of_channels>3 #Condition check for Alpha#
  sh[$>] {$num_of_channels-1} #Extract channel as if it was a shared address#
  eval. i?i(#-2,$>,0,0,0)++ #Increment values onto the index of the created array#
  rm. #Removed the shared channel#
 else
  continue #If condition is not met, then processing is skipped#
 fi
done #Finish the repeat loop#
u {crop(#-1)} #Set the number of non-transparent pixels array into the status#
rm. #Remove the array now that you don't need it anymore though you can keep it by removing it if you want to access the values other way.#

Just set debug mode on.

1 Like

Fixed in 2.9.9, with latest filter updates.

Fix is confirmed. Thank you.

For OP, if planning to use only GUI, u “Hello World” and debug mode on would get you to that part.

Absent for 3 days and Wowww! :blush:

Thank you all for your explanations/helps and links you pointed me to, a lot of reading to do.
Allow me some days, surely a week to read that all as I have a lot to ingest… (does not mean that I won’t ask more questions during those days :grinning:)

@Reptorian yes I’m planning to use only the GUI (starting slowly for the moment, I do need to understand so many things) , I’m no programmer, so not coming from C# nor C, I understand multidimensional array as I have to use PHP/JavaScript for websites, though

@grosgood Why do I feel that rabbit hole has no end :sweat_smile:

@afre thanks! that’s some very useful links :+1: