Sliding max window and its average for multi-dimensional arrays

后端 未结 3 1295
暖寄归人
暖寄归人 2021-02-08 08:59

I have a 60 x 21 x 700 matrix, where the 60 x 21 represent a pressure output x number of frames. I want to find the 2 x

3条回答
  •  花落未央
    2021-02-08 09:32

    A moving average can be done with a simple convolution. It has to be 2D in your case, so:

    A = [01 02 02 01 01
         02 01 01 02 02
         02 03 04 04 03
         01 02 06 10 05
         02 02 08 09 05];
    
    B = [1 1;1 1] / 4 ; %// prepare moving average filter [2x2]
    
    C = conv2(A,B,'valid') ; %// perform 2D moving average
    

    Produces:

    C =
        1.5     1.5     1.5     1.5
        2       2.25    2.75    2.75
        2       3.75    6       5.5
        1.75    4.5     8.25    7.25
    

    Which is exactly the average of each of your [2x2] areas.

提交回复
热议问题