It is not difficult to show that if $A \in M_n(k)$ for some field $k$, and $A^2=A$ then
$$\operatorname{tr}(A) = \dim(\operatorname{Im}(A))$$
In this comment, Terry Tao wrote:
This property, together with linearity, determines the trace uniquely, and so one can view the trace as the linearised version of the dimension-counting operator.
What does it mean precisely? If $f : M_n(k) \to k$ is $k$-linear (say with $k = \Bbb C$), and $f(A) = \dim(\operatorname{Im}(A))$ for any $A^2= A \in M_n(k)$, then we have that $f$ is the trace function?
Yes. More specifically, over any field $k$, regardless of its characteristic or algebraic closedness (or the lack of it), if $f : M_n(k) \to k$ is $k$-linear and $f(A)=\operatorname{rank}(A)$ (modulo $\operatorname{char}(k)$ if $k$ has finite characteristic) for every projection matrix $A$, then $f$ is necessarily the trace function.
Denote by $E_{ij}$ the matrix whose only nonzero entry is a $1$ at the $(i,j)$-th position. The assumption on $f$ implies that $f(E_{ii})=1$ for each $i$. Since $$ E_{12}=\left(\pmatrix{0&1\\ 0&1}\oplus I_{n-2}\right) - \operatorname{diag}(0,1,\ldots,1) $$ is a difference of two projections of equal ranks, we also have $f(E_{12})=0$ and similarly $f(E_{ij})=0$ whenever $i\ne j$. The linearity of $f$ thus implies that $f$ is the trace function.