[英]Find “external” elements bigger than a threshold value in a 3D matrix
I was wondering if someone could help me come up with a code for a 3D image I'm working on wright now. 我想知道是否有人可以帮助我为我现在正在处理的3D图像提供代码。
I've got a simple 3D matrix: 我有一个简单的3D矩阵:
A(:,:,1) = A(:,:,1)=
0 7 4
0 32 9
4 3 1
A(:,:,2) = A(:,:,2)=
6 0 4
3 4 6
2 3 11
A(:,:,3) = A(:,:,3)=
12 2 4
10 20 6
14 3 2
I would like to find those values that are bigger than a threshold value (for example biger than 7). 我想找到那些大于阈值(例如,大于7)的值。 However I only want those that are exterior elements, that is, not "central" elements (the 32 on the first layer of the matrix shouldn't be marked as a maximum) 但是,我只希望那些是外部元素的元素,而不是“中心”元素(矩阵第一层的32不应标记为最大值)
(I'm working with a bigger matrix but I guess that once I'm able to do this for the small 3D matrix from above, it won't be difficult to do it for larger ones). (我正在使用更大的矩阵,但是我想一旦能够从上方对较小的3D矩阵执行此操作,对于较大的3D矩阵将不难做到)。
Thank you a lot 非常感谢
Try this: 尝试这个:
A = randn(4,4,4); % data. Arbitrary size
th = 1; % threshold
ind = find(A>th);
[x y z] = ind2sub(size(A), ind);
ext = find((x==1)|(x==size(A,1))|(y==1)|(y==size(A,2))|(z==1)|(z==size(A,3)));
ind_solution = ind(ext); % linear index of desired values
solution = A(ind_solution) % desired values
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.