Motivated by the situation of bounded Fredholm operators, I have the following question about "unbounded Fredholm operators".

Let $\mathcal{H}_1$ and $\mathcal{H}_2$ be two Hilbert spaces, and $$ D: \mathrm{dom}(D) \subset \mathcal{H}_1 \to \mathcal{H}_2 $$ be a densely defined a unbounded operator. If we assume that the image is closed, and that $\mathrm{ker}(D)$ and $\mathrm{cokernel}(D)$ are both finite dimensional, is true that $$ \mathrm{cokernel}(D) = \mathrm{ker}(D^*), $$ where $D$ is the adjoint of $D$? Can you relax the assumptions on closure of the image, and/or dimensionality and still produce the smae result?