ZY520XUE 于 2017.09.01 10:27 提问

%% 清理工作空间
clc;
close all;
clear;

%% 系统标定
L = 200; %摄像机光心到参考平面距离（标定获得）
D = 60; %投影仪光心到摄像机光心连线距离（标定获得）
f = 1/32; %投影的光栅频率
W_Scale = 12;
H_Scale = 12;

%% 读四副图片（调制图案）
I1=double(rgb2gray(image1))/255; %将0-255转化为0-1
I2=double(rgb2gray(image2))/255;

I3=double(rgb2gray(image3))/255;

I4=double(rgb2gray(image4))/255; %转成灰度图像

%% 读参考图像
I5=double(rgb2gray(image5))/255; %将0-255转化为0-1
I6=double(rgb2gray(image6))/255;

I7=double(rgb2gray(image7))/255;

I8=double(rgb2gray(image8))/255; %转成灰度图像

%% 调制后的图像相位计算
for i=1:512
for j=1:512
if (I1(i,j)==I3(i,j))
if(I2(i,j)>I4(i,j))
I(i,j)=pi/2;
elseif(I2(i,j)<I4(i,j))
I(i,j)=3*pi/2;
else
I(i,j)=0;
end

``````    elseif (I1(i,j)>I3(i,j))
if I2(i,j)>=I4(i,j)
I(i,j)=atan((I2(i,j)-I4(i,j))/(I1(i,j)-I3(i,j)));
else
I(i,j)=2*pi-atan((I4(i,j)-I2(i,j))/(I1(i,j)-I3(i,j)));
end

else
if I2(i,j)>=I4(i,j)
I(i,j)=pi-atan((I2(i,j)-I4(i,j))/(I3(i,j)-I1(i,j)));
else
I(i,j)=pi+atan((I4(i,j)-I2(i,j))/(I3(i,j)-I1(i,j)));
end
end
end
``````

end

%% 参考图像相位计算
for i=1:512
for j=1:512
if (I5(i,j)==I7(i,j))
if(I6(i,j)>I8(i,j))
phase(i,j)=pi/2;
elseif(I6(i,j) phase(i,j)=3*pi/2;
else
phase(i,j)=0;
end
elseif (I5(i,j)>I7(i,j))
if I6(i,j)>=I8(i,j)
phase(i,j)=atan((I6(i,j)-I8(i,j))/(I5(i,j)-I7(i,j)));
else
phase(i,j)=2*pi-atan((I8(i,j)-I6(i,j))/(I5(i,j)-I7(i,j)));
end
else
if I6(i,j)>=I8(i,j)
phase(i,j)=pi-atan((I6(i,j)-I8(i,j))/(I7(i,j)-I5(i,j)));
else
phase(i,j)=pi+atan((I8(i,j)-I6(i,j))/(I5(i,j)-I7(i,j)));
end
end
end
end