The Big Bad G'MIC Thread of Silly Questions

Indeed!

2 Likes

→ Blood animation:

2 Likes

Blood does not move like this: it is more viscous. Reminds me of the final series of the Doctor Who spinoff Torchwood: Miracle Day - Wikipedia.

Infinite loop version :

ezgif.com-gif-maker(1)

From now on, I’ll stop polluting this thread :slight_smile:

It doesn’t matter, as long as you’re having fun :slight_smile:
If i may add : this thread wouldn’t even exist without you and G’mic, so… yeah, just pollute!

1 Like

3 posts were split to a new topic: Opening DNG files on my smartphone

Hi everyone, i have a few questions…

I have, in the GUI, a few drop-down menus followed by a value slider. All menus are the same, i just want to test filters in a different order.
But the more i try to improve it, the less it works.
How can i make the following script interpret $V instead of using plain text? It works with $3, $5, etc. but i don’t know how to increment them for each even numbered loop.
Is F$R doing what i think it is ( $F2,$F4 etc)? I can’t find the example i saw once in this forum :frowning:
The goal is to avoid copy/pasting many arg0... lines and manually increment $3,$5,…
Actually, I feel like nothing works in there… It’s not really clear for me :sweat_smile:

#@gui : Iterations = int(1,1,100)
#@gui : Filter 1 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : Value = float(0,0,10000)
#@gui : Filter 2 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : Value = float(0,0,10000)
#etc... they are all the same. 

repeat 14 {
  R:=$>+1
  V:=$R+1
  if $R%2==0
   arg0 $R,"blur $V","bilateral $V,$V,$V,$V","boxfilter $V","dilate $V","erode $V","smooth $V","sharpen $V"
  F$R=${}
  fi

 if $3 run $F2 fi   
 if $5 run $F4 fi
 if $7 run $F6 fi
# etc... # I could do : if $# run $F# $# fi 
# (if i take out $V when using arg0, but bilateral forces 4 values 
#so it just breaks everything and i don't really want to add conditions each time bilateral is used)

I’m not sure what you want, but maybe something like this?

foo :
m "foo_bilateral: bilateral $""1,$""1,$""1,$""1"
repeat 14 {
 r:=$>+1
 v:=$r+1
 if $r%2
  F$r=${arg\ $v,blur,foo_bilateral,boxfilter,dilate,erode,smooth,sharpen}
 fi
 F$r $v
}
um foo_bilateral

I’m not sure actually. I want to make a loop to do this :

arg0 $2,"blur $3","bilateral $3,$3,$3,$3","boxfilter $3","dilate $3","erode $3","smooth $3","sharpen $3"  
F2=${}
arg0 $4,"blur $5","bilateral $5,$5,$5,$5","boxfilter $5","dilate $5","erode $5","smooth $5","sharpen $5"
F4=${}
arg0 $6,"blur $7","bilateral $7,$7,$7,$7","boxfilter $7","dilate $7","erode $7","smooth $7","sharpen $7"
F6=${}
#etc...

if $3 run $F2 fi
if $5 run $F4 fi
if $7 run $F6 fi
#etc...

I’m just making my personal sandbox to mix some filters in any order and check results.

I think I got it now:

foo:
m "foo_bilateral: bilateral $""1,$""1,$""1,$""1"
$=arg

repeat $#-1 {
 r:=$>+1
 v:=$r+1
 if !($r%2)
  arg0 ${arg$r},blur\ $v,foo_bilateral\ $v,boxfilter\ $v,dilate\ $v,erode\ $v,smooth\ $v,sharpen\ $v
  F$r=${}
 fi
 if ${arg{$r}}
  run ${F$>}
 fi
}

um foo_bilateral

Thank you for the help @Reptorian.
Tried your script, though for some reason it doesn’t seem to work.
The default settings give this error :
Command 'input': File '1', format does not take any input options (options '0,0,0,0,0,0,0,0,0,0,0' specified).'
File '1'is the value of the first slider (Iterations), so if i choose iterations 4, error says file 4....
I have to select at least 2 effects (other than blur) from the menus to remove the error, but then it does not apply the effects. The only difference with the original image is that it gets an alpha channel.
If i remove the “iterations” slider, i get an error about the image having 980 channels (which is the value of the last slider i moved).

So i guess this is trickier than i thought it would be :slight_smile:
I just wish i could just slide the GUI items up and down haha.

Do you have full code for me to test?

There is nothing else since i deactivated all the other sliders and the old copy/pasted code. I’ve also deleted my own loop attempt since it never worked ^^:

So i guess this is only your code :

