filter that uses elements from two arrays at the same time

Posted by Gacek on Stack Overflow See other posts from Stack Overflow or by Gacek
Published on 2010-04-01T15:37:58Z Indexed on 2010/04/01 16:13 UTC
Read the original article Hit count: 300

Filed under:
|
|

Let's assume we have two arrays of the same size - A and B.

Now, we need a filter that, for a given mask size, selects elements from A, but removes the central element of the mask, and inserts there corresponding element from B.

So the 3x3 "pseudo mask" will look similar to this:

A A A
A B A
A A A

Doing something like this for averaging filter is quite simple. We can compute the mean value for elements from A without the central element, and then combine it with a proper proportion with elements from B:

h = ones(3,3);
h(2,2) =0; 
h = h/sum(h(:));
A_ave = filter2(h, A);
C = (8/9) * A_ave + (1/9) * B;

But how to do something similar for median filter (medfilt2 or even better for ordfilt2)

© Stack Overflow or respective owner

Related posts about matlab

Related posts about filter