Consider, I have the following matrix
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
I want to retrieve the values in even indices (both x and y indices are even) without using for loop.
0 2
8 10
I have big sized images (many of 5000*5000+ grayscale matrices). Using for loop doesn't seem to be the best way. I'd like to hear if there is better way than for loops.
I tried using the following mask, then do the operations but it is not efficient because I need to do 4*n^2 multiplication rather than n^2(Assume original image is 2n*2n)
1 0 1 0
0 0 0 0
1 0 1 0
0 0 0 0
Note that, I do multiple operations on the matrix. Any help is appreciated.
Thanks in advance,
You can remove the useless rows and columns, and work on a matrix with half the size of the original matrix.
You can do this easily with the
resizefunction, with nearest interpolation:Then the values in
resare only the values at the indices you need:In order to restore the values to original position, you can use the Kronecker product (not available in OpenCV, but can be easily implemented) with a suitable pattern. This will produce:
Code: