⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zlf_dunwrap_m.m

📁 这是在MATLAB下生成的彩色条纹,对于傅里叶变换很有用,可以扩大实验的研究范围,更好的设计实验
💻 M
字号:
function [UnwrappedPhase] = zlf_dunwrap_m(WrappedPhase,Mask,ptstart)
% ZLF_DUNWRAP的改进版,本文件在ZLF_DUNWRAP的基础上仅改动了路径纪录方式
% 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坐标,
%一个指针域存放下一个待展开点的地址;
SUMS=nRow*nCol;
CycQuex(1:SUMS)=0;
CycQuey(1:SUMS)=0;
CycQuepx(1:SUMS)=0;
CycQuepy(1:SUMS)=0;
CycQueni(1:SUMS)=2:SUMS+1;
CycQueni(SUMS+1)=1;

head = zeros(1,1); 
head = 1; %指向队列起始点;
rear = zeros(1,1);
rear = 2;%指向队列的尾部;初始时为head的下一个单元;

CycQuex(head) = I; %展开起始点;
CycQuey(head) = J;
CycQuepx(head) = I;%已展开点;
CycQuepy(head) = 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(CycQuepy(head),CycQuepx(head)); %展开点相位值;
    b = WrappedPhase(CycQuey(head),CycQuex(head)); %待展开点相位值;
    %         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(CycQuey(head),CycQuex(head)) = b; %展开后赋值交回;
    
    tempx = CycQuex(head);%记录当前展开点;
    tempy = CycQuey(head);
    
    Track(1,TrackCont) = tempx;%记录展开路径
    Track(2,TrackCont) = tempy;
    TrackCont = TrackCont+1;       
    
    %        pause(0.03);
    %        plot(tempy,tempx,'r*');
    
    head = CycQueni(head); %下一个结点;
    
    if (tempy > 1) & (HasPush(tempy-1,tempx) == 0) & (Mask(tempy-1,tempx) == 1) %上一点:(x,y-1)
        CycQuex(rear) = tempx; %展开点
        CycQuey(rear) = tempy-1;
        CycQuepx(rear) = tempx;%已展开点;
        CycQuepy(rear) = tempy;
        %             fprintf('Up : (%d,%d)\n',CycQuex(rear),CycQuey(rear));
        
        HasPush(CycQuey(rear),CycQuex(rear)) = 1; %修改入队标志;
        rear = CycQueni(rear); %指向下一个结点,准备进行下一次展开;
    end
    
    if (tempx < nCol) & (HasPush(tempy,tempx+1) == 0) & (Mask(tempy,tempx+1) == 1) %右一点:(x+1,y)
        CycQuex(rear) = tempx+1; %展开点;
        CycQuey(rear) = tempy;
        CycQuepx(rear) = tempx;%已展开点;
        CycQuepy(rear) = tempy;
        
        %             fprintf('Right : (%d,%d)\n',CycQuex(rear),CycQuey(rear));
        
        HasPush(CycQuey(rear),CycQuex(rear)) = 1; %修改入队标志; 
        rear = CycQueni(rear); %指向下一个结点,准备进行下一次展开;
    end
    
    if (tempy < nRow) & (HasPush(tempy+1,tempx) == 0) & (Mask(tempy+1,tempx) == 1)  %下一点:(x,y+1)
        CycQuex(rear) = tempx; %展开点;
        CycQuey(rear) = tempy+1;
        CycQuepx(rear) = tempx;%已展开点;
        CycQuepy(rear) = tempy;
        
        %             fprintf('Down : (%d,%d)\n',CycQuex(rear),CycQuey(rear));
        
        HasPush(CycQuey(rear),CycQuex(rear)) = 1; %修改入队标志;
        rear = CycQueni(rear);%指向下一个结点,准备进行下一次展开;
    end       
    
    if (tempx > 1) & (HasPush(tempy,tempx-1) == 0) & (Mask(tempy,tempx-1) == 1) %左一点:(x-1,y)
        CycQuex(rear) = tempx-1; %展开点;
        CycQuey(rear) = tempy;
        CycQuepx(rear) = tempx;%已展开点;
        CycQuepy(rear) = tempy;
        
        %             fprintf('Left : (%d,%d)\n',CycQuex(rear),CycQuey(rear));
        
        HasPush(CycQuey(rear),CycQuex(rear)) = 1; %修改入队标志;
        rear = CycQueni(rear);%指向下一个结点,准备进行下一次展开;
    end
    
end

% disp('Diamondunwrapping job finished');

Time=etime(clock,t0);
disp(' ');
fprintf('The zlf_dunwrap_m total consumption of time is %2.2f second\n',Time);
disp(' ');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -