Why do I see a light flash when startled in my sleep?

Sometimes when I’m almost asleep and wake up by a sudden loud noise I see a light flash. The more startling sound whiter and brighter the light is. Sometimes I see different colors with different noises and it only happens when I’m trying to fall asleep.

Cecil speaks on a related issue; Why do I see sparks when I cough with my eyes closed?

My guess is the same principle is involved; you are startled, that produces a surge in blood pressure, that stimulates photoreceptor cells in the eyes.