Rolling (time) average of a timeseries of images

Hi all,

I am new to Julia, and this may be a very straightforward question. I have a timeseries of images, and I am trying to calculate a pixel-wise rolling time average. The obvious choice for doing this would be the mapwindow ffunction from the Images.jl package. For instance, if I want a rolling time average (where time is the third dimension) with window size 5, the line would be time_mean = mapwindow(mean, timeseries, (1,1,5), “reflect”), but I got an error trying this, I think because mapwindow tries to pad each dimension, even if the input window size for that dimension is 1 (which would correspond to padding 0 indices). At least that was the way I understood the error message. Is there a way to make this work with mapwindow and if not, is there an alternative way to do this?

To move a rolling-sum window along efficiently, just add the new first frame and subtract the old last frame. No need to use any library function, as that is just a basic loop.

Hi there,

This is a peculiar error indeed. Would you file an issue in ImageFiltering.jl (where the mapwindow function lives)?

Interestingly, ; border = "replicate" (the default) does work fine, as does border = Inner(), but not "reflect" or NoPad(). I’m not familiar enough to be sure that it’s not my fault, but since the underlying padding algorithm seems to work just fine with reflect, you can circumvent the problem by preapplying padding and using Inner() to discard the padded edges.

testim = Gray.(rand(20,20,15))
mywindow = (1,1,5)
pad = floor.(Int, mywindow ./ 2) # (0,0,2) or just hardcode the necessary padding
paddedimages = padarray(testim, Pad(:reflect, pad)) # here :reflect does work
filteredimages = mapwindow(mean, paddedimages, mywindow; border = Inner())