Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

While on a cross-country flight, I observed what looked like a complete circular rainbow, visible against the backdrop of clouds. I took several photos thru the window with my small Nikon camera, one of which is shown below:

enter image description here

We were at about 35,000 feet with a complete cloud deck below us. I looked down and saw this rainbow-like structure above the clouds. It remained in view for about 10 minutes, and it went away when the cloud deck began to rise with respect to our flight path.

While in flight my eyes had no trouble discerning the shape and colors Red, Orange, Yellow, Green, and Blue, but no Indigo or Violet. However, when I uploaded the photos to my desktop I could barely make out these colors.

I've been trying to use Mathematica to bring out the rainbow in the images, but without much success. I'm asking for ideas on how to enhance the colors and structure of the rainbow. As you will note in the photo, there appears to be further structure outside the main rainbow, so it would be interesting to manipulate multiple parameters in the photo.

share|improve this question
Just to be nitpicking ;-), I believe that's a "glory". – Peltio Dec 15 '14 at 18:12
FYI: why you didn't see "violet" as it is meant today: – Mr.Wizard Dec 15 '14 at 18:15
I wonder why your camera failed to capture any significant color, at least as presented in this image. I don't suppose there is a "RAW" (digital negative) file? Out of curiosity was a polarizing filter of any kind in use? – Mr.Wizard Dec 15 '14 at 18:22
This is a slightly different phenomenon from a rainbow. It is called a "Brocken Spectre". – Octopus Dec 15 '14 at 20:46
This is not a rainbow--due to refraction (bending) of light and dispersion (different bending for different wavelengths)--but instead a halo, due to diffraction of light off of very small water particles. The colors are always less saturated (less intense) than in a rainbow, and the angular size and colors depend upon the size of the particles. A rainbow always subtends an angle of 42 degrees from the anti-solar point (the point opposite the sun), whereas halos are almost always of smaller angular size and (as mentioned) the size depends upon the droplet size. – David G. Stork Dec 16 '14 at 2:41

Plain old ImageAdjust will improve it quite a lot, though you have to chop off the bright orange text to stop the algorithm being fooled:

ImageAdjust[img ~ImageTake~ 2100]

enter image description here

You could now bring out the colours a bit more with a boost to the contrast of the saturation channel:

 ColorCombine[MapAt[ImageAdjust[#, {0, 2, 1}] &, ColorSeparate[%, "HSB"], 2], "HSB"]

enter image description here

share|improve this answer

Another approach is to try and histogram equalize the image to something similar, but with more pronounced colors. I found this picture at google images

img = Import[""];

enter image description here

Then the desired picture can take on (something of) the coloration of the new image using

HistogramTransform[img, img2]

enter image description here

share|improve this answer
I wonder why there is so much white in there – Dr. belisarius Dec 15 '14 at 19:01
@belisarius -- it's hard to know for sure, but I would guess it is a result of the transformation working on a channel-by-channel basis. – bill s Dec 15 '14 at 19:09
curious,isn't it? {h, s, b} = ColorSeparate[img, "HSB"]; {h2, s2, b2} = ColorSeparate[img2, "HSB"]; ColorCombine[{HistogramTransform[h, h2], HistogramTransform@s, HistogramTransform@b}, "HSB"] – Dr. belisarius Dec 15 '14 at 19:23
@belisarius -- The weird colors actually make some sense: the hue channel is getting all scrambled around by the equalization, essentially returning random colors. For comparison, try HistogramTransform[ColorConvert[img, "LAB"], ColorConvert[img2, "LAB"]] – bill s Dec 15 '14 at 19:37
Is this answer really enhancing the colours and structure that exist in the original image, or is it simply imposing the colours and structure of a different image on it? – Rahul Dec 15 '14 at 21:45

There appears to be insufficient data in the provided image. Boosting saturation by a factor of ten:

img = Import[""];

hsb = ColorConvert[img, "HSB"];

ImageApply[# {1, 10, 1} &, hsb]

enter image description here

share|improve this answer
@MichaelE2 Oops! I used a drag-and-drop in the code I actually ran and that produced an alpha channel, then I just added the Import when I pasted it here. It was hubris to think I knew how the code would evaluate. – Mr.Wizard Dec 16 '14 at 19:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.