function [L R] = cd2lr2(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
% 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------------------LEFT----%
% Left Image
mask.luma = zeros(rows,cols);
mask.chroma1 = zeros(rows/2, cols/2);
% 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
end
NHOOD = [1 1 1 0 0 0];
se = strel('arbitrary', NHOOD)
y = imdilate(mask.luma,se);
NHOOD2 = [0 0 0 1 1 1 1 1 1];
se2 = strel('arbitrary', NHOOD2);
x = imerode(y, se2);
z = x.*mask.luma;
mask.luma = z;
for i = 1:rows
% 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
for i = 3:rows-2
% Smooth the filled occlusions
for j = 3:cols-2
if(mask.luma(i,j)==0)
L{nf}.luma(i,j) = sum(sum(L{nf}.luma(i-2:i+2,j-2:j+2)))/25;
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
end
for i = 1:rows/2
% 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
%-------------------------------------RIGHT------------------RIGHT----%
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
end
NHOOD = [0 0 0 1 1 1];
se = strel('arbitrary', NHOOD)
y = imdilate(mask.luma,se);
NHOOD2 = [1 1 1 1 1 1 0 0 0];
se2 = strel('arbitrary', NHOOD2);
x = imerode(y, se2);
z = x.*mask.luma;
mask.luma = z;
for i = 1:rows
% 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 = 3:rows-2
% Smooth out the filled occlusions
for j=cols-2:-1:3
if(mask.luma(i,j) == 0)
R{nf}.luma(i,j) = sum(sum(R{nf}.luma(i-2:i+2,j-2:j+2)))/25;
end
end
end
% Chroma Components
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
end
for i = 1:rows/2
% 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
DIBR.zip_DIBR_DIBR matlab_vsrs_虚拟视点_虚拟视点绘制
版权申诉
51 浏览量
2022-07-15
04:52:46
上传
评论
收藏 3.69MB ZIP 举报
邓凌佳
- 粉丝: 65
- 资源: 1万+
最新资源
- Python 版冒泡排序算法源代码
- tensorflow-gpu-2.7.2-cp38-cp38-manylinux2010-x86-64.whl
- tensorflow-2.7.3-cp39-cp39-manylinux2010-x86-64.whl
- tensorflow-2.7.2-cp39-cp39-manylinux2010-x86-64.whl
- Python版本快速排序源代码
- Python 语言版的快速排序算法实现
- 450815388207377安卓_base.apk
- 超微主板 X9DRE-TF+ bios 支持 nvme启动
- 基于Python通过下载气象数据和插值拟合离散数据曲线实现对寒潮过程的能量分析
- 智能车仿真软件.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