% 2015/04/18
% author: igor brkic <i@hyperglitch.com>
% released to public domain

% script will take the brightest pixel from all images
pkg load image;
lst = dir('image*.jpeg');

frame_skip = 4;

out = uint8(imread(lst(1).name));
out_gr = rgb2gray(out);

out_r = out(:,:,1);
out_g = out(:,:,2);
out_b = out(:,:,3);

for i=2:frame_skip:length(lst)
    im = uint8(imread(lst(i).name));
    im_r = im(:,:,1);
    im_g = im(:,:,2);
    im_b = im(:,:,3);

    im_gr = rgb2gray(im);
    idx = im_gr>out_gr;

    out_r(idx)=im_r(idx);
    out_g(idx)=im_g(idx);
    out_b(idx)=im_b(idx);

    out(:,:,1) = out_r;
    out(:,:,2) = out_g;
    out(:,:,3) = out_b;
    out_gr = rgb2gray(out);
end

imwrite(out, 'out.jpg');

