i_k,\Delta j_k)$; typically $(0,0)$ is one of these pairs, and the others are centered around $(0,0)$, often in a symmetric way. For example, a $(2\ell+1)\times(2\ell+1)$ window is given by $S=\{-\ell,\ldots,+\ell\}\times\{-\ell,\ldots,+\ell\}$, or an approximately disc-shaped window of radius $r$ by $S=\{(\Delta i,\Delta j)~|~i,j\in\mathbb{Z},i^2+j^2\le r^2\}$.

For each pixel $(i,j)$, the sliding window is shifted to this pixel to select a set of pixels around $(i,j)$ and generate new (filtered) pixel values from the selected pixels. Using the notation $(i,j)+S:=\{(i+\Delta i,j+\Delta j)~|~(\Delta i,\Delta j)\in S\}$, the median filter assigns the median of all $u_{i',j'}$ for $(i',j')\in(i,j)+S$ to pixel $(i,j)$ in the median-filtered image $v$, $$\begin{aligned}
v_{i,j} &:= \operatorname{med}\{u_{i',j'}~|~(i',j')\in(i,j)+S\}
\;.\end{aligned}$$ For pixels near the boundary where $(i,j)+S$ contains locations outside the image domain $\{1,\ldots,N_x\}\times\{1,\ldots,N_y\}$, a suitable boundary treatment needs to be defined, which we do not discuss further here.

It is important to notice that the filter consists of two steps: the *selection step* that extracts values from the input image using the sliding window, and the *aggregation step* that uses the median to generate the new value from the extracted values. This is the universal structure of local image filters; the specification of selection and aggregation step defines the particular filter.

The entire 