frdescp.m

%frdescp源程序
function z = frdescp(s) 
%FRDESCP Computes Fourier descriptors. 
%   Z = FRDESCP(S) computes the Fourier descriptors of S, which is an 
%   np-by-2 sequence of image coordinates describing a boundary.   
% 
%   Due to symmetry considerations when working with inverse Fourier 
%   descriptors based on fewer than np terms, the number of points in 
%   S when computing the descriptors must be even.  If the number of 
%   points is odd, FRDESCP duplicates the end point and adds it at 
%   the end of the sequence. If a different treatment is desired, the 
%   sequence must be processed externally so that it has an even 
%   number of points. 
% 
%   See function IFRDESCP for computing the inverse descriptors.  
 
%   Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins 
%   Digital Image Processing Using MATLAB, Prentice-Hall, 2004 
%   $Revision: 1.4 $  $Date: 2003/10/26 23:13:28 $ 
 
% Preliminaries 
[np, nc] = size(s); 
if nc ~= 2  
   error('S must be of size np-by-2.');  
end 
if np/2 ~= round(np/2); 
   s(end + 1, :) = s(end, :); 
   np = np + 1; 
end 
 
% Create an alternating sequence of 1s and -1s for use in centering 
% the transform. 
x = 0:(np - 1); 
m = ((-1) .^ x)'; 
  
% Multiply the input sequence by alternating 1s and -1s to 
% center the transform. 
s(:, 1) = m .* s(:, 1); 
s(:, 2) = m .* s(:, 2); 
% Convert coordinates to complex numbers. 
s = s(:, 1) + i*s(:, 2); 
% Compute the descriptors. 
z = fft(s); 
%源程序
function s = ifrdescp(z, nd) 
%IFRDESCP Computes inverse Fourier descriptors. 
%   S = IFRDESCP(Z, ND) computes the inverse Fourier descriptors of 
%   of Z, which is a sequence of Fourier descriptor obtained, for 
%   example, by using function FRDESCP.  ND is the number of 
%   descriptors used to computing the inverse; ND must be an even 
%   integer no greater than length(Z).  If ND is omitted, it defaults 
%   to length(Z).  The output, S, is a length(Z)-by-2 matrix containing 
%   the coordinates of a closed boundary. 
 
%   Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins 
%   Digital Image Processing Using MATLAB, Prentice-Hall, 2004 
%   $Revision: 1.6 $  $Date: 2004/11/04 22:32:04 $ 
 
% Preliminaries. 
np = length(z); 
% Check inputs. 
if nargin == 1 | nd > np  
   nd = np;  
end 
 
% Create an alternating sequence of 1s and -1s for use in centering 
% the transform. 
x = 0:(np - 1); 
m = ((-1) .^ x)'; 
 
% Use only nd descriptors in the inverse.  Since the  
% descriptors are centered, (np - nd)/2 terms from each end of  
% the sequence are set to 0.   
d = round((np - nd)/2); % Round in case nd is odd. 
z(1:d) = 0; 
z(np - d + 1:np) = 0; 
% Compute the inverse and convert back to coordinates. 
zz = ifft(z); 
s(:, 1) = real(zz); 
s(:, 2) = imag(zz); 
% Multiply by alternating 1 and -1s to undo the earlier  
% centering. 
s(:, 1) = m.*s(:, 1); 
s(:, 2) = m.*s(:, 2); 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值