function [rec,obj1,obj2]=extrapolation(Im , extrap , direction, patchSize)

close all;
% Read image
trueIm = double(Im);
sizeIm = size(Im);

% Create mask for extrapolation
thick = extrap;
Mask = ones(sizeIm);

%% Choosing direction to extrapolation  

switch direction
    case 1 
        for i=1:thick
            Mask(:,sizeIm(2)-i)=0;
        end
    case 2 
        for i=1:thick
             Mask(sizeIm(1)-i,:)=0;
        end
    case 3 
        for i=1:thick
             Mask(:,+i)=0;
        end
    case 4 
        for i=1:thick
             Mask(i,:)=0;
        end
end

Mask = logical(Mask);
maskedIm = trueIm .* Mask;

%% Extrapolation of image

[ResIm , ResIm_OMPonly] = extrapolate(trueIm, maskedIm , Mask, extrap, direction, patchSize);
rec=ResIm;

%% Show results
% figure; imshow(trueIm , [0 255]); title('True Im');

% figure; imshow(maskedIm , [0 255]); 
% P = Compute_Error_Stats(maskedIm , trueIm); 
% title(sprintf('Masked & noisy Im , %02.2f dB' , P));

figure; imshow(ResIm , [0 255]); 
P = Compute_Error_Stats(ResIm , trueIm); 
% title(sprintf('Result, replacing only missing pixels , %02.2f dB' , P));

obj1=P;
obj2=ssim_index(ResIm , trueIm);

% Finished
return;
