%EUSIPCO 2012
%Imperial College London 
%Andriy Gelman, Jon Onativia and Pier Luigi Dragotti 

function [uncovered, intra] = compute_uncovered_pixels(label, D, round_param, number_of_original_images, iteration)

[r,c, number_of_images] = size(label);

%transform buffers
label(label == -1) = max(max(max(label)));

number_of_layers = length(D);

%uncovered pixels appear in frame 2
uncovered = zeros(r, c, number_of_images/2);

if strcmp(round_param, 'ceil') == 1
    disparity = ceil(([0:1: number_of_original_images-1])'*D');
else
    disparity = round(([0:1: number_of_original_images-1])'*D');
end

%downsample disparity
for l = 1:iteration-1
   disparity = downsample(disparity,2); 
end

for i = 1:number_of_images/2
    %Apply prediction high-pass step   
    
    label_buffer = label(:,:,2*i-1:2*i);
    disparity_buffer = disparity(2*i-1:2*i,:);
    
    for l = 1:number_of_layers
        %Update uncovered areas       
        [connected_pixels, new_uncovered_pixels] = evaluate_uncovered_pixels(label_buffer, l, disparity_buffer(2,l) - disparity_buffer(1,l));   
        uncovered(:,:,i) = uncovered(:,:,i) + new_uncovered_pixels*l;    
        %apply prediction step to the connected pixels           
    end
end
low_label = label(:,:,1:2:end);
high_label = label(:,:,2:2:end); clear label;

intra = uncovered;
%[buffer, intra] = forward_prediction(zeros(r,c,number_of_images/2), low_label, zeros(r,c,number_of_images/2), high_label, uncovered, D, round_param);

end