function [ levels, sizes ] = buildPyramid( image )
kernel = [1 4 6 4 1]' * [1 4 6 4 1];
kernel = kernel/ sum(sum(kernel));
currentG = image;
nextG = imresize(imfilter(currentG, kernel, 'replicate'),0.5,'nearest');
currentL = currentG - imresize(nextG, size(currentG),'method','nearest');
currentG = nextG;
levels = currentL;
sizes(:,1) = size(image);
sizes(:,2) = size(nextG);
levelindex = 2;
while 1
if (levelindex >= 8 || (max(size(currentG)) <= 1))
currentG = zeros(size(nextG,1),size(image,2));
currentG(1:size(nextG,1),1:size(nextG,2)) = nextG;
levels = [levels; currentG];
break;
end
nextG = imresize(imfilter(currentG, kernel, 'replicate'),0.5,'nearest');
currentL = zeros(size(nextG,1),size(image,2));
currentL(1:size(currentG,1),1:size(currentG,2)) = currentG - imresize(nextG, size(currentG),'nearest');
sizes(:,levelindex+1) = size(nextG);
levels = [levels; currentL];
levelindex = levelindex + 1;
currentG = nextG;
end
end