pecopeco
Electrical
- Jan 16, 2004
- 1
Hello... this is the very first time I use
the newsgroups, so I don't even know if
this is the place for this kind of questions.
Anyway, here I go !
There is one thing I need to do in Matlab
VERY FAST... but the only way I can think of
uses "for" loops and it's soooo slow
This is it:
We have a 3D matrix and we want to "extract"
some "neighbourhoods" of values from that
Matrix into another 2D matrix for further
fast proccessing of those groups of values.
The extracting proccess is as follows:
- Let's call the 3D matrix 'Neighbours'.
Dimensions: AxBxC
- To the 'extracting' function we pass
4 parameters, and it returns a 2D
matrix:
M=extract(c,dA,dB,dC);
'c' is >0 and <=C
'dA' is >-1
'dB' is >-1
'dC' is >-1
- Now, there are AxB neighbourhoods to be
extracted, each one with (2*dA+1)*(2*dB+1)*
*(2*dC+1) members (let's call this number 'm')
Then the returning 2D matrix, M, is of dimensions
m x (AxB).
I.e., (AxB) columns, each one corresponding to
a neighbourhood, containing the 'm' members
of each neighbourhood each one.
- Finally, each neighbourhood is obtained liked this:
* For some value in Neighbours
located at (x,y)) we take the following values:
Neighbours(x-dA:x+dA,y-dB:y+dB,c-dC:c+dC);
* We do this for every value in Neighbours
obtaining (AxB) neighbourhoods at the end, each
one corresponding to a column in M (the returning
2D matrix).
One more thing... for values NEAR THE EDGES of the
3D matrix, MIRROWED values are considered (that is,
the 3D matrix is extended by simetry.
Buff... I've tried to be clear
So... doing this the 'C' way is trivial, but in
Matlab in takes way to much time.
Please, if you know how to deal with this problem
"the Matlab way" let me know.
Thanks in advance.
Fernando.