That’s going to be hard given that it’s a bit hard to maintain the code.
I made a better algorithm to make the end image better. There’s two problem - A incredible annoying bug, and having to figure out shift due to nearest neighbor scaling issue. This approach uses indexing instead.
#@cli rep_lbchstatfunc_to_pal: (eq. to rep_layers_by_channel_statistical_function_to_palette)
rep_lbchstatfunc_to_pal: rep_layers_by_channel_statistical_function_to_palette $*
#@cli rep_layers_by_channel_statistical_function_to_palette: variable
#@cli: Converts layers to palette using statistical function by channels per layers into 1x1 tile, then append them.
rep_layers_by_channel_statistical_function_to_palette: to_rgb rep_bchstatfunc $1 a x
#copy and paste below into code filter in g'mic, and copy and paste above to somewhere where you can remove it when not needed#
v=25
isw={w>h?1:w/h}
ish={h>w?1:h/w}
vw={floor($v*$isw)}
vh={floor($v*$ish)}
nsw={ceil(w/$vw)}
nsh={ceil(h/$vh)}
to_a
l[0] +r[0] {$nsw},{$nsh},1,{s},5 endl
+rep_lbchstatfunc_to_pal[^0-1] ia
split_opacity[1]
index[1] .,.85,1
a[1,2] c
r[1] {w#0+($v-(w#0%$v))},{h#0+($v-(h#0%$v))},1,{s#1},1
shift[1] {w>h?0:0},{h>w?0:0}
f[0] "i#1"
rm[1]
r[^0,{$!-1}] {ceil($vw)},{ceil($vh)},1,4,5
r[^0,{$!-1}] {w#0},{h#0},1,4,0,2
split_opacity[^{$!-1}]
l[0,{$!-1}] pal_l. r[^0] {w#0},{h#0},1,3,1 endl
ti={($!+1)/3}
repeat {($ti-1)} l[0,{$!-$ti+$>+1}] f. "i#0==i#1?255:0" to_gray. endl done
repeat {($ti-1)} l[{($>*2)+3},{$!-$ti+$>+1}] f.. "i#0==i#1?255:0" endl done
rm[^0-{$!-$ti}]
repeat {($!/2)-1} a[{$>+2},{$>+3}] c done
blend[^0-1] alpha rv[0,2] rm. split_opacity.. blend[^0] multiply a c
Some part of the image are shifted for some reason, and I don’t know how exactly do I fix that bug. There’s also the need to add shift because some areas have bigger side than the other areas. See what I mean by deleting everything after shift and checking for yourself.