Removing People from Vacation Snaps
2012-06-26 by , tagged as
Taking multiple images of the very same scene, captured using a tripod, we are going to remove moving objects by simply taking the median (i.e. the robust average) of all avaiable images.
Contents
Loading all images
We load all images into a large 4D matrix (height, width, channels, images). To speed up the process a little and to save memory, we scale down all images by some constant factor.
scale = 0.25; images = dir('*.JPG'); info = imfinfo(images(1).name); img = zeros(info.Height * scale, info.Width * scale, 3, numel(images), 'uint8'); for i = 1 : numel(images) img(:, :, :, i) = imresize(imread(images(i).name), scale); end collage = imresize([ ... img(:, :, :, 1), img(:, :, :, 2), img(:, :, :, 3); img(:, :, :, 4), img(:, :, :, 5), img(:, :, :, 6); img(:, :, :, 7), img(:, :, :, 8), img(:, :, :, 9); img(:, :, :, 10), img(:, :, :, 11), img(:, :, :, 12); img(:, :, :, 13), img(:, :, :, 14), img(:, :, :, 15); img(:, :, :, 16), img(:, :, :, 17), img(:, :, :, 18); img(:, :, :, 19), img(:, :, :, 20), img(:, :, :, 21); img(:, :, :, 22), img(:, :, :, 23), img(:, :, :, 24)], 1 / 5); imshow(collage, 'Border', 'tight'); imwrite(collage, 'collage.png');

Compute the median
Taking the median over all images will preserve static objects like background, buildings and monuments, but suppress deviations caused by moving objects such as people, birds etc.
med = median(img, 4); imshow(med, 'Border', 'tight'); imwrite(med, 'median.png');
