虚拟视点绘制|DIBR实现|3D变换

8 篇文章 0 订阅
2 篇文章 0 订阅

数据集
https://www.microsoft.com/en-us/download/details.aspx?id=52358
示例
原图
请添加图片描述
深度图
请添加图片描述
DIIBR图像
请添加图片描述
代码实现:

clc;
% close all;
time1=clock;
addpath(genpath('D:\chengxu_matlab_project'));%调用不同文件夹里的子函数

%%  42  130  44  120
%读取CFG路径
CFG='D:\vitual_viewpoint\CFG\3d-ballet.cfg';
% CFG='D:\vitual_viewpoint\Vitual\3d-dancer - 副本.cfg';
[Width,Height,Frames,D_min,D_max,C_ParameterFile,pbnum_L,pbnum_V,pbnum_R,L_route,R_route,L_depth_route,R_depth_route,Output_Virtual]=extract_cfg(CFG);
col=Width;%1024
row=Height;%768

%读取相机参数 获取矩阵
[LMat_In_ref,LMat_Spin,LMat_Pan,LMat_Ex_ref,RMat_In_ref,RMat_Spin,RMat_Pan,RMat_Ex_ref,VMat_In_ref,VMat_Spin,VMat_Pan,VMat_Ex_ref]=Read_matrix(C_ParameterFile,pbnum_L,pbnum_V,pbnum_R);

%基线距离
Tvl=sqrt((VMat_Ex_ref(1,4)-LMat_Ex_ref(1,4))^2+(VMat_Ex_ref(2,4)-LMat_Ex_ref(2,4))^2+(VMat_Ex_ref(2,4)-LMat_Ex_ref(2,4))^2);
Tvr=sqrt((VMat_Ex_ref(1,4)-RMat_Ex_ref(1,4))^2+(VMat_Ex_ref(2,4)-RMat_Ex_ref(2,4))^2+(VMat_Ex_ref(2,4)-RMat_Ex_ref(2,4))^2);

%%
%公式推导
%参考视点:
kr_Mat=LMat_In_ref*LMat_Spin;   %K*R

kt_MatKT=LMat_In_ref*LMat_Pan;  %K*T

KR_V=VMat_In_ref*VMat_Spin;
KT_V=VMat_In_ref*VMat_Pan;
%%
%虚拟视点博客处理参考视点矩阵
exMat_L=zeros(3,4);
m_RotMatrix=zeros(4,4);
inMat_L=zeros(3,3);
inMat_L=LMat_In_ref;

exMat_L=LMat_Spin;
for i=1:3
    exMat_L(i,4)=LMat_Pan(i,1);
end
for i=1:3
    for j=1:4
        m_RotMatrix(i,j)=0;
        for k=1:3
            m_RotMatrix(i,j)=m_RotMatrix(i,j)+inMat_L(i,k)*exMat_L(k,j);
        end
    end
end
m_RotMatrix(4,4)=1;

%处理虚拟视点矩阵
exMat_V=zeros(3,4);
m_RotMatrix_V=zeros(4,4);
inMat_V=zeros(3,3);
inMat_V=VMat_In_ref;

exMat_V=VMat_Spin;
for i=1:3
    exMat_V(i,4)=VMat_Pan(i,1);
end
for i=1:3
    for j=1:4
        m_RotMatrix_V(i,j)=0;
        for k=1:3
            m_RotMatrix_V(i,j)=m_RotMatrix_V(i,j)+inMat_V(i,k)*exMat_V(k,j);
        end
    end
end
m_RotMatrix_V(4,4)=1;

%%
%初始化
page=3;
disp(['当处理的yuv视频帧数为',num2str(Frames),'帧时:']);
output_image=zeros(row,col,page);%输出合成图像初始化
output_depth_L=zeros(row,col,page);%输出深度图像初始化

flag_depth_L=zeros(row,col);%左空洞图
flag_depth_R=zeros(row,col);%右空洞图
flag_image=zeros(row,col);

output_image_L=zeros(row,col,page);%初始化左合成图
output_image_R=zeros(row,col,page);%初始化右合成图
output_depth_R=zeros(row,col,page);%初始化深度图

L_path_list=dir(strcat(L_route,'*.bmp'));
L_dep_path_list=dir(strcat(L_depth_route,'*.png'));

R_path_list=dir(strcat(R_route,'*.jpg'));
R_dep_path_list=dir(strcat(R_depth_route,'*.png'));

for f=1:Frames

    img_F=L_path_list(f).name;
    img=imread(strcat(L_route,img_F));
    
    img_F=L_dep_path_list(f).name;
    img_dep=imread(strcat(L_depth_route,img_F));
    figure,imshow(img_dep);title('原深度图');

 [output_image,flag_depth]=Transf_dep(row,col,img_dep,D_min,D_max,m_RotMatrix,m_RotMatrix_V,img);
    figure,imshow(output_image);title('原深度图');

end

function [image,flag_depth]=Transf_dep(row,col,img_dep,Zmin,Zmax,m_RotMatrix,m_RotMatrix_V,img)
output_depth=zeros(row,col,1);
flag_depth=zeros(row,col);
img_1=img_dep(:,:,1);

image=zeros(row,col,3);

for i=1:row
    for j=1:col
        Z=1.0/((double(img_1(i,j))/255.0)*(1.0/Zmin-1.0/Zmax)+1.0/Zmax);
        [X,Y]=projUVZtoXY(row,col,m_RotMatrix,j,i,Z);%第一个 X=-25.1382  Y=16.7334
        [u,v,w]=projXYZtoUV(row,col,m_RotMatrix_V,X,Y,Z);%第一个 u=54.9588  v=19.9150
        u=u+0.5;
        v=v+0.5;
        u=fix(u);
        v=fix(v);
        w=img_1(i,j);
%         w = (255.0*(1 / w - 1.0/Zmax) / (1.0/Zmin-1.0/Zmax));
        if(u>0&&u<=col-1e-6&&v>0&&v<=row-1e-6 )
            output_depth(v,u,1)=w;
            image(v,u,1)=img(i,j,1);
            image(v,u,2)=img(i,j,2);
            image(v,u,3)=img(i,j,3);
        end
    end
end
% 滤波
%深度图的变换图
output_depth=uint8(output_depth);

figure,imshow(output_depth);impixelinfo;

% 1
hole=made_hole_gray(output_depth);

%有滤波的深度图1
% [output_depth,hole]=smooth_hole(output_depth,hole);
% figure,imshow(output_depth);impixelinfo;
% figure,imshow(flag_depth);impixelinfo;

% caise 3*3原来  深度图的滤波大小为3*3  图像不会模糊。1
image=uint8(image);

image(:,:,1)=medfilt2(image(:,:,1),[3,3]);
image(:,:,2)=medfilt2(image(:,:,2),[3,3]);
image(:,:,3)=medfilt2(image(:,:,3),[3,3]);

end


  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值