Replace loop over image stack calculations?

What is the best way to do the calculations below without a for loop?

// assume these two waves exist already
make/N=(100,100,200) imgwave= // ... (filled with some image data)
make/N=(200)/D ifrac

// how do I handle this part without a for loop?
variable ic
for (ic = 0;ic<200;ic+=1)
    WaveStats/Q/M=1 imgwave[][][ic]
    ifrac[ic] = V_sum/(V_npnts*V_max)

For reference, I am computing the fraction of white level in a threshold image going through each plane in a stack.

How about this:

Function Test()
    make/O/N=(100,100,200) ImageWave=gnoise(1)
    make/O/N=(200)/D ifrac

    Variable t=StartMSTimer
    Redimension/N=(100*100*200) ImageWave
    Redimension/N=(100*100,200) ImageWave
    MultiThread ifrac[]=DoStuffFunction(ImageWave, p)

Threadsafe Function DoStuffFunction(ImageWave, col)
Wave ImageWave
Variable col
    Duplicate/O/FREE/R=[][col] ImageWave, SingleColWave
    Return Mean(SingleColWave)/WaveMax(SingleColWave)


I guess I could have done it without the redimension, but I initially tried to make it work with MatrixOP, and for that the redimension was convenient.

just as example to use MatrixOP without Redimension:


function foo()
    make/O/N=(100,100,200) imgwave= p+r
    make/O/D/N=(200) iFrac

    Multithread iFrac = WorkerFunc(imgwave,p)
Threadsafe function WorkerFunc(w, n)
    wave w
    variable n

    MatrixOP/FREE val = mean(layer(w,n)) / maxVal(layer(w,n))
    return val[0]