The Big Bad G'MIC Thread of Silly Questions

That’s a quite classical problem :slight_smile:

You have to keep in mind that the examples in the G’MIC command documentation are written in the G’MIC scripting language. In that language, you need some special characters such as ', {, } and so on…
But if you call G’MIC from a shell (e.g. bash or sh), these special characters are also used by the shell itself, and they are used before the call to G’MIC is done.

So, depending on the shell you use, it’s not unusual to have to quote or backslash those characters so that they can be indeed passed to the G’MIC interpreter.

In your example, with a bash shell, you’ll have to transform the example syntax a little bit, and write it as:

$ gmic sp greece add "'80*cos(80*(x/w-0.5)*(y/w-0.5)+c)'" cut 0,255

and you’ll get this:

$ gmic sp greece add "'80*cos(80*(x/w-0.5)*(y/w-0.5)+c)'" cut 0,255 o output.jpg,85
[gmic]./ Start G'MIC interpreter (v.3.3.6).
[gmic]./ Input sample image 'greece' (1 image 750x500x1x3).
[gmic]./ Add expression '80*cos(80*(x/w-0.5)*(y/w-0.5)+c)' to image [0].
[gmic]./ Cut image [0] in range [0,255].
[gmic]./ Output image [0] as jpg file 'output.jpg', with quality 85% (1 image 750x500x1x3).
[gmic]./ End G'MIC interpreter.

Yes, I’ve been forced to put the add argument between double quotes, so that the ', ( and ) characters are passed to the G’MIC interpreter as it. If you are using another shell, you’ll have to do something else (e.g. Powershell). That’s why we cannot put directly the bash-modified commands in the documentation.

1 Like

Well, i see a difference, but it wasn’t what you expected it seems :slight_smile:
My bad, didn’t look at the examples.

This is unfortunate. I will adapt. Thank you!

Then how do you make it “behave” like it should using run to avoid the backslash nightmare? It didn’t throw an error when I added { }, but it didn’t look like anything it should. Probably because it sent everything to the math parser and it is a totally different result?

Just see it as a test of endurance :slight_smile:
I wonder, what does Image magick use to display images?
It works for me but always opens windows maximized.
(Or python since it seems it’s always there on linux?)
But maybe that’s too much, i don’t know.

All this talk about motion blur and stuff made me want to play with the wind:



1 Like

28 posts were split to a new topic: Fun with prawnsushi

But guys, do you know i’m still struggling with the real basic things of G’MIC?

Like this:
1500,700,1,3,[103,2,1]*y/(h-1)
100,100,1,3,"lerp([ 32,128,99 ],[ 200,0,16 ],y/(h-1))"
These create a gradient from one color to another, alright?
How do i add a third color?

And, how do i create a 1x3 image and give each pixel different RGB values?
i’ve seen this a lot :
1,3,1,3,'128,50,80'
but can’t do it for RGB triplets.
I think i’ve asked this before, but i can’t remember or find the answer.
When i do :
(50;0;0^50;25;0^100;100;0)
Colors are wrong ; 50,0,0 becomes 50,50,100, etc.
Puzzling.

I’ve read this too :

(v1,v2,…)[xN]: Insert one or N new images from specified prescribed values. Value separator inside parentheses can be , (column separator), ; (row separator), / (slice separator) or ^ (channel separator). For instance, expression (1,2,3;4,5,6;7,8,9) creates a 3x3 matrix (scalar image), with values running from 1 to 9.

(‘string’[:delimiter])[xN]: Insert one or N new images from specified string, by filling the images with the character codes composing the string. When specified, delimiter tells about the main orientation of the image. Delimiter can be x (eq. to , which is the default), y (eq. to ;), z (eq. to /) or c (eq. to ^). When specified delimiter is , ;, / or ^, the expression is actually equivalent to ({‘string’[:delimiter]})[xN] (see section Substitution Rules for more information on the syntax).

