生成多频外差的光栅图像【Matlab】

背景介绍

在matlab中生成多频外差的光栅图像,其中3种频率的选择参考如下文献:
Liu S , Feng W , Zhang Q , et al. Three-dimensional shape measurement of small object based on tri-frequency heterodyne method[C]// 2015 International Conference on Optical Instruments and Technology: Optoelectronic Measurement Technology and Systems. International Society for Optics and Photonics, 2015.
λ 1 = 1 s − s , λ 2 = 1 s , λ 3 = 1 s + ( s + 1 ) \lambda_1 = \frac{1}{s-\sqrt{s}},\lambda_2=\frac{1}{s},\lambda_3=\frac{1}{s+(\sqrt{s}+1)} λ1=ss 1,λ2=s1,λ3=s+(s +1)1

代码段

% 生成三频四步条纹光栅图案,创建一个generatePic的文件夹存放生成图像
clc,clear;
width = 1280;
height = 720;

% 垂直条纹
Iv = zeros(height,width,12);
Ia = 150;
Ib = 100;
s = 36;
f = [s+sqrt(s)+1,s,s-sqrt(s)];
f = f/width;
for j=1:width
    for k=1:3
        Iv(:,j,(k-1)*4+1) = round(Ia+Ib*cos(2*pi*f(k)*(j-0.5)+0*pi/2));
        Iv(:,j,(k-1)*4+2) = round(Ia+Ib*cos(2*pi*f(k)*(j-0.5)+1*pi/2));
        Iv(:,j,(k-1)*4+3) = round(Ia+Ib*cos(2*pi*f(k)*(j-0.5)+2*pi/2));
        Iv(:,j,(k-1)*4+4) = round(Ia+Ib*cos(2*pi*f(k)*(j-0.5)+3*pi/2));
    end
end

for n=1:12
    strNum = num2str(n);
    filename = ['generatePic\',strNum,'.bmp'];
    imwrite(uint8(Iv(:,:,n)),filename);
end

% 水平条纹
Ih = zeros(height,width,12);
s = 25;
f = [s+sqrt(s)+1,s,s-sqrt(s)];
f = f/height;
for i=1:height
    for k=1:3
        Ih(i,:,(k-1)*4+1) = round(Ia+Ib*cos(2*pi*f(k)*(i-0.5)+0*pi/2));
        Ih(i,:,(k-1)*4+2) = round(Ia+Ib*cos(2*pi*f(k)*(i-0.5)+1*pi/2));
        Ih(i,:,(k-1)*4+3) = round(Ia+Ib*cos(2*pi*f(k)*(i-0.5)+2*pi/2));
        Ih(i,:,(k-1)*4+4) = round(Ia+Ib*cos(2*pi*f(k)*(i-0.5)+3*pi/2));
    end
end
for n=1:12
    strNum = num2str(n+12);
    filename = ['generatePic\',strNum,'.bmp'];
    imwrite(uint8(Ih(:,:,n)),filename);
end

你可能感兴趣的:(结构光三维重建,matlab,开发语言,c++)