#@gui  An Experiment in Terror : pr_ter, pr_ter_preview
#@gui : Iterations = int(1,1,100)
#@gui : Filter 1 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : Value = float(0,0,10000)
#@gui : Filter 2 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : Value = float(0,0,10000)
#@gui : Filter 3 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : Value = float(0,0,10000)
#@gui : Filter 4 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : Value = float(0,0,10000)
#@gui : Filter 5 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : Value = float(0,0,10000)
#@gui : Filter 6 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
## @gui : Value = float(0,0,10000)
## @gui : Hue = float(0,-100,100)
## @gui : Saturation = float(0,-100,100)
## @gui : Saturation (post) = float(0,-100,100)
#@gui : sep = separator()
#@gui : note = note("<small>Author: <i><a href="http://prawnsushi.free.fr">Prawnsushi</i></a>.\
# Latest Update: <i>2023/26/09</i>.</small>")
pr_ter :


m "foo_bilateral: bilateral $""1,$""1,$""1,$""1"
$=arg

repeat $#-1 {
  r:=$>+1
  v:=$r+1
  if !($r%2)
    arg0 ${arg$r},blur\ $v,foo_bilateral\ $v,boxfilter\ $v,dilate\ $v,erode\ $v,smooth\ $v,sharpen\ $v
    F$r=${}
    fi
    if ${arg{$r}}
      run ${F$>}
      fi
    }

    um foo_bilateral


#
# arg0 $2,"blur $3","bilateral $3,$3,$3,$3","boxfilter $3","dilate $3","erode $3","smooth $3","sharpen $3"
# F2=${}
# arg0 $4,"blur $5","bilateral $5,$5,$5,$5","boxfilter $5","dilate $5","erode $5","smooth $5","sharpen $5"
# F4=${}
# arg0 $6,"blur $7","bilateral $7,$7,$7,$7","boxfilter $7","dilate $7","erode $7","smooth $7","sharpen $7"
# F6=${}
# arg0 $8,"blur $9","bilateral $9,$9,$9,$9","boxfilter $9","dilate $9","erode $9","smooth $9","sharpen $9"
# F8=${}
# arg0 $10,"blur $11","bilateral $11,$11,$11,$11","boxfilter $11","dilate $11","erode $11","smooth $11","sharpen $11"
# F10=${}
# arg0 $12,"blur $13","bilateral $13,$13,$13,$13","boxfilter $13","dilate $13","erode $13","smooth $13","sharpen $13"
# F12=${}
#
#   foreach {
#   [0]
#   l. {
#     repeat $1 {
#       if $3 run $F2 fi
#       if $5 run $F4 fi
#       if $7 run $F6 fi
#       if $9 run $F8 fi
#       if $11 run $F10 fi
#       if $13 run $F12 fi
#       if $15 adjust_colors 0,0,0,0,$15 fi
#     }
#   }
#   # rv
#   blend and,0.5
#   if $14||$16 adjust_colors 0,0,0,$14,$16 fi
#
# }

  pr_ter_preview :
  pr_ter $*

Just found out that i forgot to remove foo: haha. But it still doesn’t apply the effects.

Ok, that gives me more information. I coded it in the way that I understood your intention on the commented out code.

Result:

image

Try this:

#@gui  An Experiment in Terror : pr_ter, pr_ter_preview
#@gui : 1.Iterations = int(1,1,100)
#@gui : 2.Filter 1 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : 3.Value = float(0,0,10000)
#@gui : 4.Filter 2 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : 5.Value = float(0,0,10000)
#@gui : 6.Filter 3 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : 7.Value = float(0,0,10000)
#@gui : 8.Filter 4 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : 9.Value = float(0,0,10000)
#@gui : 10.Filter 5 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : 11.Value = float(0,0,10000)
#@gui : 12.Filter 6 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : 13.Value = float(0,0,10000)
#@gui : 14.Hue = float(0,-100,100)
#@gui : 15.Saturation = float(0,-100,100)
#@gui : 16.Saturation (post) = float(0,-100,100)
pr_ter :
  m "foo_bilateral: bilateral $""1,$""1,$""1,$""1"
  foreach {
    +_pr_ter_process_per_image ${1--4},$-2
    blend and,.5
    if $-3||$-1 adjust_colors 0,0,0,$-3,$-1 fi
  }
  um foo_bilateral
_pr_ter_process_per_image :
  $=arg
  repeat $1 {
    repeat ($#-2)/2 {
      value=${arg{$>*2+3}}
      filter_choice=${arg{$>*2+2}}
      if $value
        arg0 $filter_choice,blur\ $value,foo_bilateral\ $value,boxfilter\ $value,dilate\ $value,erode\ $value,smooth\ $value,sharpen\ $value
        run ${}
      fi
    }
    if $-1 adjust_colors 0,0,0,0,$-1 fi
  }
pr_ter_preview :
  pr_ter $*

The reason I’m using negative argument selection is to allow for dynamic amount of Filter/Value combos. In my opinion, you don’t need 6. 3-4 will do. Also, it’s hard to work with big values, I had to type in values.

