9
$\begingroup$

As is well known (see https://www.youtube.com/watch?v=fVsONlc3OUY ), the Northern Lights or Auroral displays appear as variations of several colours (generally pale green and pink). Is there a possibility that a colour variation effect can be introduced onto an existing image of the Northern Lights using Mathematica. One possibility is to employ an animation where the pale green gradually changes to pink and vice versa. A naïve choice is as follows

   Manipulate[ImageEffect[image, {"Solarization", x}], {{x, 0.5}, 0, 1}]

where image is attached hereenter image description here

However the Solarization technique is not convincing. Would appreciate better techniques of showing a colour changing effect.

$\endgroup$
  • 1
    $\begingroup$ A job for ColorFunction -> "AuroraColors" perhaps? $\endgroup$ – dr.blochwave Oct 21 '15 at 11:52
10
$\begingroup$

First, we define a suitable color function that cycles from green to purple:

cf[h_] := If[h < .5, h + .4, (1 - h) + .4]
SetAttributes[cf, Listable]

And then we apply it to the hue channel of our image:

i = Import["http://i.stack.imgur.com/iMzXN.jpg"];
cSep = ColorSeparate[ColorConvert[i, "HSB"]];
ct = ParallelTable[
  ColorCombine[{Image[cf[Mod[ImageData[#[[1]]] + hueShift, 1]]], #[[
       2]], #[[3]]} &@cSep, "HSB"], {hueShift, 0, 1 - .05, .05}];

And by exporting it as an animated gif, with Export["aurora.gif", ct] we obtain:

http://i.imgur.com/dem9fog.gifv

Update

As per @Kuba's suggestion, you can achieve a ~100x speedup if you perform the color shifting using ImageApply:

ct = ParallelTable[
  ColorCombine[{ImageApply[
       cf[Mod[# + hueShift, 1]] &, #1], #2, #3} & @@ cSep, 
   "HSB"], {hueShift, 0, 1 - .05, .05}];
| improve this answer | |
$\endgroup$
  • 3
    $\begingroup$ Nice +1, ImageApply will be faster, you can even use it interactively: Manipulate[ ColorCombine[{ ImageApply[cf[Mod[# + hueShift, 1]] &, #1], #2, #3 } & @@ cSep, "HSB"] , {hueShift, 0, 1 - .05, .05} ] $\endgroup$ – Kuba Oct 21 '15 at 12:43
  • $\begingroup$ ImageApply does speed things up noticeably $\endgroup$ – thils Oct 21 '15 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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