Without knowing much about what this is doing (something to do with SNR I guess given average/stddev?), the main thing I’d try to do is remove the ‘+l[^0]’ part. It’s the most expensive part other than split_details because it copies all the split images. Here’s one way without that (I added a parameter for number of levels):
deets : skip ${1=5}
r={[im,iM]} split_details $1
l[^0]
$!,1,1,1,"(ia#x-im#x)/sqrt(iv#x)" log. /. {im}
repeat {$!-1} -*[$>] {@$>} done rm.
endl
+ n $r
The first step was to rearrange the maths to avoid having to normalize to (0,1). It turns out that’s just a case of subtracting image minimum from the average, because this is a ratio and variance is not affected by the minimum.
Then instead of using separate variables to store the values you can use a 5x1 ‘image’ which is very like a 1 dimension array. That way when fill loops over each point you can reference the relevant image using the x coord.
Finally now that we have an array the log part, minimum and division can all be done to the array as a whole. Then it’s a case of looping over the images to multiply by the relevant array value: {@$>}.
I’m really not sure what you’re doing maths wise here but ratios of logs amount to taking a log of the numerator with a base of the denominator. What I mean is you have log10 (a) / log10 (b) and that’s the same as logb (a) which also makes the base irrelevant in the fraction.
Incidentally I really don’t like usual log() syntax as if it were a function, I tend to treat it as an operator in my scribbles. I find it easier to write x|10 instead of log10 (x). After all it’s only repeated division in a way!