Sliding window in a sparse 3d volume

Hi, I have a 3d (MxNxL) matrix, and I want to compute for a list of x,y,z (actually all x,y, and a certain z, not for each x,y,z!) a function over a i*j*k window.
The sliding window should be of size(i*j*k) but not all values in the window are the neighborhood, for example, the window can be a sphere of radius r that is bound in that square window, or it could be a cylinder or some kind of other shape.
The results I need is a MxN matrix (2D, so no convn), where for each x,y location I have the result of the function applied on x,y 3d neighborhood. MxN could be very large, I don't want to do it with loops.
Example for a window I want to slide over the 3d volume:
[x,y,z] = meshgrid(1:r,1:r,1:r);
xc = floor(r./2)+1;
yc = floor(r./2)+1;
zc = floor(r./2)+1;
sphere_window = (x-xc).^2 + (y-yc).^2 + (z-zc).^2 <= r.^2;

댓글 수: 7

Sean de Wolski
Sean de Wolski 2013년 4월 8일
What does the function look like? It might be something you could do with convn() or similar but we'll have to see the function.
Orly amsalem
Orly amsalem 2013년 4월 8일
I actually have a 2 functions in mind: 1. compute for each neighborhood a: cx = sum(sum(sum(a.*x)))./sum(a(:)); cy = sum(sum(sum(a.*y)))./sum(a(:)); cz = sum(sum(sum(a.*z)))./sum(a(:)); and the finally the distance between (cx,cy,cz) and (0,0,0) (the center). where x,y,z are coordinates. 2. For each sliding window, compute pca for the points in the neighborhood, and take the ratio between the 2 largest eigenvalues.
I think convn would be too slow for that matter, and will operate for each x,y,z while I want for each x,y and one specific z. (x*y times and not x*y*z times)
Image Analyst
Image Analyst 2013년 4월 8일
If you can do it with convn, I'd recommend that. It is highly optimized so it won't be as slow as you think. For example with a 10x10x10 cube, moving it over by 1 voxel only has to read in another 100 voxels, not a thousand.
Orly amsalem
Orly amsalem 2013년 4월 8일
convn also performs for each x,y,z, i.e. return a 3d volume also, while I need a result of 2d matrix...
Image Analyst
Image Analyst 2013년 4월 8일
Then use conv2().
Orly amsalem
Orly amsalem 2013년 4월 8일
The input is two 3d volumes and the input should be 2d matrix. Because I need the neighborhood to be 3d , but the function is performed for each x,y, not for each x,y,z
Orly amsalem
Orly amsalem 2013년 4월 8일
besides, I have no idea if it possible to do what I want with convolution...

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

질문:

2013년 4월 8일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by