G'MIC exercises

gmic sample tiger . blur[tiger~] 2

I am unable to select the second tiger using its name. :crying_cat_face:  ATM, the workaround is renaming the images that contain the tilde (~).

PS I noticed that erode and dilate no longer exhibit the negative value problem that I mentioned earlier. Did you fix it? Or did I do something different?

That’s expected, image names inside brackets can be only composed of a subset of characters (those which classically define a variable name), and ~ is not of them.
Solution : use the newly included command named, like this:

blur[${"named tiger~"}] 2

or

named tiger~
blur[${}] 2

I don’t remember exactly what was the problem sorry, but it may be I’ve fixed this already yes (I fix a lot of things, that I discover also by myself, and don’t remember of all the fixes I’ve done. Yes, I know, I should write a changelog :slight_smile: ).

That makes sense and is silly at the same time. All this, blur[${"named tiger~"}] 2, to select an image! :poop:  I would rather change its name as I said above; much shorter to type. Any chance of replacing the ~ with something else? E.g., with a number that counts up for every copy introduced?


I am still working on afre_dehaze, considering more options. Right now, I am trying to understand what this paper is doing with (14) and how I could script it. This is all we are given. It might be enough info for you but I wish papers elaborated on their work a bit more.

Basically, we are using a weight map to refine t. W and t are images but I don’t know what L and -1 are. Is L the command laplacian of a certain image? Is -1 element-wise, matrix inversion or ilaplacian? Thoughts?

PS It is from another paper: https://arxiv.org/pdf/1904.12245.pdf. You might glean more insight into it by referring to the original (updated) He et al. paper in post #373. See soft matting.

That’s a good idea, yes, maybe something as tiger_1, tiger_2, etc…
I’ll look at this tonight.

I don’t have any advice on this (I haven’t read the paper), but maybe @Jerome_Boulanger could help ?

Following up on my question regarding sort from this thread. It is actually a continuation of post #369, where I am searching for the top % of the brightest pixels.

As mentioned, I would like to understand sort better. In sum, I determined that axis=(undefined) wasn’t suitable. axis=y doesn’t seem right either. What I probably want is to sort the colours by their norms. Here is an example column. File here: column.zip (603 Bytes).

image


Update This is my solution. Thoughts?

gmic column.jpg s y repeat $! l[$>] nm {norm(I)} endl done sort_list -,b a x o sorted.jpg

However, colours don’t always stay together. See palette below. The grey is separated by the ever so slight blue.

I don’t know if I can or should order by colourfulness; i.e., grey or colourful first.

I would write:

$ gmic column.jpg l. +norm rv a x sort +,y z 1,1 endl 

sort_luminance
And yes, color won’t necessarily stay together, there are no reasons that using the norm as a sorting criterione won’t separate them in some way. Maybe another sorting criterion that involves the hue or saturation may work better ? Not sure if it’s easy to find.

I am no longer confused about grey scale morphology. Looks like all I had to do was match the range with that of binary morphology. The rest is grasping what erosion and dilation are.

Grey scale erosion (and dilation) requires a much larger kernel (about 5x the size) than its binary counterpart to be comparable, taking a lot more time to process. Now, I am wondering if there is a good way to approximate it. (There is probably a paper out there called fast grey scale morphology. :stuck_out_tongue:)

On my system, the current afre_dehaze, using grey scale morphology, takes 2 min to run on a 1200 length image. When I resize it to 1800 length, it takes 10 min! In contrast, binary morphology takes no more than a couple of seconds.

How can I apply channel changes using shared, and then change the number of channel in the original image?

sh 0,1
to_rgb.

With 4 channel Images, I expect something like this.
R,G,B,A - [0]
Gray,A - Shared Image of [0]
Gray,A becomes R,G,B
Result of [0] = R,G,B,B,A

sh 0,1 means you are taking the first two channels of your image(s).

Yes, and in those places, I would like to change it to 3 channel in place of the two channels without using s c a c.

Don’t think that is possible:

*** Error *** Command 'to_rgb': [instance(750,500,1,2,0000000011dfd040,shared)] gmic<float>::assign(): Invalid assignement request of shared instance from specified image (750,500,1,3).

Well, ok, got it. Would be nice if it works only because that means fewer lines of code would be needed to do things. Thanks!

I’m not exactly sure what procedure you’re asking about but I suppose that you’re talking about editing a channel through a shared buffer and then changing the number of channels in the original image. In G’MIC, shared buffers themselves cannot be resized as far as I know. What’s more, if you change the dimensions of an image which has any shared buffers and don’t change them back, then performing any operation on one or more buffers for that image will result in a segfault.

Aside from that, how would I do the following correctly:

rtest 20%,40%,60%,80%

rtest :
repeat 2

vara = $>*2+1
vara = $>*2+2
+r[0] ${${vara}-${varb}}
done

I’m attempting to use a subset of arguments where the start and end points of the subset are themselves variables, with the motivation being that I can use different arguments for similar procedures (for example, performing warps of different intensities on each channel individually - this is not what I actually want to do, of course). How would I do it?

I don’t know the syntax for that but this is what I would do.

