📄 zlf_dunwrap.m
字号:
function [UnwrappedPhase] = zlf_dunwrap(WrappedPhase,Mask,ptstart)
% ZLF_DUNWRAP - Unwrapping the wrapped phase using DIAMOND method;-
%
%Descriptions:
% [UnwrappedPhase] = ZLF_DUNWRAP(WrappedPhase,mask,ptstart);
%Examples:
% [UnwrappedPhase] = zlf_dunwrap(WrappedPhase,mask,ptstart);
% WrappedPhase : The wrapped phase;
% mask : The [0 1] binary mask plate using in phase unwrapping;
% ptstart : the coordinates of start point; it MUST be a 1*2 array;
% UnwrappedPhase : The unwrapped phase;
%See also: zlf_funwrap
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Author - Qc Zhang & Y Li 16-Nov-2004
% Last Revised - Qc Zhang & Y Li 16-Nov-2004
% Copyright 2004-2004 Qc Zhang & Y Li. All Rights Reserved.
% $Revision: 1.001.001 $ $Date: 16-Nov-2004 16:34:27 $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
error(nargchk(1, 3, nargin));
error(nargchk(0, 1, nargout));
if nargin == 1
[r c] = size(WrappedPhase);
Mask = ones(r,c);
ptstart = [round(r/2),round(c/2)];
elseif nargin == 2
[r c] = size(WrappedPhase);
ptstart = [round(r/2),round(c/2)];
elseif nargin ~= 3
disp('Error using! Not enough OR too many parameters.')
end
t0=clock;
J = ptstart(2);
I = ptstart(1);
disp('Unwrapping the Phase Using Diamond Method...');
[nRow, nCol] = size(WrappedPhase);
UnwrappedPhase = zeros(nRow, nCol);
% UnwrappedPhase=UnwrappedPhase-20000*pi;
HasPush = zeros(nRow,nCol);
Track = zeros(2,nRow*nCol);
TrackCont = 1;
%构造一个循环队列,四个值域分别放置待展开点和已展开点的x,y坐标,
%一个指针域存放下一个待展开点的地址;
for i = 1:2*(nRow+nCol)
CycQue(i).x = 0; %待展开的点x坐标;
CycQue(i).y = 0; %待展开的点y坐标;
CycQue(i).px = 0; %已展开的前一点x坐标;
CycQue(i).py = 0; %已展开的前一点y坐标;
CycQue(i).ni = i+1; %待展开的下一点队列位置;
end
t0=clock;
CycQue(i).ni = 1;%队列尾部单元的指针指向队头,形成循环队列;
head = zeros(1,1);
head = 1; %指向队列起始点;
rear = zeros(1,1);
rear = 2;%指向队列的尾部;初始时为head的下一个单元;
CycQue(head).x = I; %展开起始点;
CycQue(head).y = J;
CycQue(head).px = I;%已展开点;
CycQue(head).py = J;
HasPush(J,I) = 1; %入队标志
UnwrappedPhase(J,I) = WrappedPhase(J,I); %已展开相位;
%idisp(Mod);set(gcf,'Color',[1, 1, 1]);axis off
%hold on;
while (head ~= rear) % 如果该循环队列为空,停止展开;
a = UnwrappedPhase(CycQue(head).py,CycQue(head).px); %展开点相位值;
b = WrappedPhase(CycQue(head).y,CycQue(head).x); %待展开点相位值;
% disp('Unwrapping...')
b = b + ((b-a) < -pi).*2*pi*round(-(b-a)/(2*pi)) - ((b-a) > pi).*2*pi*round((b-a)/(2*pi)); %相位展开
UnwrappedPhase(CycQue(head).y,CycQue(head).x) = b; %展开后赋值交回;
tempx = CycQue(head).x;%记录当前展开点;
tempy = CycQue(head).y;
Track(1,TrackCont) = tempx;%记录展开路径
Track(2,TrackCont) = tempy;
TrackCont = TrackCont+1;
% pause(0.03);
% plot(tempy,tempx,'r*');
head = CycQue(head).ni; %下一个结点;
if (tempy > 1) & (HasPush(tempy-1,tempx) == 0) & (Mask(tempy-1,tempx) == 1) %上一点:(x,y-1)
CycQue(rear).x = tempx; %展开点
CycQue(rear).y = tempy-1;
CycQue(rear).px = tempx;%已展开点;
CycQue(rear).py = tempy;
% fprintf('Up : (%d,%d)\n',CycQue(rear).x,CycQue(rear).y);
HasPush(CycQue(rear).y,CycQue(rear).x) = 1; %修改入队标志;
rear = CycQue(rear).ni; %指向下一个结点,准备进行下一次展开;
end
if (tempx < nCol) & (HasPush(tempy,tempx+1) == 0) & (Mask(tempy,tempx+1) == 1) %右一点:(x+1,y)
CycQue(rear).x = tempx+1; %展开点;
CycQue(rear).y = tempy;
CycQue(rear).px = tempx;%已展开点;
CycQue(rear).py = tempy;
% fprintf('Right : (%d,%d)\n',CycQue(rear).x,CycQue(rear).y);
HasPush(CycQue(rear).y,CycQue(rear).x) = 1; %修改入队标志;
rear = CycQue(rear).ni; %指向下一个结点,准备进行下一次展开;
end
if (tempy < nRow) & (HasPush(tempy+1,tempx) == 0) & (Mask(tempy+1,tempx) == 1) %下一点:(x,y+1)
CycQue(rear).x = tempx; %展开点;
CycQue(rear).y = tempy+1;
CycQue(rear).px = tempx;%已展开点;
CycQue(rear).py = tempy;
% fprintf('Down : (%d,%d)\n',CycQue(rear).x,CycQue(rear).y);
HasPush(CycQue(rear).y,CycQue(rear).x) = 1; %修改入队标志;
rear = CycQue(rear).ni;%指向下一个结点,准备进行下一次展开;
end
if (tempx > 1) & (HasPush(tempy,tempx-1) == 0) & (Mask(tempy,tempx-1) == 1) %左一点:(x-1,y)
CycQue(rear).x = tempx-1; %展开点;
CycQue(rear).y = tempy;
CycQue(rear).px = tempx;%已展开点;
CycQue(rear).py = tempy;
% fprintf('Left : (%d,%d)\n',CycQue(rear).x,CycQue(rear).y);
HasPush(CycQue(rear).y,CycQue(rear).x) = 1; %修改入队标志;
rear = CycQue(rear).ni;%指向下一个结点,准备进行下一次展开;
end
end
% disp('Diamondunwrapping job finished');
Time=etime(clock,t0);
disp(' ');
fprintf('The total consumption of time is %2.2f second\n',Time);
disp(' ');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -