Let $L_n(m)$ be defined as in this answerthis answer. Then the function $f(n,m)$ questioned here (aware that it is different from $f$ in the linked answer) can be computed as
$$f(n,m) = \sum_{k=n}^{m} \binom{k}{n}\cdot L_k(m).$$
This formula easily follows from the observation that from a line with (exactly) $k$ grid points, we can form $\binom{k}{n}$ different subsets of $n$ collinear points.
Now, let us compute $f'(n,m)$. The number of sets of $n$ collinear points on horizontal lines is $m\cdot \binom{m}{n}$, and so is the number of those on vertical lines. The number of sets of $n$ collinear points on 45° lines equals $$\binom{m}{n} + 2\sum_{k=n}^{m-1} \binom{k}{n} = \binom{m}{n} + 2\binom{m}{n+1}.$$ Hence, $$f'(n,m) = f(n,m) - (2m+1)\cdot \binom{m}{n} - 2\binom{m}{n+1}.$$