I made a new CLI command that some coders might find useful. Thanks for David to point out to get/set, and I went to look into v2s to solve it:
It’s rep_extract_unique_values_and_count, and it doesn’t have arguments. I should add a warning that it only works on int though, but eh.
You can see output here:
D:\Programs\G'MIC\gmic-community>gmic (1,1,1,5,5,5,5,5,5,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3) rep_extract_unique_values_and_count
[gmic]./ Start G'MIC interpreter (v.3.3.6).
[gmic]./ Input image at position 0, with values (1,1,1,5,5,5,5,5,5,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3) (1 image 24x1x1x1).
[gmic]./ Display image [0] = '[unnamed]'.
[0] = '[unnamed]':
size = (4,1,1,2) [32 b of float32].
data = (1,5,2,3^3,6,3,12).
min = 1, max = 12, mean = 4.375, std = 3.46152, coords_min = (0,0,0,0), coords_max = (3,0,0,1).
[gmic]./ End G'MIC interpreter.
1 has 3 occurrence, and it appeared first.
5 has 6 occurence, and it appeared second.
…
Leaving this pushed code here for example:
#@cli rep_extract_unique_values_and_count:
#@cli : Extract Unique values from a image starting from 0,0,0,0, and then outputs unique values only with the count.
rep_extract_unique_values_and_count:
foreach {
current_img_ind=key_{$>}_
{whds#-1},1,1,2
eval[-2] >"begin(
key='"$current_img_ind"';
mi=0;
);
isnan(value=get([key,v2s(i,16,16)]))?(
I[#-1,mi]=[i,1];
set([key,v2s(i,16,16)],mi);
++mi;
):(
++i(#-1,value,0,0,1);
);
end(resize(#-1,mi,1,1,2,0););"
rm..
}
And I like that G’MIC can support something akin to dictionary in math parser.
Anyway, this is a good case study for @prawnsushi on dictionary.
It’s not a particularly fast solution, but for parsing small images, that is just fine and dandy.