foo:
1500,700,1,3,"begin(
        colors=[[32,128,99],[200,0,16],[95,190,20]];
        const num_of_colors=int(size(colors)/s);
        const division=(h-1)/(num_of_colors-1);
    );
    relative_point=y/division;
    index=int(y/division);
    if(isint(relative_point)
    ,(colors)[index*s,s]
    ,lerp((colors)[index*s,s],(colors)[(index+1)*s,s],relative_point-index)
    );
    "

On this:

(50;0;0^50;25;0^100;100;0)

You can use CLI to extract value, so make your palette here, and copy from CLI. That’s how I did +pal thing.

To use GUI to make 3 colors:

($1,$4,$7^$2,$5,$8^$3,$6,$9)

And then you can resize with linear interpolation.

Alternatively:

(${1-9:3}^${2-9:3}^${3-9:3})
1 Like

Mmmm so I guess I have to rearrange them as a square to make it more readable:

($1,$4,$7^\
$2,$5,$8^\
$3,$6,$9)
1 Like

At some point in time, try to absorb Input - 4. Prescribed Values if you have not already done so. This section covers inputting an image by way of a stream of numeric values.

Various non-numeric delimiters partition streams into column (,), row (;), slice (/) and channel (^) regions.

In this stream that you have written:

(50;0;0^50;25;0^100;100;0)

It probably is not obvious, but the absence of delimiters indicates as much about the organization of an image as their presence. There are no slashes or commas. So, at the outset, the image has at most one column and at most one slice. For if were otherwise, the presence of commas would delimit the stream into two or more columns, and the presence of slashes would delimit the stream into two or more slices.

Semicolons and carets are present, so the image is delimited into more than one row; rows are what semicolons delimit; and more than one channel; channels are what carets delimit. Taking into account the presence and absence of delimiters, this particular stream first fills row 0, 1, and 2 of column 0 (and there can only be one column). As these data precede the first caret, the flow necessarily is into channel 0 (we think of this channel as “red”; G’MIC could not care less). That first caret delimits channel 0 from channel 1; data following it flows into row 0, 1, and 2 of channel 1 (“green”). The second and final caret separates channel 1 from channel 2; data following it flows into row 0, 1 and 2 of channel 2 ("blue). This is how a stream flows into a 1,3,1,3 image. Homework: how would the flow go if all of the semicolons change to commas (Hint: since there are no semicolons, the flow would go into at most one row, but more than one columns)?

The color of the pixel in row 0 necessarily must be [50,50,100] because these three values are each the first items in each of the three channel blocks. and these first items successively flow into channel 0 - the block before the first caret, channel 1 - the block before the second caret, and finally channel 2 - the trailing block. Similarly, the three values that are the second items in each of the three channel blocks compose [0,25,100], the pixel in row 1. What is the pixel in row 2 (Can it be any blacker)?

Make various small images and observe how G’MIC prints them out in the console log.

gosgood@lydia ~ $ gmic run 'v 2 (50;0;0^50;25;0^100;100;0)'
[gmic]./ Start G'MIC interpreter (v.3.3.6).
[gmic]./run/__run/ Set verbosity level to 2.
[gmic]./run/__run/ Input image at position 0, with values (50;0;0^50;25;0^100;100;0) (1 image 1x3x1x3).
[gmic]./ Display image [0] = '(50;0;0^50;25;0^100;100;0)'.
[0] = '(50;0;0^50;25;0^100;100;0)':
  size = (1,3,1,3) [36 b of float32].
  data = (50;0;0^50;25;0^100;100;0).
  min = 0, max = 100, mean = 36.1111, std = 41.6667, coords_min = (0,1,0,0), coords_max = (0,0,0,2).
1 Like

Ah thanks, i’ve been looking for this page for hours today…
Couldn’t find the link, all input links i found in the tutorials point to the reference page, which is less detailed. I knew this page existed, seen it last year lol. Could you tell me which page has the link? It’s hidden too well.

Anyway, i’ve finally noticed how the values were ordered in between the (), wasn’t sure if it was supposed to be this way, or if i did it wrong ( without your link, hard to figure this out). I’m used to write RGB colors as 255,0,0 for red, etc. , so you can guess how it can confuse me to split colors like you described.

In the end i wrote it this way for the “forest” gradient:

    (2;2;2;2;0\
    ^0;0;1;2;0\
    ^0;0;0;2;0)

More readability for me this way, i don’t have to “jump” over 2 values to guess a color.
I had to use very dark colors though, since with all the effects it would quickly become very bright.

3,1,1,3. I wanted a vertical image though, hence the use of ;
But i will allow a gradient along x axis too.

0,0,0. I wish it could be “more blacker” but anyway no screen could display it.

Thanks a lot.

image

Have fun!

1 Like

Lol. Color me depressed.
I was looking in the scripting tutorial…

Not sure that I understand. The cited URL in the help text is among those pages making up the scripting tutorial, because “tutorial” is a part of the URL. One of these days I shall have to learn French, so that I can confuse you in your native language, rather than resorting to an Americanized form of English with Brooklynese variants…

Perhaps you want the pure web-browser path, for those adverse to using command shells.

  1. From the G’MIC home page (gmic.eu), choose “Scripting Tutorial”, second item down, with the “?” icon.
  2. That brings one to Start Here, the home page (“root”) of Tutorial Land, with the fake CRT G’MIC prompt animation.
  3. Scroll all the way down to the bottom, where the Tutorial Land header resides (“If all else fails, read the manuals.”).
  4. From that table, click on Command Guide, 8th entry down (“Tutorials written around not nearly enough commands.”).
  5. That brings one to Command Tutorials, where there are vast tables of G’MIC commands listed, but somewhat out-of-date, and mostly back-pointing to Technical Reference URL’s (Availability=Ref.).
  6. However, some antediluvian pages are in the radioactive Old Tutorial space (Availability<2.0), but a very few are almost, nearly, kind of, current (Availability>2.0). Scroll down and find input with an Availability ≈ 2.9x. Ah! That’s as good as it gets!
  7. That link brings you to the page that gmic -h input does rather more directly.
  8. One of these days, I’ll complete this section. Possibly after I learn French.

Have fun!

1 Like

I can’t really ping you at github, so I mentioned you on this feature idea - (Feature Idea) Literals to affect inputs · Issue #42 · GreycLab/gmic · GitHub . Did not want to PM you just for a small message.

Lol ok. Well I struggled because I lost my way to the input tutorial page. I was very tired it seems, considering it was right under my nose all this time. But it was because I usually use sample or an existing image to work on, and never create images from scratch, unless it’s white or black.

A post was merged into an existing topic: Fun with prawnsushi

Now that i have added tree seeds in underwoods

  • It works for the preview, moving the light doesn’t change trees shape or position.
  • It works for the output, but the output doesn’t look anything like the preview.

Probably because i 'm using image width as a repeat loop, and the preview image width is different. Looking for a solution…

1 Like

Maybe use full preview?

From stdlib:

#    '#@gui Command name : command, preview_command (zoom_factor)[*|+] [: default_input_mode]
#    '#@gui : parameter1 = typedef(arguments1...), parameter2 = typedef(arguments2...)'
#    '#@gui : parameter3 = typedef(arguments3...),
#
#   where :
#
#      'command' is the G'MIC command name called to process the image.
#
#      'preview_command' is the G'MIC command name called to process the preview.
#
#           Note that you can optionally specify a float-valued factor>=0 between parentheses at the end of
#           the 'preview_command' to force the default zoom factor used by the preview for this filter.
#           Use (0) for a 1:1 preview, (1) for previewing the whole image, (2) for 1/2 image and so on...
#           You can put an additional '+' sign after the parenthesis to specify the rendered preview
#           is still accurate for different zoom factors. Use '*' instead to tell the plug-in that the preview filter
#           must get the entire image rather than a thumbnail.