www.pudn.com > DIBR.zip > cd2lr.m, change:2010-07-06,size:5964b


function [L R] = cd2lr(color, depth, rows, cols, numf) 
% This program performs the popular Depth Image Based Rendering to generate 
% Stereoscopic views for 3D Video Displays 
% 
% This program accepts the color video and the depth video in the YUV 4:2:0 
% format and convert it to the stereoscopic views, known as Left and Right 
% Videos. The output Left and Right will be in the same YUV format. rows is 
% the height of the video and cols is the width of the video, while numf is 
% the number of frames that you need to convert 
% 
% This program requires the yuv toolbox which can be downloaded from 
% http://sprljan.com/nikola/matlab/yuv.html for free. YUV Toolbox is a 
% provided by Nikola Sprljan.  
% 
% This program implements the rendering framework that is used in the paper 
% 
%       " D. De Silva, W. Fernando, and H. Kodikaraarachchi,  
%	  A NEW MODE SELECTION TECHNIQUE FOR CODING DEPTH MAPS OF 3D VIDEO,  
%	   IEEE International Conference on Acoustics, Speech and Signal  
%	   Processing, ICASSP 2010. pp. 686-689.  Mar. 2010." 
% 
%       which has the following features: 
%    
%       1. Depth maps are interpreted according to the MPEG Informative 
%          Recommendations in MPEG Doc. N8038. 
%       2. Left image is rendered from Right most pixel to the Left most  
%          pixel and Right Image is rendered vice versa. This is done to 
%          make sure that no background pixels would appear as foreground. 
%       3. Disocclusions are filled with Background pixel extrapolation, 
%          however with some small modifications. Disocclusions 
%          are filled in the opposite direction to rendering.  
% 
% Varuna De Silva, I-Lab, University of Surrey, Guildford, GU2 7XH, UK. 
% Version 1.0: May 2010.  
% Please send your comments and additional requirements to the author at 
% varunax@gmail.com 
% 
 
[Y U V] = yuv_import(color,[cols rows],numf); 
[Y2 U2 V2] = yuv_import(depth,[cols rows],numf); 
 
for nf = 1:size(Y,2) 
    L{nf}.luma = zeros(rows,cols); 
    L{nf}.chroma1 = zeros(rows/2, cols/2); 
    L{nf}.chroma2 = zeros(rows/2, cols/2); 
 
    R{nf}.luma = zeros(rows,cols); 
    R{nf}.chroma1 = zeros(rows/2, cols/2); 
    R{nf}.chroma2 = zeros(rows/2, cols/2); 
end 
 
mask.luma = zeros(rows,cols); 
mask.chroma1 = zeros(rows/2, cols/2); 
 
% This value is the half of the maximum shift 
% Maximum shift comes at depth = 0; 
S = 58; 
 
N = 256; %Number of depth planes 
depth = 0; 
shiftx = zeros(1,N); 
 
% Calculate the shift table to lookup 
for i = 1:N 
    shiftx(1,i) = find_shiftMC3(i-1, cols); 
end 
        
     
for nf=1:size(Y,2) 
     
D = Y2{nf}; 
     
    % Left Image 
     
    % Luma Components 
    for i = 1:rows 
        %Note the order of rendering 
        for j = cols:-1:1 
            shift = shiftx(1,(D(i,j)+1)); 
 
            if(j-shift+S<cols) 
                L{nf}.luma(i,j+S-shift)= Y{nf}(i,j); 
                mask.luma(i,j+S-shift) = 1; 
            end 
        end 
         
        % Filling of disocclusions with Background Pixel Extrapolation 
        for j = 1:cols 
            if(mask.luma(i,j)==0) 
                if(j-7<1) 
                    L{nf}.luma(i,j) = Y{nf}(i,j); 
                else 
                    L{nf}.luma(i,j) = sum(L{nf}.luma(i,j-7:j-4))/4; 
                end 
            end 
        end 
    end 
     
    % Chroma Components 
    for i = 1:rows/2 
        for j = cols/2:-1:1 
            shift = shiftx(1,(D(i*2,j*2)+1)); %P.S. It is not cols/2 here 
 
            if(j-ceil(shift/2)+S/2<cols/2) 
                L{nf}.chroma1(i,j-ceil(shift/2)+S/2)= U{nf}(i,j); 
                L{nf}.chroma2(i,j-ceil(shift/2)+S/2)= V{nf}(i,j); 
                mask.chroma1(i,j-ceil(shift/2)+S/2) = 1; 
            end 
        end 
         
        % Filling of disocclusions with Background Pixel Extrapolation 
        for j = 1:cols/2 
            if(mask.chroma1(i,j)==0) 
                if(j-2<1) 
                    L{nf}.chroma1(i,j) = U{nf}(i,j); 
                    L{nf}.chroma2(i,j) = V{nf}(i,j); 
                else 
                    L{nf}.chroma1(i,j) = sum(L{nf}.chroma1(i,j-2:j-1))/2; 
                    L{nf}.chroma2(i,j) = sum(L{nf}.chroma2(i,j-2:j-1))/2; 
                end 
            end 
        end 
    end 
     
    mask.luma = zeros(rows,cols); 
    mask.chroma1 = zeros(rows/2, cols/2); 
     
    % Right Image 
    for i = 1:rows 
        for j = 1:cols 
            shift = shiftx(1,(D(i,j)+1)); 
             
            if(j+shift-S>1) 
                R{nf}.luma(i,j+shift-S)= Y{nf}(i,j); 
                mask.luma(i,j+shift-S) = 1; 
            end 
        end 
         
        % Filling of disocclusions with Background Pixel Extrapolation 
        for j=cols:-1:1 
            if(mask.luma(i,j) == 0) 
                if(j+7>cols) 
                    R{nf}.luma(i,j) = Y{nf}(i,j); 
                else 
                    R{nf}.luma(i,j) = sum(R{nf}.luma(i,j+4:j+7))/4; 
                end 
            end 
        end 
    end 
     
    for i = 1:rows/2 
        for j = 1:cols/2 
            shift = shiftx(1,(D(i*2,j*2)+1)); 
             
            if(j+ceil(shift/2)-S/2>1) 
                R{nf}.chroma1(i,j+ceil(shift/2)-S/2)= U{nf}(i,j); 
                R{nf}.chroma2(i,j+ceil(shift/2)-S/2)= V{nf}(i,j); 
                 
                mask.chroma1(i,j+ceil(shift/2)-S/2) = 1; 
            end 
        end 
         
        % Filling of disocclusions with Background Pixel Extrapolation 
        for j=cols/2:-1:1 
            if(mask.chroma1(i,j) == 0) 
                if(j+2>cols/2) 
                    R{nf}.chroma1(i,j) = U{nf}(i,j); 
                    R{nf}.chroma2(i,j) = V{nf}(i,j); 
                else 
                    R{nf}.chroma1(i,j) = sum(R{nf}.chroma1(i,j+1:j+2))/2; 
                    R{nf}.chroma2(i,j) = sum(R{nf}.chroma2(i,j+1:j+2))/2; 
                end 
            end 
        end 
    end 
     
     
end