People see the opposite colors or a negative image because staring at one color for an extended period will fatigue the eyes rods & cones. There is some constancy with after images as people see images within the same general hue families.
A more in depth explanation offered by Peter Kaiser, MD while at York University, CA:
When you focus on a [strong stimulus], light sensitive photoreceptors (whose job it is to convert light into electrical activity) in your retina respond to the incoming light. Other neurons that receive input from these photoreceptors respond as well. As you continue to stare at the [strong stimulus] your photoreceptors become desensitized (or fatigued).
Your photopigment is "bleached" by this constant stimulation. The desensitization is strongest for cells viewing the brightest part of the figure, but weaker for cells viewing the darkest part of the figure. Then, when the screen becomes white, the least depleted cells respond more strongly than their neighbors, producing the brightest part of the afterimage.
Most afterimages last only a few seconds to a minute, since in the absence of strong stimulation, most nerve cells quickly readjust. Desensitization of the retina can be important for survival. A constant stimulus is usually ignored in favor of a changing one by the brain, because a changing stimulus is usually more important. But desensitization also leads to afterimages.
Afterimages are constantly with us. When we view a bright flash of light, briefly look at the sun, or are blinded by the headlights of an approaching car at night, we see both positive and negative afterimages. To prevent permanent damage to your eyes, NEVER look at any bright light source, in particular the sun.
The British psychologist Kenneth Craik burned a tiny hole in his right retina and permanently scarred his eye at that spot, when he stared directly into the sun for two minutes. DON'T TRY THIS AT HOME! For the first few days following his experiment--in which he wanted to find out whether such a lesion in the eye is visible--he saw a dim orange disk with closed eyes (positive afterimage) and a black afterimage with open eyes. Fortunately, after a year or so, Craik's vision at that location in his eye appeared to return to normal. His brain cleverly filled-in information at this damaged piece of retina.