How to find neighbors in 4D array in MATLAB? -



How to find neighbors in 4D array in MATLAB? -

i bit confused , appreciate help.

i have read many posts finding neighboring pixels, beingness extremely helpful:

http://blogs.mathworks.com/steve/2008/02/25/neighbor-indexing-2/

however have problem applying on 4d matrix (a) size(a)=[8 340 340 15]. represents 8 groups of 3d images (15 slices each) of want neighbors. not sure size utilize in order calculate offsets. code tried, think not working because offsets should adapted 4 dimensions? how can without loop?

%a 4d matrix 0 or 1 values aidx = find(a); % loop here? [~,m,~,~] =size(a); neighbor_offsets = [-1, m, 1, -m]'; neighbors_idx = bsxfun(@plus, aidx', neighbor_offsets(:)); neighbors = b(neighbors_idx);

thanks, ziggy

have considered using convn?

msk = [0 1 0; 1 0 1; 0 1 0]; msk4d = permute( msk, [3 1 2 4] ); % create 1-3-3-1 mask neighbors_idx = find( convn( a, msk4d, 'same' ) > 0 );

you might find conndef useful defining basic msk in general way.

matlab multidimensional-array neighbours

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -