medfilt2
result = medfilt2(x, [window=3])
Input: x, window · Output: result
What it is
Synonyms for medfilt at the Qu level: x is a length-N number vector or an Image, window an optional positional/named odd integer, default 3. On a plain vector the result is identical to medfilt(x, window) (a 1-D median); the two-dimensional median — over a window×window square, channel by channel, not separable, so the median of medians is never substituted for the real thing — only happens when x is an Image, since the image itself carries its own width and height.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = medfilt2(x, [window=3]) | x number, vector, or Imagenot documented yetwindow number, vector, or Image, optional (default 3)not documented yet | result — | Returns a value the same shape as x. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
m = [10, 200, 10; 200, 10, 200; 10, 200, 10] # a badly salt-and-peppered checkerboard
img = image_from_matrix(m)
a = medfilt2(img, 3)
b = median_filter(img, 3) # same filter, other name
print("{a.width}x{a.height} cleaned, {b.width}x{b.height} cleaned")
3x3 cleaned, 3x3 cleaned
from noise
How it works
medfilt(x, n) on a vector, medfilt(img, n) on an image. The answer to salt-and-pepper, and the reason is worth knowing: an average is pulled by an outlier in proportion to how far out it is, while a median ignores it entirely as long as fewer than half the window is corrupt. Which is also why it keeps an edge that an average smears -- a step is not an outlier to a median.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.
See also
median_filter — documented in the same entry.