# G'MIC exercises

Is this a bug or just math? I applied this curve to i

x-axis should be [0,1]

and it turned tiger into

In fact, this happens to every image.

@afre which command did you use for that?

Here is my command, the part that is causing this problem. It happens when the parameter is between [-126,-120ish]. I realize that it likely has to do with {2^-126} being an extreme value of 1.1754943508222875e-038. A lower value yields an image of 0s.

gmic sp tiger,barbara hlg_afre -126 to_rgb a x
hlg_afre: skip \${1=0}
n 0,1 * {2^\$1}
f "a=.17883277;b=.28466892;c=.55991073;
if(i>1/12,a*log(12*i-b)+c,sqrt(3*i))"
n 0,1

Tested here on my Ubuntu Linux, and it works without any banding effect.

It is always Windows’ fault, isn’t it?

1 Like

I came across something interesting. I was having some G’MIC fun when I made a typo. y50_afre is supposed to take in one parameter (forgot to add a ,). I wonder what is going on and how I could arrive at “Typo” without incorrect syntax.

texture_afre: skip \${1=1},\${2=10}
repeat \$! l[\$>]
n 0,255
+l
+l
if \$1 gradient_orientation 2 n 0,1 + y50_afre # ,
b 1,1,1
endl
*. {255*\$2/iM} +
n 0,255
endl
+l.. n 0,1 f gauss(i-.5) n 0,1 endl
endl done

No typo

Typo

I like the second one better even though the first one is more like the original picture.

When the , is commented, then else is passed as first argument of command y50_afre, and the test if \$1 does not hold (there is no file with filename else that exists).
After returning from command y50_afre , the next command to be executed is gradient_norm (as else was not considered to be a command, but an argument to a command).

So, to get the same behavior, you should probably write y50_afre 0 gradient norm instead of y50_afre.

Thanks, I suspected as much. When debugging the commands, I must have made a few additional typos that confused me. I will add this to my the fun with afre thread.

When I paste a GUI filter into user.gmic, it loads properly in the plugin; but when I put it into another *.gmic and load it with cli_start, it doesn’t get picked up.

Closest solution to the 6 layers to 3 layers blend problem found! Not quite the solution as the 3rd layer seem to show blending if using 4 layers.

repeat {int(\$!/2)} l[\$>,{\$>+1}] f "(i#0+i#1)/2"  endl done

The problem is even if I put if {\$>%2==0} fi, it doesn’t work like the blend[standard] approach. Just this little step to finishing the modo cli command I have been working on.

It depends on which layers you would like to blend together. I mean, there are many ways to go from 6→3 alone. Right now, it looks like you are blending 0-3 layers when you have 6 layers. Would blending like this work in the case of 4→3?

gmic sp dog,cat,tiger,flower blend[0-1] average

PS If I recall correctly, the plugin has layer modes that might be useful to learn from.

I would like to see either odd or even layers to show blend result using 2 layers and no overlaps. Like how the blend standard does it. I copied and pasted the relevant part of blend standard and edited into my WIP modo CLI and it does not seem to behave similar. So, no to your question.

1,2,3,4,5,6 -> [1,2], [3,4], [5,6]

@afre Found the solution after thinking of the increment at one. Thanks. Now, this behaves exactly like I wanted.

repeat {\$!/2} l[{\$>*2},{\$>*2+1}]
f[1] "(i#0+i#1)/2"
-endl done

Loops aren’t so bad after all, just a little confusing at first. But, then again, I had that experience with c++ programming.

It was a fun exercise. Sorry, I kept on messing up my example. This one should be correct. Basically, it pairs up the layers with a choice of which odd layer to leave out; e.g.:

1,2,3,4,5,6 → [1,2],[3,4],[5,6]
1,2,3,4,5 → [1,2],[3,4],[5] or [1],[2,3],[4,5]
etc.

\$1 → how many sample images to insert (edit: random; could be the same in a row)
\$2 → which odd one to leave out; 1=first, 0=last

blend_test_afre: skip \${1=6},\${2=1}
repeat \$1
sp
done
if {\$1%2==0} a="0--1" elif \$2 a="1--1" else a="0--2" fi
l[\$a]
repeat {if(\$!%2,\$!/2-1,\$!/2)}
blend[\$>,{\$>+1}] average
done
endl

