# Exercise MF: median filter

## Detailed specification

You need to implement the following function:

```void mf(int ny, int nx, int hy, int hx, const float* in, float* out)
```

Here `in` and `out` are pointers to `float` arrays, each of them contains `ny*nx` elements (these will be floating point numbers between 0.0 and 1.0). The arrays are already allocated by whoever calls this function; you do not need to do any memory management.

The original value of pixel (x,y) is given in `in[x + nx*y]` and its new value will be stored in `out[x + nx*y]`.

### Correct output

In the output, pixel (x,y) will contain the median of all pixels with coordinates (i,j) where

• `0 <= i < nx`,
• `0 <= j < ny`,
• `x - hx <= i <= x + hx`,
• `y - hy <= j <= y + hy`.

This is the sliding window. Note that the window will contain at most `(2*hx+1) * (2*hy+1)` pixels, but near the boundaries there will be fewer pixels.

### Median

For our purposes, the median of the vector a = (a1, a2, …, an) is defined as follows:

• Let x1, x2, …, xn be the values of a sorted in a non-decreasing order.
• If n = 2k + 1, then the median of a is xk+1.
• If n = 2k, then the median of a is (xk + xk+1)/2.