获取函数及其使用方法
pzernfun函数可在下面的链接中获取:
https://ww2.mathworks.cn/matlabcentral/fileexchange/33644-pseudo-zernike-functions?s_tid=FX_rc3_behav作者很贴心地在函数里添加了示例,如果我们想要获取一个图像的伪泽尼克矩,可参考其中的Example2,具体代码见下:
% Example 2: Pseudo-Zernike moments
%
% % Build a grid
% N = 100;
% x = (-N:2:N)/N;
% [X,Y] = meshgrid(x);
% [theta,r] = cart2pol(X,Y);
%
% is_in_circle = r <= 1;
% r = r(is_in_circle);
% theta = theta(is_in_circle);
%
% % Create some data
% F = peaks(N+1);F = F/max(abs(F(:))); % Normalize
% F(~is_in_circle) = nan;
%
% % Compute a (finite) basis of pseudo-Zernike functions
% n_max = 7;
% n = zeros(1,(n_max+1)^2);
% m = zeros(1,(n_max+1)^2);
% for k = 0:n_max
% n(k^2+1:(k+1)^2) = repmat(k,1,2*k+1);
% m(k^2+1:(k+1)^2) = -k:k;
% end
% P = pzernfun(n,m,r,theta);
%
% % Estimate the pseudo-Zernike moments, using simple
% % summation to approxmiate the integrals
% M = zeros(1,(n_max+1)^2);
% for k = 1:(n_max+1)^2
% M(k) = sum(F(is_in_circle)'*P(:,k))*(2/N)^2;
% end
%
% % Use the computed moments to recover the original data
% F_recovered = nan(size(X));
% F_recovered(is_in_circle) = P*M';
它相当于是将图像先映射到单位圆中,n_max是阶数,先根据pzernfun函数得到一个矩阵P,再将其与图像F进行一系列运算即可得到维泽尼克矩。