The Big Bad G'MIC Thread of Silly Questions

Thanks, that’s quite nice indeed!
But i’m a wanderer, i have to explore this a bit more.
Found out i can fix the “tilted” look with even numbers here:

   R = 2*cos(pi/4+$angle*pi/360)*rot($angle°);

Which makes this tileable:

Adding points to the polygon makes it look weird but what i want is really just draw the shape once, but in a random or chosen angle. It’s just so i can switch rectangle to polygon in the previous code i posted (the bubbly chaos stuff). rectangle is cool but i can’t (can i?) use it to draw tilted rectangles/squares.
In your example the square still grows from tiny to oversized. What mod would make it keep it’s defined/original size? Like rotate would do, but without the added borders? I don’t want it to go outside the image, it would break the seamless tiling. (at least AFAIK).


Then if erode/dilate are out, maybe i could cheat by drawing the shape a few times (warning, brainless one-liner below, i hardly ever use vars in commandline mode, it’s just for testing):

gmic 800,800,1,3,255 run 'repeat 100 polygon[0] 4,{50+$>}%,{1+$>}%,{99-$>}%,{50+$>}%,{50-$>}%,{99-$>}%,{1+$>}%,{50-$>}%,1,0xFFFFFFFF,0,0,0  polygon[0] 4,{50.05+$>}%,{1.05+$>}%,{99.05-$>}%,{50.05+$>}%,{50.05-$>}%,{99.05-$>}%,{1.05+$>}%,{50.05-$>}%,1,0xFFFFFFFF,0,0,0 polygon[0] 4,{49.95+$>}%,{0.95+$>}%,{98.95-$>}%,{49.95+$>}%,{49.95-$>}%,{98.95-$>}%,{0.95+$>}%,{49.95-$>}%,1,0xFFFFFFFF,0,0,0 w. wait 25 done d'

It’s in % so it’s a bit trickier than adding/substracting one pixel to/from coords to get some thickness. As you can see, there are some gaps in between lines:
EDIT: wrong image :frowning:
BTW it seems some lines still appear thinner than others (bottom left, top right). Don’t know what causes this.

Or go crazy and simulate everything with thickline? After all, back when i was still drawing by hand (that’s so 1950 now :P) i was only using lines, not squares…

Anyway, thank you guys :slight_smile:

2 Likes

Hi, question-man here again. :person_raising_hand:

Would this be a good right way to add an alpha channel to an existing colored outline drawing ? I don’t want to lose information in the process. The ideal would be to get a binary image to append as an alpha channel.
EDIT: But then if i use black for the outline, these lines disappear in the process…

+f 0 # <<< add a black layer at the start of the script

# ...
# A bunch of drawing stuff here
# ...

+compose_channels. add to_gray.
# cut. {ia},{iM} << seen this in a tutorial by Gary, not sure if relevant here
cut. 0,1 n. 0,255
a[-2,-1] c rv # << append channel then reverse to put new layer on top

Result :

Thanks

  1. Create a four channel canvas image: blahx,blahy,1,4,0 so that all channels are zeroed out, including the alpha channel.
  2. Then draw with polygon (or whatever else of that ilk) using a four channel color argument with alpha set. To draw the problematical black color, feed polygon with color argument 0,0,0,255
  3. Canvas is now ready to be composed on top of whatever background image you may have in mind.

Hope this helps. BTW, love the color ambience of your work-in-progress. Keep on having fun…

1 Like

You just saved my day, i was getting some headache now lol.
I didn’t add an alpha layer at the start because for some reason drawing on that image would make some lines transparent instead of the background.
So in the end :

+to_a f. 0 # << changed this
ML=$1
MR:=100-$2
MT=$3
MB:=100-$4
m "rcol : u {[${17--1}][3*int(u(8)%8),3]},255" # << added ",255" to David's subcommand
if ${"is_pattern \"$12\""} pat=$12 else pat=0xFFFFFFFF badpat=1 fi

# ...
# A bunch of drawing stuff here:
repeat $5 { rectangle. {u($ML,$MR)}%,{u($MT,$MB)}%,{u($ML,$MR)}%,{u($MT,$MB)}%,1,$pat,${-rcol} } 
# ...
rv #  << still need to reverse in the end but that's ok

Result… looks like everyone’s here! Phew!:

Thanks :slight_smile:
EDIT : This also kinda solves my dilate/erode problem since dilate over alpha also thickens black lines: :sunglasses:

That looks like a math book cover. Still though, keep it up.

I can’t tell, i’ve never seen one :open_mouth:

BTW, is there any case where dilate 1 does something?

i had to +1 so that it always do something for my case:
if $11 dilate. {$11+1} fi

I don’t know, let’s make a test:

foo_test_dilate:
+dilate 1 
+neq 
echo[0] Does\ dilate\ 1\ do\ something\?\ ${arg\ iM+1,No,Yes}

Output:


C:\Windows\System32>gmic (0,1,0;0,1,1;1,1,1) foo_test_dilate
[gmic]./ Start G'MIC interpreter (v.3.3.4).
[gmic]./ Input image at position 0, with values (0,1,0;0,1,1;1,1,1) (1 image 3x3x1x1).
[gmic]./ Does dilate 1 do something? No
[gmic]./ Display images [0,1,2] = '(0,1,0;0,1,1;1,1,1), (0,1,0;0,1,1;1,1,1)_c1, (0,1,0;0,1,1;1,1,1)_c1'.
[0] = '(0,1,0;0,1,1;1,1,1)':
  size = (3,3,1,1) [36 b of float32].
  data = (0,1,0;0,1,1;1,1,1).
  min = 0, max = 1, mean = 0.666667, std = 0.5, coords_min = (0,0,0,0), coords_max = (1,0,0,0).
[1] = '(0,1,0;0,1,1;1,1,1)_c1':
  size = (3,3,1,1) [36 b of float32].
  data = (0,1,0;0,1,1;1,1,1).
  min = 0, max = 1, mean = 0.666667, std = 0.5, coords_min = (0,0,0,0), coords_max = (1,0,0,0).
[2] = '(0,1,0;0,1,1;1,1,1)_c1':
  size = (3,3,1,1) [36 b of float32].
  data = (0,0,0;0,0,0;0,0,0).
  min = 0, max = 0, mean = 0, std = 0, coords_min = (0,0,0,0), coords_max = (0,0,0,0).
[gmic]./ End G'MIC interpreter.
1 Like

No, the dilate operator replaces each pixel by the max value in a neighborhood of size N\times N centered on this pixel. If N==1, this max is the same as the current pixel value.

2 Likes

Just uploaded that thing in git:

Had to change the way it works since dilate would make some ugly stitches where lines of a different color would cross. So i decided to draw shapes and lines with the same color on separated layers. It’s less chaotic but i guess that’s ok.
I’m still not sure if it’ll be useful to someone, but who knows lol.

2 Likes

Indeed, with dilate, the max in a neighborhood is computed independently for each channel, meaning, which means the locations of the max can be at different places for different channels, resulting in color mixing in some way.

If you have a predefined colormap, it can be useful to work only with a scalar image all the way long, where values are just indices in the colormap, then at the end you use map to map the desired palette.
Doing that will ensure that the dilate operation won’t mix colors. It will just locally favor the highest index but that’s OK.

Nice filter, BTW!

Seconded.
Been here for a little over a year now. Pretty good progress for a ‘math amputee’.

Yes, with so many lines it was rather messy, almost looking like i used outline patterns when i didn’t. And TBH, i actually considered using palette mapping over a grayscale image at the beginning, but then went the “random” way again. This particular filter didn’t really need it. Next one will probably need it, but may not need dilate. Or maybe it will need it, since it can give a nice calligraphic look to splines and circles when using different x,y size values. Well, i’ll see.

(interlude: i wonder if it still has the parallax effect with the layers…)
(EDIT: it seems it does, but the use random of random dilate values won’t please epilectics… one more thing i didn’t think about)

BTW, is there any reason why spline can’t be drawn with a pattern like line or polygon?

Thanks! shift saved me a lot of time, at the start i was already thinking about how i should split the image in 4 parts, and append everything together in another way, etc… shift made things so much easier to make the seamless effect, even with so much chaos going on. You and @grosgood were a great help too, as usual :slight_smile:

