basic Weighted Median filter

is there a beginner method for this filter?
if:
I = [10, 200, 21; 7, 9, 10; 200, 20, 50];
and after adding zeros:
0 0 0 0 0
0 10 200 21 0
0 7 9 10 0
0 200 20 50 0
0 0 0 0 0
w = [1, 2, 1; 2, 3, 2; 1, 2, 1];
it should result in [0, 0, 0, 0, 0, 0, 10, 10, 10, 200, 200, 0, 7, 7, 9] for number 10 (2,2)
and so on for each number.
without using Matlab functions (so only by using For loops, If conditions and so on... )

1 个评论

i managed to write this:
I = [10, 200, 21; 7, 9, 10; 200, 20, 50];
[r, c] = size(I);
IZ = zeros(r + 2, c + 2);
IZ(2:end - 1, 2:end - 1) = I;
w = [1, 2, 1; 2, 3, 2; 1, 2, 1];
for n = 1:r
for m = 1:c
P = 1;
for i = 1:3
for j = 1:3
for t=1:w(i,j)
temp(P) = IZ(i+(n-1), j+(m-1));
P = P + 1;
end
end
end
temp = sort(temp);
O(n, m) = temp(round(length(temp)/2));
end
end
is there a way to simplify the loops more?

请先登录,再进行评论。

回答(0 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by