I am working with vImages in Cocoa Touch, which in my case are basically ARGB-float-Arrays, and I need to do a subsampling. Low pass filtering is no problem using the vImage functions but how do I select one out 2x2 pixels (assuming I want to subsample by factor 2)? Of course I could use a vDSP stride function, but this only works for horizontal subsampling, not vertical subsampling.
I hope the following will clarify what I intend to do. I wish to select all pixels marked with an X as shown in this image:
X O X O X O
O O O O O O
X O X O X O
O O O O O O
X O X O X O
O O O O O O
But since the memory is linear, my array looks like this:
X O X O X O O O O O O O X O X O X O O O O O O O X O X O X O O O O O O O
How can I perform subsampling in a reasonable fashion?
EDIT: I am looking for an efficient way to do a two dimensional downsampling of a given bitmap stored as a one dimensional float-array (that includes negative values).
The reality is that when you're doing this sort of subsampling, there isn't really anything clever that can be done; strided memory access doesn't admit many tricks to go fast, so any library code you use will be essentially equivalent to the C code you might write yourself in a few minutes. I would use a simple C implementation.
I believe that this can be done reasonably efficiently on the GPU, but that won't be a performance win unless your data is already in a GPU context. If you have to transfer the data there first, that cost will swamp any performance savings in the actual operation.