# Matrix Standard Deviation in 3D neighborhood

4 ビュー (過去 30 日間)
Wajahat 2012 年 4 月 10 日
Hi
I have a 3D matrix (NxNxM) and I want to compute standard deviation in a sliding window of, say, 3x3xM which means a square window going across all the matrices (or slices) but sliding in 2D only? Can anyone help me on this.
stdfilt() does not do what I want. It computes a 3x3x(odd number) window standard deviation which is perhaps sliding in depth or 3rd dimension as well.
Best Regards
Wajahat

サインインしてコメントする。

### 採用された回答

Andrei Bobrov 2012 年 4 月 10 日
% I - your 3D matrix - array(NxNxM)
s = size(I);
out = zeros(s(1),s(2));
for j1 = 1:size(I,1)
for j2 = 1:size(I,2)
out(j1,j2) = std2(k(j1 + (0:2),j2 + (0:2),:));
end
end

サインインしてコメントする。

### その他の回答 (1 件)

Sean de Wolski 2012 年 4 月 10 日
stdfilt() will ignore the three-dimensional component if you tell it to:
x3 = stdfilt(repmat(magic(10),[1 1 3]),ones(3,3,1)) %three-d array, all slices equal
x1 = stdfilt(magic(10),ones(3,3,1)) %two-d array
all equal?
all(all(all(bsxfun(@eq,x3,x1))))
##### 1 件のコメント表示非表示 なし
Wajahat 2012 年 4 月 12 日
I do not want to ignore the three dimensional component, I want to include it but I want a 2D array at the end.
As I have understood after the two answers, x3=stdfilt(repmat(magic(10),[1 1 3]), ones(3,3,5));
x3=x3(:,:,1);
will also do the same thing as Andrei Bobrov answer above.
With a window of 5 in depth, stdfilt() will center the window on the first slice and will include all the slices of 3-Slice 3D array while having a 3x3 window in 2D. Window size in depth will be limited by the number of available slices.
The documentation for stdfilt() should also explain how the selected neighborhood or window is placed in 3D.

サインインしてコメントする。

### カテゴリ

Find more on Elementary Math in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!