Say I have a matrix A, which is of dimension 4x4.
Now I want to downsample this matrix by a factor 2 to get a new matrix B of dimension 2x2.
I want to downsample in the following way :
Let A be
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
I want B to be
3.5000 11.5000
5.5000 13.5000
To get B(1,1) = I take mean (1, 5, 2 and 6)
To get B(1,2) = I take mean (9, 13, 10 and 14)
To get B(2,1) = I take mean (3, 7, 4 and 8) and so on.
So for every element in B, I take the corresponding 2x2 block from A and take the mean of it.
In my case, the matrix A is of large dimension. Also, the downsampling factor could be arbitrary.
For example, A =
1 7 13 19 25 31
2 8 14 20 26 32
3 9 15 21 27 33
4 10 16 22 28 34
5 11 17 23 29 35
6 12 18 24 30 36
For downsampling of size 3/2.
Matrix B will be of size 4x4.
For every B unit I would have to take non-overlapping 1.5x1.5 blocks of A.
For example,
B(1,1) = mean(1, 0.5x7, 0.5x2, 0.5x8)
B(2,1) = mean(0.5x2, 0.5x8, 3, 9)
B(3,1) = mean(4, 0.5x10, 0.5x5, 0.5x11)
B(4,1) = mean(0.5x5, 0.5x11, 6, 12)
and so on.
Is there a faster way to do this without for loops?