# Processing a circular rainbow in an image

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:

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.

• Just to be nitpicking ;-), I believe that's a "glory". Dec 15 '14 at 18:12
• FYI: why you didn't see "violet" as it is meant today: youtube.com/watch?v=9udYi7exojk 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? Dec 15 '14 at 18:22
• This is a slightly different phenomenon from a rainbow. It is called a "Brocken Spectre". 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. Dec 16 '14 at 2:41

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["http://i.stack.imgur.com/ogkEu.jpg"];
img2=Import["http://i.stack.imgur.com/vEkvx.jpg"];


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

HistogramTransform[img, img2]


• I wonder why there is so much white in there 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. 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"] 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"]] 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?
– user484
Dec 15 '14 at 21:45

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]


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"]


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

img = Import["http://i.stack.imgur.com/ogkEu.jpg"];

hsb = ColorConvert[img, "HSB"];

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


• @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. Dec 16 '14 at 19:13