Wednesday, 24 April 2013

Thunderstorm - Video

The previous post shows you pictures of a thunderstorm, and how to create a composite from the images. This one shows you how to make a video from the images.

Two week-ends ago, a fairly strong thunderstorm struck, with clear views from my window. I mounted my camera on a tripod, and I took close to 1000 shots in about 45 minutes, each with 2 seconds exposure.

The previous post shows you some sample pictures, as well as a composite of many lightnings.

Composite shot, see previous article.
This post will show you how to make a video from these images. Just playing those images at normal video speed (25 frames per second) will not work: because of the 2 seconds exposure I use, lightnings only appear on 1 images, at most 2. Played at 25 fps, each lightning would only appear for 1/25s: barely noticeable.

The idea is therefore to create some burn-in effect, where the bright lightning stay for a number of frames, slowing fading away. The resulting video is below (go to Vimeo for higher resolution):



The first step to create a video is to resize the images to HD format, that is 1080p (1920x1080):
mkdir sm1080
ls *.JPG | xargs -I{} convert -crop 4380x2464+143+67 -resize 1920x1080 -quality 95 {} sm1080/{}
I also do a bit of cropping, as my original framing shows some of the wall next to the window.

We then add the required "burn-in" effect, so that bright light will appear quickly, and slowly fade away. I tried several methods to create this effect, but this very simple method seems to work best:
  1. Get the maximum between the last output frame and the current frame.
  2. Blend this maximum image with the current frame (93% maximum, 7% current): this is your next output frame.
  3. Iterate on the next input frame.
The idea is that a bright lightning will appear immediately, through the maximum operator: if the frame is bright, at step 2, the current frame is the same as the maximum frame, therefore you get 100% of the current frame. For following images, the current frame is less bright, so the brightness decays at a 93% rate. That is, the lightning will disappear almost completely within 29 frames (slightly more than a second). See Wikipedia on exponential decay for more details.

I tried different parameters, 90% made lightnings appear for a too short duration, and 95% led to significant artifacts: 93% seems to be a sweet spot.

This simple Ruby script, that calls ImageMagick, does the job for you:

list ="."){|x| x.match(/.*\.JPG/)}.sort

system("mkdir output")
system("rm output/*")
system("cp #{list[0]} output/#{list[0]}")
list.each_cons(2){|k1, k2|
system("convert output/#{k1} #{k2} -evaluate-sequence max output/max-#{k2}.tiff")
system("composite output/max-#{k2}.tiff #{k2} -blend 93% output/#{k2}")
I output the maximum images as TIFF, as to avoid additional JPEG compression artifacts.

It is easy to check out the resulting video with mplayer:
mplayer mf://sm1080/output/*.JPG -mf fps=25:type=jpg
Once you are happy with the results, you can then encode the output (I chose highest quality x264 encoding):
mencoder mf://sm1080/output/*.JPG -mf fps=25:type=jpg -ovc x264 -x264encopts preset=veryslow:tune=film:crf=15:frameref=15:fast_pskip=0:threads=auto -o video.avi
The video can be seen in 720p on Vimeo, and in 1080p on Youtube (unfortunately, Youtube does not let me choose a good thumbnail image, so I switched to Vimeo for this reason).

Sunday, 21 April 2013

Thunderstorm - Composite shot

One of the nice (and sometimes a little scary) things about living under the tropics is those very intense thunderstorms, especially at night.

Composite of an evening thunderstorm.
Last weekend a big one struck, so I mounted my camera (Panasonic DMC-GX1) on the window ledge, using my Gorillapod, and set the kit lens 14-42mm at its widest angle. Luckily, the rain was quite localized, so it wasn't raining much outside my window: no worries about getting my camera wet!

I use the camera in burst mode, more precisely the "H" mode, that allows maximum speed while keeping the maximum resolution. I keep the trigger pressed using my home-made remote trigger. All these shots are taken at f/5.0, with 2 seconds exposure, at ISO 160, slightly underexposed when there is no lightning, but sometimes overexposed for the brightest ones. Only mistake: I should have fixed the white balance, some of the shots clearly use different balances.

The interval between shots is short, around 400ms, meaning that we expose almost all the time, and therefore are able to capture most lightnings. Actually, some lightnings last for a fairly long time, and can be seen over 2 consecutive shots.

In total, I have close to 1000 shots, acquired over 45 minutes. Here are some of the best ones:

2 lightnings next to each other
Intra-cloud lightnings, those are attenuated, probably because the light has to go though clouds and rain.
A bit overexposed, but notice how the sky becomes blue, at night.

The 13 nicest images of the series can be seen in this Picasa album:

I am going to do 2 things with those images: a composite image of all the lightnings, and a video, that I will show in the next post.


I tried a few different ways to get a nice composite, here is what I think works best:
  1. Select the nicest images, that have a clear lightning in it.
  2. For each of these, take a difference image to the previous one in the series. That is, we want to remove all the background light (man-made light and other background lighting), and only take out the extra light created by the lightning. An image explains it best:
    From top to bottom: 1. Number 226 in sequence, no lightning; 2. Number 227 in sequence, strong lightning; 3. Difference between 227 and 226: all man-made lights have disappeared.
    Obtaining these difference images is straightforward with ImageMagick:
    convert ../P1180226.JPG P1180227.JPG -evaluate-sequence subtract diff/P1180227.JPG
  3. The composition itself is done is Gimp: First, open one of the original images in Gimp, that does not contain a lightning. Then, drag and drop all the differences images in the Layers window.
  4. Hide all these new layers (i.e. until you are back to the original image).
  5. Move one of the difference layer above your original image (start with the brightest lightnings), and show it.
  6. Choose Screen as layer mode. Lighten may also work, but produces results that are not as nice in my opinion.
  7. Go to Colors, then Levels, and increase the input black level until you only see mostly the lightning, without too much increase in the background light in the sky. You can also change the input white level if you want the lightning to appear brighter.
  8. Repeat from step 5.
This shows you the progression of the composition, starting from the original image, step 0:
Montage of the progression of the composite image. One image is added at each step (2 images from 3 to 5).
For step 1, the black level is not increased significantly, so as to get the blue sky on the right.
The image at step 12 is the one shown at the beginning of this post, after slight color adjustments.

If you like my posts, you can now follow me on Google Plus, Twitter, or via RSS, thanks!

Tuesday, 9 April 2013

Macro video - Correcting chromatic aberration, white balance, and soundtrack

This post is about taking macro videos, that is, videos of small objects, at relatively high magnification. In other posts, you can find a general introduction on taking macro pictures using a close-up filter, and how to correct chromatic aberration.
The previous post shows how to force the lens aperture on the DMC-GX1, this post gives technical details to correct chromatic aberration, white balance, and improve the soundtrack.

As mentioned in the previous post, the Panasonic DMC-GX1 is severely limited when it comes to video mode: it does not allow manual setting of the aperture and white balance.

Once we managed to trick the lens to force a slow aperture, we get this this not-so-nice video, with chromatic aberration (red/blue fringes in the corner of the images), incorrect white balance (the music box looks too white), and noisy soundtrack:

With a few operations, we'll show how to turn it into this nicer looking one:

Thursday, 4 April 2013

Macro video

This post is about taking macro videos, that is, videos of small objects, at relatively high magnification. In other posts, you can find a general introduction on taking macro pictures using a close-up filter, and how to correct chromatic aberration.

This post will show you how to take videos of small objects. I used my Reuge music box as an example, since it is small, and it moves (playing some nice music in the process, of course)... The final result is shown here:

My camera, the Panasonic DMC-GX1, is in the medium range of what Panasonic offers, which, unfortunately, means that there is no manual control of aperture or white balance in video mode. There is no technical reasons for that, only commercial ones, and, well, that's a shame: there is enough feature differentiation between the DMC-GH2/GH3 and the GX1 without adding artificial limitations.