G'MIC exercises

I will give you just the two rows solution. I think this looks good.

foo_two_rows:
(0,0,1,2,3,4,4;0,0,1,2,3,4,4)

{ceil(w#-2/7)},{h#-1},1,1

f. "begin(
  const vs=7;
  const ww=w#-2;
 );
 m=0;
 px=x*vs;
 k=[crop(#-2,px,y,z,c,vs,1,1,1)];
 for(p=0,p<vs&&px<ww,p++,
  m=m+(inrange(p+1,0,vs,1,0)?k[p+1]:0)-(inrange(p-2,0,vs,1,0)?k[p-2]:0);
  i(#-2,px,y,z,c)=m;
  px++;
 );
 "

Looks more involved than I thought…

Basically, G’MIC processes every pixel in the xyz order. I want it to process by rows, columns or tiles. If I use crop, it will crop for every pixel rather than the number of rows, columns or tiles.

The reason I used crop is that I thought that you wanted the values using the formula specified by your libreoffice sample.The small image is used to speed up the process, and you can use : or * in the beginning of the small image. In fact, this was a technique I used for rep_axis_streak where either row or column are processed in the parallel, and this speeds up the process much faster than if it were done via serial processing.

E.g., instead of processing from AI in xy order, I want to process A1A3, B1B3 and C1C3 in parallel. But if the Bs required values from the As, then A's would be retrieved, since As are processed before Bs. So, there are two cases: a) sets are processed in isolation and b) sets depend on previous sets.

image

@afre I have a idea. You could use shared to separate row, then use the parallel trick. Hope I read it right this time.

Side note, this is why I wanted a built-in parallel_for option for math evaluator.

There is also doing run(f. parallel_processing), but yeah, that’s gonna slow things a lot.

I could certainly do

gmic (0,0;0,0;1,1;2,2;3,3;4,4;4,4) s x Acolumn a x

where Acolumn processes the columns in isolation, but I want to learn how to do it entirely in the math interpreter so that a) I don’t have to alternate interpreters and b) I can do more sophisticated things such as (overlapped) tiling, and c) use and preserve high precision if needed. I am not a natural at coding, so it is hard for me to know where to begin or even read others’ code examples.

Actually, that would be a good solution. However, it’s a slow approach. Hence why I think parallel_for should be a thing and that should only work only in serial processing i.e “>”.

In that case, you have to split your image first into different columns, and use a fill on each one to do the computation of all their values in parallel.
In the fill, you can still access the values of the other columns if necessary (with i[#ind,pos]), where ind is the indice of the column image you want to access).

Okay, so I am on the right track. Thanks for your input. Still, I want to see if I could do all of it within the math interpreter.

Not if you enable parallelization. In the math interpreter, parallelization is all or nothing.
You cannot say : “parallelize only the computations for the first column, then for the second, then for the third.”

I forget if we have gone through this yet: I would like to graph one colour channel against another. What is a good way to visualize that?


This is a first dumb try.

gmic sp tiger channels 0,1 s c n 0,255 round +f. 0 \
  repeat 255 circle. {0,i($^>)},{1,i($^>)},1,255,255,255 done \
  a y o redgreenscatter.png

foo :
  sp tiger
  channels 0,1 s c
  256,256
  eval... "
    i0 = i;
    i1 = i(#-2);
    i(#-1,i0,i1) = 1"

Good. One last thing to add would be the axes lines and labels.

Wouldn’t it be easier to do this?

foo:
 sp tiger
 channels 0,1
 256,256
 eval.. "i(#-1,I)=1;"

I try to avoid s c as much as possible myself.

EDIT:

Fixed.

The difference is that there’s less lines involved. It also avoid s c.

I is channel 0 value and channel 1 value.

True but I am still used manipulating images outside of the math interpreter, so I will be using shared for efficient processing. Also, more intense changes require a combination of multiple fills and evals.

More importantly, if I want to compare two images, it makes complete sense for us to see the two images being compared alongside the scatter plot.

I’m now working on alphabet-related task. Here’s my question:

Let’s say I have 6 inputs. The command I want will loop through variable of alphabet starting a to z and assign each inputs to each letter.

How would I create this command?

Something like this if you catch my drift.

 id=0
 forloop(#input){alp(id)=$(id+1)} 

If you’re curious on why, I’m creating a new attractor function that improves upon rep_trsa, and I will rename Attractor to TR’s Strange Attractor, and then make the new attractor filter as Attractor.

Another question. Let’s say I have these inputs

$1=id_a+id_b+id_c+id_d+id_e+id_f+id_g+id_h+id_i+id_aa
$2=1
$3=2
$4=1
$5=6
$6=1
$7=1

Each inputs after the first one correspond to the letter, and after z, it corresponds to aa, ab, and ac. In addition, I would like to assign the inputs to the corresponding variables. Like id_a=$2 and id_c=$4.

Question. This would go to @David_Tschumperle. On GUI element, when using point, what does the ? in point(50,50,?,?,200,200,200,0,10) mean? I change them, but they do nothing?

Well, it has no meaning, where did you find such a line ?

Everywhere.

Also, I noticed the last two numbers. They don’t mean anything either, do they?

Look at the doc at the beginning og gmic_stdlib.gmic:

#      _ 'point(_X,_Y,_removable={ -1 | 0 | 1 },_burst={ 0 | 1 },_R,_G,_B,_[-]A,_radius[%])':
#          Add X,Y parameters (as a moveable point over the preview).
1 Like