Programming Parallel Computers 2019

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

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.


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