Thanks for the help, too! That alpha trick was getting on my nerve… You can’t even imagine how long i struggle with some parts of my scripts (not just the maths) before asking a question here lol. I just don’t know all the g’mic commands. Having a bad memory doesn’t help either since i forget parameters or commands. Well, even if i know the commands most of the time i don’t see which can be combined effectively, so it’s a lot of trial and error.
Still, i don’t think there’s a lot of maths in my scripts. The only “advanced” stuff i did on my own was converting this in g’mic language to calculate color distance for Sick Painter. I still don’t know how i managed to do it but it worked, even though David gave me a shorter version (as usual xD). I still have to fix the alpha in this thing btw.

Anyway, next “filter” will probably take me a thousands years to complete, even if most of it should already be in SCP, which was a training, in a way.

whatis may be of some help. Let’s say you half-remember some G’MIC command that has “sharp” in it:

gosgood@lydia ~ $ gmic whatis sharp
[gmic]./ Start G'MIC interpreter (v.3.3.4).
afre_sharpenfft
blend_sharpness
gcd_reverse_unsharp
hessian_sharpen
rep_tr_pixel_sharpener
sharpen
sharpen_alpha
unsharp
unsharp_octave
[gmic]./ End G'MIC interpreter.
gosgood@lydia ~ $

It finds all the commands (with written #@cli headers) that have sharp in their names and lists them. Perhaps an item in that listing jogs your memory enough to invoke gmic help on it.

whatis is not available in a just-installed standard distribution, but it is very easy to add. In fact I use it to introduce G’MIC neophytes to the fine art of writing their own custom commands. It is just two lines. See: I want to run the — you know! — the — the — whatchamacallit command. The apply something command. You know. That command. in the introduction to tutorials.

1 Like

Thanks for the tip! I’m used to use autocompletion to find commands starting with “[whatever]” but this is so much better. I’m tempted to put it in my prawnsushi.gmic file instead of the local .gmic. Or you should put it in yours!
Or i’ll just try to remember only one command : parse_cli print,[whatchamacallit - that command]. Actually print is not needed since it’s the default, so it’s just parse_cli ,[whatwasitagain].

And i’ll try not to take long g’mic breaks like i just did haha.

I may be asking for the impossible, but is there any way to make
r=10 R:=w/$r X,Y:=-$R work when written like this :

r,R,X,Y:=10,w/$r,-$R,-$R

Obviously the latter doesn’t work since $r is not defined, and then $R fails, and so on.

If you want a one liner:

r,R,X,Y:=r=10;[r,vector3(w/r)*[1,-1,-1]]

Other solutions:

r=10
R,X,Y:=vector3(w/$r)*[1,-1,-1]
r,R,X,Y={"
 r=10;
 R=w#-1/r;
 [r,w#-1/r,-R,-R];
 "}

You can also break them into lines. Like this:

r=10 
R:=w/$r
X,Y=-$R

Haha, that looks even more confusing :sweat_smile:

Yes, i do this a lot for more readability, then i rewrite what i can to save vertical space.

I understand your examples but… still hard to read. Maybe i’ll switch to this style when the script is finished?

Here is something else that i’m trying to figure out. The script below insists on creating a new layer in Gimp :sweat_smile:
I wonder what causes this?

m "circpat : 
  r=10 R:=w/$r X,Y:=-$R 
  repeat {(h/$R)+2} { 
    repeat {(w/$R)+2} { 
      circle $X,$Y,$R,1,$7,0,0,0,255  
      X+=$R 
    }  
  X=-$R Y+=$R  
  }"
${-circpat}
um *


Hi, who are you? Where are you from?

Made a mistake on the one liner solution. Remove the $ from $r.

Anyway, glancing from the code, I think it’s a G’MIC plugin configuration problem.

Thanks, noted.

I also made a mistake in my code. Changed *2 to +2

EDIT : actually i looks like this now:


m "circpat : 
W,H:=w,h r:=$_Size+1 R:=w/$r X,Y:=-$R 
expand_xy. 1 
repeat {(h/$R)+2} { 
  repeat {(w/$R)+2} { 
    circle {$X},{$Y},$R,1,$7,0,0,0,255 X+=$R 
  } 
  X=-$R Y+=$R 
} 
r. $W,$H,100%,100%,1"

Had to expand then resize the canvas otherwise the last circles would be out of bounds by 1 px, which breaks the seamless look.
Is there a trick to know about?

David, does um * do anything? Could I use this to uncommand all internal commands?