5. Given the function $f(x)=x^{2}-x+\sqrt{2 x^{4}-6 x^{2}+8 x+16}$, then the minimum value of $f(x)$ is
A. 4
B. $\frac{7}{2}$
C. 3
D. $\frac{5}{2}$
Consider the function
$$
\begin{array}{l}
g(x)=x^{2}-x+1+\sqrt{2 x^{4}-6 x^{2}+8 x+16} \\
=\sqrt{2}\left[\frac{x^{2}-x+1}{\sqrt{2}}+\sqrt{\left(x^{2}-2\right)^{2}+(x+2)^{2}}\right] .
\end{array}
$$

This represents the sum of the distances from the point \( P\left(x^{2}, x\right) \) to the line \( x-y+1=0 \) and the point \( A(2,-2) \), multiplied by \( \sqrt{2} \).
Construct the parabola \( y^{2}=x \), and draw a line \( AB \) from point \( A \) perpendicular to the line \( x-y+1=0 \), intersecting the parabola at points \( C \) and \( O \). It is easy to see that \( C(1,-1) \). Therefore, when point \( P \) coincides with point \( C \) or \( O \), \( g(x) \) achieves its minimum value \( \sqrt{2}|AB|=5 \). Thus, the minimum value of \( f(x)=g(x)-1 \) is 4, so the answer is \( A \).