Taking a break from that thing. Went to revisit a old problem.
As @afre was in that thread, I’ll let him know it has been solved - Sort images according to N-Sized Channels
This can work on 20 channels too.
I do think it can be extended though. It’s slow though.
@David_Tschumperle How I would extend this per axis akin to what you did with autocrop?
#@cli rep_sort_colors:
#@cli : Sort pixels by their color.
rep_sort_colors:
m __$0_store_level:"
if s>1
N:=$!
+channels {s-1}
store[-$N--1] v$""1
channels 0,{s-2}
else
store v$""1
fi
"
foreach {
n,w,h,d,s,whd={n},{w},{h},{d},{s},{whd}
mirror. c
resize $whd,1,1,100%,-1
repeat $s {
foreach {
+channels {s-1}
pixelsort.. +,x,[-1]
sort.
+discard. x
resize. 100%,1,1,2,-1
start_value:=i[#-2,0]
eval[-2] >"begin(
test_value=$start_value;
ix=ex=p=0;
);
i==test_value?(ex=x):(
I[#-1,p++]=[ix,ex];
ix=ex=x;
test_value=i;
);
end(
I[#-1,p]=[ix,ex];
);
"
rm[-2]
repeat w {
+crop[0] {I[#1,$>]}
}
rm[0,1]
}
__$0_store_level $<
}
repeat $s {
N:=$!
${v$<}
a[$N--1] x
}
a c
resize $w,$h,$d,100%,-1
}