In an image processing system, an algorithm processes an $N \times N$ image with each pixel being a number between $0$ and $255$. It finds the median value $M$ in the $N \times N$ image and applies the binary function $f(x)$ to every pixel.
$f(x) = \begin{cases} 1 & \text{if $x ≥ M$} \\ 0 & \text{if $x < M$} \end{cases}$
What is the time complexity of the algorithm? Is it $O(N^2)$ or $O(N^2\ log\ N)$? I think the answer is $O(N^2\ log\ N)$.