Edit: You can probably make it easier to use by using something like int(1*10^x) and further adjustment with math and gui elements. This is logarithmic scaling. Hint on math part, 1*10^(x<0) is less than 1. Probably overkill.

Here it is with logarithmic scaling. Now, it’s easier to use as it feels more natural:

0 - 1
1 - 10
2 - 100
3 - 1000
4 - 10000

#@gui  An Experiment in Terror : pr_ter, pr_ter_preview
#@gui : 1.Iterations = int(1,1,100)
#@gui : 2.Filter 1 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : 3.Value = float(-.001,-.001,4)
#@gui : 4.Filter 2 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : 5.Value = float(-.001,-.001,4)
#@gui : 6.Filter 3 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : 7.Value = float(-.001,-.001,4)
#@gui : 8.Filter 4 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : 9.Value = float(-.001,-.001,4)
#@gui : 10.Filter 5 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : 11.Value = float(-.001,-.001,4)
#@gui : 12.Filter 6 = choice(0,"Blur","Bilateral","Boxfilter","Dilate","Erode","Smooth","Sharpen")
#@gui : 13.Value = float(-.001,-.001,4)
#@gui : 14.Hue = float(0,-100,100)
#@gui : 15.Saturation = float(0,-100,100)
#@gui : 16.Saturation (post) = float(0,-100,100)
pr_ter :
  m "foo_bilateral: bilateral $""1,$""1,$""1,$""1"
  foreach {
    +_pr_ter_process_per_image ${1--4},$-2
    blend and,.5
    if $-3||$-1 adjust_colors 0,0,0,$-3,$-1 fi
  }
  um foo_bilateral
_pr_ter_process_per_image :
  $=arg
  N:=($#-2)/2 # Number of Filter/Value combo
  repeat $1 {
    repeat $N {
      value:=int(10^${arg{$>*2+3}})
      filter_choice=${arg{$>*2+2}}
      if $value
        arg0 $filter_choice,blur\ $value,foo_bilateral\ $value,boxfilter\ $value,dilate\ $value,erode\ $value,smooth\ $value,sharpen\ $value
        run ${}
      fi
    }
    if $-1 adjust_colors 0,0,0,0,$-1 fi
  }
pr_ter_preview :
  pr_ter $*

I made 6 - 1 per filter in the list. But i will need more since i will add some more filters (spread, etc).
The goal is to make a sandbox so i can use all of them or just 2-3, in any order.
I will add a blend drop down menu later and make the blending optional.
I like the big values - even if they’re hard to use with sliders - because some filters can create some cool stuff when you go all out (try smooth 10000?).

I feel a bit lost with the logarithmic approach (feels lke i don’t know what i’m doing) - i wanted to use the actual values used by the filters.
I actually wanted to use textboxes but it would be nightmarish to code since typing 5,5,5,5 would create 4 variables and you wouldn’t know how many there are. I’d have to maybe use spaces or something that would just keep the text as one chain, then split it with a delimiter (or use quotes?)
Maybe i could use percents so it’s 0-100 on each slider?

Anyway thanks for making this work with better code :slight_smile: I intended to make a personal use of this but I think i’ll release it since you actually took the time to write it -who knows ? Someone might find it useful.

Here’s a quick result (used the logarithmic values so i have no clue what the settings are :sweat_smile: ) :

2 Likes

Added spread and dilate/erode_circ :


This one looks cool (used pre and post saturation : -25, 25 respectively )

Original here

Let’s see what more i can add without breaking stuff :slight_smile:

I also used negative argument selection in the 1st draft of this - because i wanted sharpen to always be the last filter. But somehow i switched later after making the drop downs. Don’t ask me why - i don’t know :slight_smile: Just random thinking.
What is $""1 btw?

2 Likes

The first local argument within merge command argument. You can think of $1 as a global argument, and $""1 as a local argument that only applies with local command scope.

1 Like

It’s actually very simple : In a command, when you want to define an item that contains $1 (e.g. a string, for a new command definition), you cannot just write str=$1 because $1 would be replaced by the command argument, when the command is instanciated (even in str="$1").
The trick is then to add an empty string between the $ and the 1, so the substitution of $1 is not done when instantiating the command.
So :

foo : 
  str1=$1
  e $str1
  str2=$""1
  e $str2

gives:

$ gmic foo argument
[gmic]./ Start G'MIC interpreter (v.3.3.1).
argument
$1
[gmic]./ End G'MIC interpreter.
1 Like

Thinking about it : another trick would be to write $\61 because 61 is the octal code for character 1. But that is probably a bad idea :slight_smile:

1 Like

Perfect for obfuscation in fact. There’s plenty of other obfuscation techniques for G’MIC if one wants to have fun doing that.