Sunday, 20 December 2015

Long Exposure Shots with a GoPro and Matlab

I recently got  a GoPro. You know to get cool selfies, videos and all :D I am very much impressed by all the cool things you can do with it but was specifically impressed by the fact that one can create a time lapse video.

After giving a couple of tries to time lapse videos, I wanted to go beyond. I had always seen photographers make a long exposure shots by using specific DSLR cameras. I wanted to create just that using the only camera I had, a GoPro. However I had something much more than the camera, I knew how to write a code that deals with a number of images (I am a Computer Vision Engineer).

I brainstormed a plan which involved two main components:

1. Taking a set of time lapsed pictures of a scene with both moving and stationary objects.
2. Write a code that uses these pictures and gives a single long exposure shot.

I found a scene and took time lapsed pictures with a 3 second time interval for about 10 minutes. I had enough 'data' that I knew I could use and build my code on.  Here is what it looked like:

London Eye

AND YES! The London Eye DOES MOVE!!

Now the fun part - I wrote a simple script that loaded all the images and took a mean to create the final image - giving a nice long exposure.

Click to enlarge

Click to enlarge

And finally here is the Matlab Code:
% Script for creating long exposure using multiple images
close all
clear all
folder = sprintf(' ');
% count the number of png files
D = dir([folder, '\*.jpg']);
cumulativeImage = [];
numOfImages = size(D, 1);
% loading and accumulating
for i = 1:numOfImages
    inImage = imread(D(i).name);
    if( i == 1 )
        cumulativeImage = double(inImage);
        cumulativeImage = cumulativeImage + double(inImage);
longExposureImage = uint8(cumulativeImage./numOfImages);
imwrite(longExposureImage, 'longExposureImage.jpg');