2 Likes

That’s a lot better than my attempt with my modo cli code. I did however, added a way to create blended and reversed blended while the alpha is based off top to below blending. I think that a combination of those techniques could lead to something that’s fully flexible with blending layers, but that’s going to take a while.

I tried seamcarve for the first time. This is a comparison with it and IM’s implementation. IM’s looks better to me on the left edge. Anything you could do @garagecoder?

gmic sp tiger seamcarve 75% o tiger_gmic.png

magick tiger.png -liquid-rescale 75x100%! tiger_im.png

Sorry probably not, it’s based on a more complex real time algorithm which sacrifices some quality for speed. David already added some clever interpolation as well. Having said that, there are some pending feature requests to look at which might help

Edit: seamcarving will generally struggle with images having global “high energy”, i.e. no smooth areas.

I don’t know where to put this on github, so I’m going to leave this here and mentioned that I fixed Layer Cake. I know @Joan_Rake1 made it, but he isn’t here at all. The layer goes in the correct order when output layers are on. The preview also works as expected.

#@gui Layer Cake : fx_layer_cake, fx_layer_cake_preview(1)
#@gui : note = note("Splits image into annular or circular layers and rotates each layer. Based on <a href="https://forums.getpaint.net/topic/26566-layer-cake-plugin/">the Paint.NET plugin</a>.")
#@gui : Iterations = int(4,1,32)
#@gui : Angle at Centre = float(360,-1440,1440)
#@gui : Angle Times Iteration = bool(0)
#@gui : Size = float(75,0,200)
#@gui : Centre = point(50,50,0,1,255,255,255,175)
#@gui : Boundary = choice(3,"None","Nearest","Periodic","Mirror")
#@gui : Interpolation = choice(1,"None","Linear","Bicubic")
#@gui : Blur = float(0,0,200)
#@gui : sep = separator()
#@gui : Anti-Alias Amplitude = float(30,0,100)
#@gui : Edge Threshold (%) = float(0,0,100)
#@gui : Smoothness = float(3,0,10)
#@gui : Output Layers = choice("Off","Hollow","Filled")
#@gui : sep = separator(), Preview type = choice("Full","Forward horizontal","Forward vertical","Backward horizontal","Backward vertical","Duplicate top","Duplicate left","Duplicate bottom","Duplicate right","Duplicate horizontal","Duplicate vertical","Checkered","Checkered inverse"), Preview split = point(50,50,0,0,200,200,200,0,10,0)
fx_layer_cake :
repeat \$! l[\$>]
iter=\$1
angle=\$2
if \$3 angle*=\$iter fi
size=\$4/2
to_rgba split_opacity to_rgb
repeat 2
part={1-\$>}
l[\$part]
repeat \$iter
[0] rotate[-1] {\$angle/\$iter*(\$>+1)},\$8,\$7,\$5%,\$6%
100%,100%,1,1 ellipse. \$5%,\$6%,{\$size/\$iter*(\$iter-\$>)}%,{\$size/\$iter*(\$iter-\$>)}%,0,1,255
if {\$13!=2} ellipse. \$5%,\$6%,{\$size/\$iter*(\$iter-1-\$>)}%,{\$size/\$iter*(\$iter-1-\$>)}%,0,1,1 fi
blur. {\$9/\$iter}
fx_smooth_antialias. \${10-12}
blend[-1,-2] multiply
done
if {\$13!=2} 100%,100%,1,1 fc. 255,255,255 ellipse. \$5%,\$6%,{\$size}%,{\$size}%,0,1,0
blur. {\$9/\$iter}
fx_smooth_antialias. \${9-11}
blend[-1,0] multiply fi
if \$part to_gray fi
endl
done
list={int(\$!/2)}
repeat {\$list} a[\$>,\$list] c done
skip {\$13==0}
if {\$13} rv fi
endl
done
fx_layer_cake_preview:
if {!\$13} gui_split_preview "fx_layer_cake \$*",\${-3--1} else fx_layer_cake \${1-12},0 fi

I followed this up with a joke but it is a real problem for me in Windows. The extreme banding occurs when I display the images and when I output to file.

Similar issue with apply_tiles. Using the example in the docs, I am not getting the nice interpolation that it should be getting.

From my output

From docs