rtest: skip ${1=1},${2=2},${3=3},${4=4}
  ($1,$2,$3,$4)
  repeat 4
    +r[0] {i(#1,$>)}
  done
1 Like

I can use that to get a subset of variables which is a fixed length by way of using vectors, but what about a variable-length subset just in case that’s needed?

Edit: I can use crop() to do that.

https://images.app.goo.gl/QU5LzFWsxMknPj7Y6

The above shows dots connected by lines. Reason being I’m looking at this is because it’s the key to making the gmic version of this Paint.NET plugin - Gossamer - released 10/02/2015 - Plugins - Publishing ONLY! - paint.net Forum

Since it’s the documentation, @David_Tschumperle could point me to that right location as clicking the picture goes to a link where the picture does not exist.

I’ve always preferred the GEGL kaleidoscope script to G’MIC’s one but I’m not sure where to find the GEGL source code for it and I’m also not sure how to implement a rotation in G’MIC using f.

Edit: I’ve found the source but it looks really confusing. gegl/mirrors.c at 3248572b79f5f0c4c43a514cab6aa5d75de93942 · GNOME/gegl · GitHub

Ok, I’m having a big time issue here, and scratching my head on this.

v1=0
v2=0
v3=0
v4ch1=0
v5ch2=1
v6ch3=2
v7ch1=0
v8ch2=1

v9_vsty=1
v10_v1=8
v11_v2=8
v12_v3=128
v13_op=2
v14_ang=45
v15_x=0
v16_y=0
v17_n=1

v18_vsty=1
v19_v1=8
v20_v2=8
v21_v3=128
v22_op=2
v23_ang=45
v24_x=0
v25_y=0
v26_n=1

v31_vsty=1
v32_v1=8
v33_v2=8
v34_v3=128
v35_op=2
v36_ang=45
v37_x=0
v38_y=0
v39_n=1

v40_vsty=1
v41_v1=8
v42_v2=8
v43_v3=128
v44_op=2
v45_ang=45
v46_x=0
v47_y=0
v48_n=1

v49_vsty=1
v50_v1=8
v51_v2=8
v52_v3=128
v53_op=2
v54_ang=45
v55_x=0
v56_y=0
v57_n=1

cs_mode=$v1
cmyk_mode={$cs_mode==3?4:3}
contain_alpha={$v2?1:0}
bitmode=$v3
tch={$cmyk_mode+$contain_alpha}

channels 0
r 100%,100%,100%,$tch

if {$tch==3} ($v4ch1,$v5ch2,$v6ch3)
elif {$tch==4} ($v4ch1,$v5ch2,$v6ch3,$v7ch1)
elif {$tch==5} ($v4ch1,$v5ch2,$v6ch3,$v7ch1,$v8ch2)
fi 

tc={w#1} s. x remove_duplicates tw={$!-1} if $tw<$tc v + error "Invalid Channel Order!" v - fi 

a[^0] x rv
($v1,$v2,$v3,$v4ch1,$v5ch2,$v6ch3,$v7ch1,$v8ch2,$v9_vsty,$v10_v1,$v11_v2,$v12_v3,$v13_op,$v14_ang,$v15_x,$v16_y,$v17_n,$v18_vsty,$v19_v1,$v20_v2,$v21_v3,$v22_op,$v23_ang,$v24_x,$v25_y,$v26_n,$v31_vsty,$v32_v1,$v33_v2,$v34_v3,$v35_op,$v36_ang,$v37_x,$v38_y,$v39_n,$v40_vsty,$v41_v1,$v42_v2,$v43_v3,$v44_op,$v45_ang,$v46_x,$v47_y,$v48_n,$v49_vsty,$v50_v1,$v51_v2,$v52_v3,$v53_op,$v54_ang,$v55_x,$v56_y,$v57_n)

if ($cs_mode==3||(($cs_mode>8&&$cs_mode<11)||$cs_mode<3))||$bitmode (256,256,256,256,256)
else
    if $cs_mode>3&&$cs_mode<7 (361,101,101,256)
    elif $cs_mode==7 (101,201,201,256)
    elif $cs_mode==8 (101,129,{ceil((pi)*200)},256)
    elif $cs_mode==11 (301,301,301,256)
    elif $cs_mode==12 (256,301,301,256)
    elif $cs_mode==13 (301,301,301,256)
    fi
fi
repeat $tch
sh[1] {i(#0,$>,0)}
rep_binaltquad. {crop(#2,8+11*$>,0,15+11*$>,1)},{i(#3,$<,0)},{i(#3,$<,0)},{crop(#2,15+11*$>,0,16+11*$>,1)}
rm.
done
k[1]

For some reason, crop doesn’t give me the value I’d like. Yet, 1,8,8,128,2,45,0,0,{i(#3,$>0)},{i(#3,$>0)},1 just works. So, I don’t understand what’s going on here.

Could you break it down a bit more? At this point, I am just guessing what your issue is. $>0 means that you are substituting the repeat count and appending a zero; i.e., 00, 10, 20, … Direction matters: $> vs $<.

What you are asking about doesn’t even match your code (e.g., the number of comma separated values) and your code has many typos.