If I stare at an object for a long time and close my eyes, at first I can still see the object with my eyes closed. But the image I see with my eyes closed is inverted: dark colors appear as light and light colors appear as dark. Why is that?
I think it is because of light adaptation. The rods that are perceiving strong light, downregulate their response. But when the light is suddenly withdrawn then the rods that are adapted to perceive bright light cannot immediately sense dim light.
There are two forms of adaptation- fast and slow. The fast one is Ca²⁺ dependent- decrease in Ca causes cGMP to increase which in turn depolarizes the cell. Calcium modulates this process by other means also. This article suggests that slow adpatation is because of an allosteric binding of cGMP on transducin-phosphodiesterase complex, which stabilizes this transition state and delays the signaling.
Adaptation can also happen because of photobleaching of rhodopsin.
I don't know how an image "remains" in the eye for a while. I believe it is because of asymmetric slow light adaptation between different spatially distributed rods(some rods take a while to readapt to dim conditions).
Similar effect you can feel with colour vision also. You keep staring at green for a while, then when you see something else it appears reddish.