本文主要是介绍非接触测量-数字光栅投影-采样云纹法学习记录,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
对于前两天关于相位的问题有了新的理解,现在明白了怎么提取相位以及怎么使用提取出的相位。
分析
假设是一维变形,已知条件是变形前的光栅以及变形后的光栅,目标是算出位移;
以下是采样云纹法提取相位的程序
% 程序开始clc;close all;clear; % 图片的初始化
width = 1024;
heigth = 768; % 三频率
%像素单位为个数,可以看做频率;正弦函数为周期含义freq = [70 64 59]; %频率1,2,3;
f12 = abs((freq(1) * freq(2)) / (freq(1) - freq(2)));
f23 = abs((freq(2) * freq(3)) / (freq(2) - freq(3)));
f13 = abs((freq(1) * freq(3)) / (freq(1) - freq(3)));
f123 = abs((f12 * f23) / f12 - f23);% 利用分块矩阵C存储3组共计12张图
% 三种频率,四组相位
C = cell(3,4); for i = 1:3for j = 1:4C{i,j} = zeros(heigth,width);end
end% 利用余弦函数计算12张图的灰度值
% 图像的生成
% 三种频率,四组相位for i = 1 : 3 % 对应三种不同的频率for j = 0 : 3 % 对应四种相位for k = 1 : widthC{i,j + 1}(:,k) = 128 + 127 * sin(2 * pi * k * freq(i) / width + j * pi / 2);endend
end% 对灰度值进行归一化处理
for i = 1 : 3for j = 1 : 4C{i,j} = mat2gray(C{i,j});end
end% 显示12张图for i = 1 : 3for j = 1 : 4n = 4 * (i-1) + j;% h = figure(n);%imshow(C{i,j});filename = sprintf('Pic(%d).bmp', n);imwrite(C{i,j},filename,'bmp');endend% 初始化三组处理后的图片灰度矩阵
% phi也是分块矩阵
% 存储相位主值图像
phi = cell(3,1);
for i = 1:3phi{i,1} = zeros(heigth,width);
end% 求取相位差
% 计算每种频率对应的相位主值
% 输出三种频率的相位主值,用于相差计算for i = 1:3 % 对于3组中的每一组图片,每一组相同频率的有四张图片I1 = C{i,1};I2 = C{i,2};I3 = C{i,3};I4 = C{i,4};for g = 1:heigthfor k = 1:width if I4(g,k) == I2(g,k) && I1(g,k) > I3(g,k) %四个特殊位置phi{i,1}(g,k) = 0;elseif I4(g,k) == I2(g,k) && I1(g,k) < I3(g,k) %四个特殊位置phi{i,1}(g,k) = pi; elseif I1(g,k) == I3(g,k) && I4(g,k) > I2(g,k) %四个特殊位置phi{i,1}(g,k) = pi/2;elseif I1(g,k) == I3(g,k) && I4(g,k) < I2(g,k) %四个特殊位置phi{i,1}(g,k) = 3*pi/2;elseif I1(g,k) < I3(g,k) %二三象限phi{i,1}(g,k) = atan((I4(g,k)-I2(g,k))./(I1(g,k)-I3(g,k)))+pi;elseif I1(g,k) > I3(g,k) && I4(g,k) > I2(g,k) %第一象限phi{i,1}(g,k) = atan((I4(g,k)-I2(g,k))./(I1(g,k)-I3(g,k)));elseif I1(g,k) > I3(g,k) && I4(g,k) < I2(g,k) %第四象限phi{i,1}(g,k) = atan((I4(g,k)-I2(g,k))./(I1(g,k)-I3(g,k)))+2*pi;endend end
end% 计算相差
% 保存矩阵,用于多频相差的计算
PH1 = phi{1,1}; %频率1
PH2 = phi{2,1}; %频率2
PH3 = phi{3,1}; %频率3% 初始化相差变量
% 多频相差
PH12 = zeros(heigth,width);
PH23 = zeros(heigth,width);
PH13 = zeros(heigth,width);
PH123 = zeros(heigth,width);% 计算相差
% 相差计算
% 解相for g = 1:heigthfor k = 1:width% 计算第一组和第二组的相差if PH1(g,k) > PH2(g,k)PH12(g,k) = PH1(g,k) - PH2(g,k);elsePH12(g,k) = PH1(g,k) + 2 * pi - PH2(g,k);end% 计算第一组和第三组的相差if PH1(g,k) > PH3(g,k)PH13(g,k) = PH1(g,k) - PH3(g,k);elsePH13(g,k) = PH1(g,k) + 2*pi - PH3(g,k);end% 计算第二组和第三组的相差if PH2(g,k) > PH3(g,k)PH23(g,k) = PH2(g,k) - PH3(g,k);elsePH23(g,k) = PH2(g,k) + 2*pi - PH3(g,k);end% plot(1,k);end
end% 计算最终相差
% 相差图案
% 相位解包裹 相位展开for g = 1:heigthfor k = 1:width if PH12(g,k)>PH23(g,k)PH123(g,k) = PH12(g,k)-PH23(g,k);elsePH123(g,k) = PH12(g,k)+2*pi-PH23(g,k);endend
end% 利用外差合成的一级条纹计算不同频率的展开相位%UPH12 = zeros(heigth,width);
%UPH23 = zeros(heigth,width);
%UPH13 = zeros(heigth,width);UPH1 = zeros(heigth,width);
UPH2 = zeros(heigth,width);
UPH3 = zeros(heigth,width);for g = 1:heigthfor k = 1:width %UPH12(g,k) = PH12(g,k) +2 * pi * ceil((f12 / f123 * PH123(g,k) - PH12(g,k)) / (2*pi));%UPH23(g,k) = PH23(g,k) + 2* pi * ceil((f23 / f123 * PH123(g,k) - PH23(g,k)) / (2*pi));%UPH13(g,k) = PH13(g,k) + 2* pi * ceil((f13 / f123 * PH123(g,k) - PH13(g,k)) / (2*pi));UPH1(g,k) = PH1(g,k) + 2 * pi * ceil((freq(1) * PH123(g,k) - PH1(g,k)) / (2*pi));UPH2(g,k) = PH2(g,k) + 2*pi * ceil((freq(2) * PH123(g,k) - PH2(g,k)) / (2*pi));UPH3(g,k) = PH3(g,k) + 2*pi * ceil((freq(3) * PH123(g,k) - PH3(g,k)) / (2*pi));endend% 显示figure,imshow(mat2gray(PH12));title('1,2外差'); imwrite(mat2gray(PH12),'12外差.bmp');
figure,imshow(mat2gray(PH23));title('2,3外差'); imwrite(mat2gray(PH23),'23外差.bmp');
figure,imshow(mat2gray(PH123));title('1,2,3外差');imwrite(mat2gray(PH123),'123外差.bmp');figure,imshow(mat2gray(PH1));title('频率1相位主值'); imwrite(mat2gray(PH1),'1相位主值.bmp');
figure,imshow(mat2gray(PH2));title('频率2相位主值'); imwrite(mat2gray(PH2),'2相位主值.bmp');
figure,imshow(mat2gray(PH3));title('频率3相位主值'); imwrite(mat2gray(PH3),'3相位主值.bmp');%figure,imshow(mat2gray(UPH1));title('频率12展开相位'); imwrite(mat2gray(UPH12),'1展开相位.bmp');
%figure,imshow(mat2gray(UPH2));title('频率23展开相位'); imwrite(mat2gray(UPH23),'2展开相位.bmp');
%figure,imshow(mat2gray(UPH3));title('频率13展开相位'); imwrite(mat2gray(UPH13),'3展开相位.bmp');figure,imshow(mat2gray(UPH1));title('频率1展开相位'); imwrite(mat2gray(UPH1),'1展开相位.bmp');
figure,imshow(mat2gray(UPH2));title('频率2展开相位'); imwrite(mat2gray(UPH2),'2展开相位.bmp');
figure,imshow(mat2gray(UPH3));title('频率3展开相位'); imwrite(mat2gray(UPH3),'3展开相位.bmp');
5.31
去包裹相位如图;
频率1和频率2去包裹之后相位差:
频率2和频率3去包裹之后相位差:
多频外差原理
云纹法计算位移的关键在于获取变形前后的相位差。
这篇关于非接触测量-数字光栅投影-采样云纹法学习记录的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!