I have a large matrix from which I would like to gather a collection of submatrices. If my matrix is NxN and the submatrix size is MxM, I want to collect I=(N - M + 1)^2 submatrices. In other words I want one MxM submatrix for each element in the original matrix that can be in the top-left corner of such a matrix.
Here’s the code I have:
for y = 1:I
for x = 1:I
index = (y - 1) * I + x;
block_set(index) = big_mat(x:x+M-1, y:y+M-1)
endfor
endfor
The output if a) wrong, and b) implying there is something in the big_mat(x:x+M-1, y:y+M-1) expression that can get me what I want without needing the two for loops. Any help would be much appreciated
There seem to be a few things wrong in your code. Here’s how I’d do it if I were to use the double loop:
EDIT
I just saw that there is an implementation of im2col for Octave. Thus, you can rewrite the double-loop as
This is probably faster, and saves lots of digital trees.