How can one describe the closure of the image of a morphism of schemes? Let $(f,f^{\#}):(X,\mathcal{O}_{X})\to(Y,\mathcal{O}_{Y})$ be a morphism of schemes. Is it possible to describe $\overline{f(X)}$ concretely? Note that if $X$ and $Y$ are affine, then $\overline{f(X)}=V(\ker f^{\#}(Y))$. Also more generally, if $U\subseteq Y$ is affine open, then for the induced morphism $f_U:f^{-1}U\to U$ I am able to prove $\operatorname{cl}_U(\operatorname{im} f_U)=V(\ker f^{\#}(U))$, at least provided that $X$ is Noetherian. But then we only have $\operatorname{cl}_U(\operatorname{im} f_U)=U\cap\overline{U\cap\operatorname{im}f}$, and it would be more practical to have a description of $U\cap \overline{\operatorname{im}f}$ instead. Can something general, yet useful be said? Perhaps under some mild conditions? Thanks in advance!
 A: If $f$ is quasi-compact or $X$ is reduced, then the underlying set of the scheme-theoretic image is indeed the closure of the set-theoretic image. One cannot remove both of these assumptions.
Vakil's book does a good job with these items in section 8.3, and this post follows that exposition. Briefly, what you would want to do is given an affine open subset $\operatorname{Spec} A\subset Y$, cover $f^{-1}(\operatorname{Spec} A)$ with affine opens $\operatorname{Spec} B_i\subset X$ and declare the scheme-theoretic image to be the subscheme cut out by the kernel of $A\to\prod B_i$. In order to glue these together correctly, you need to show that $\ker(A\to \prod B_i)_g = \ker(A_g\to \prod (B_i)_g)$ for any $g\in A$.
In order for this to be true, given an $a/g^n\in \ker(A_g\to \prod (B_i)_g)$, one needs to find an $m>0$ so that $g^ma\in B_i$ is zero for all $i$. If there are finitely many $B_i$ (the case when $f$ is quasi-compact), you're good - just take the maximum. Alternatively, in the case that $X$ is reduced, $m=1$ works: if $g^na=0$ in $B$, then $ga$ is a nilpotent, so $ga=0$.
To see that there are examples of bad behavior when $X$ is nonreduced and $f$ is not quasi-compact, see a recent example here, copied for posterity:

Let $X=\coprod_{n\geq 0} \operatorname{Spec} k[x]/(x^n)$, let $Y=\operatorname{Spec} k[x]$, and define $f:X\to Y$ by the obvious map $\operatorname{Spec} k[x]/(x^n) \to \operatorname{Spec} k[x]$ on each component. Then the set-theoretic image of $f$ is just $(x)$, but the scheme-theoretic image is all of $Y$: the statement about factorization means we're looking to find the kernel $I$ of the map $k[x]\to \prod_{n\geq 0} k[x]/(x^n)$, and then the closed subscheme which is the scheme-theoretic image is $\operatorname{Spec} k[x]/I$. It is straightforward to see that $I$ must be zero: if a polynomial in $x$ is zero modulo every $x^n$, it must be zero.

