# what is zernike moments?

조회 수: 16(최근 30일)
편집: arun anoop m 2019년 9월 9일
hello!
I have gotten the code of zernike moments from mathworks site it work good and it return tow value, but I don't know what is that and also I don't know how many moment it extract from image if it extract one moment how I edit this code that extract several moment. this is the code:
each function is in separate script.
p = im2bw(a,0.5);
figure(1);subplot(2,3,1);imshow(p);
title('Horizontal oval');
p = logical(not(p));
tic
[~, AOH, PhiOH] = Zernikmoment(p,n,m); % Call Zernikemoment fuction
Elapsed_time = toc;
xlabel({['A = ' num2str(AOH)]; ['\phi = ' num2str(PhiOH)]});
%***************************************************************************
function [Z A Phi] = Zernikmoment(p,n,m)
N = size(p,1);
x = 1:N; y = x;
[X,Y] = meshgrid(x,y);
R = sqrt((2.*X-N-1).^2+(2.*Y-N-1).^2)/N;
Theta = atan2((N-1-2.*Y+2),(2.*X-N+1-2));
R = (R<=1).*R;
Z = sum(Product(:)); % calculate the moments
cnt = nnz(R)+1; % count the number of pixels inside the unit circle
Z = (n+1)*Z/cnt; % normalize the amplitude of moments
A = abs(Z); % calculate the amplitude of the moment
Phi = angle(Z)*180/pi; % calculate the phase of the mement (in degrees)
%**********************************************************************************
for s = 0:(n-abs(m))/2
c = (-1)^s*factorial(n-s)/(factorial(s)*factorial((n+abs(m))/2-s)*factorial((n-abs(m))/2-s));
end

댓글을 달려면 로그인하십시오.

### 답변(5개)

student 2016년 12월 19일
Hi Mansoor. I used the same code but i have different error which is : Index exceeds matrix dimensions.
Error in Zernikmoment (line 47) Product = p(x,y).*Rad.*exp(-1i*m*Theta);
Error in process_predict_leaf (line 80) [mom, amplitude, angle] = Zernikmoment(b,4,0); % Call Zernikemoment fuction n=4, m=0
Did you know why I got this error?
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

댓글을 달려면 로그인하십시오.

ancy micheal 2017년 11월 21일
unable to execute : Undefined function or variable 'n'.
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

댓글을 달려면 로그인하십시오.

arun anoop m 2019년 9월 9일
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

댓글을 달려면 로그인하십시오.

arun anoop m 2019년 9월 9일
hello Mansoor sir,
But you need to keep it as seperate files.
%*******************************************************************************
zerniketest.m
p = im2bw(a,0.5);
figure(1);subplot(2,3,1);imshow(p);
title('Horizontal oval');
p = logical(not(p));
tic
[~, AOH, PhiOH] = Zernikmoment(p,n,m); % Call Zernikemoment fuction
Elapsed_time = toc;
xlabel({['A = ' num2str(AOH)]; ['\phi = ' num2str(PhiOH)]});
%*******************************************************************************
for s = 0:(n-abs(m))/2
c = (-1)^s*factorial(n-s)/(factorial(s)*factorial((n+abs(m))/2-s)*factorial((n-abs(m))/2-s));
end
%*******************************************************************************
Zernikemoment.m
function [Z A Phi] = Zernikmoment(p,n,m)
N = size(p,1);
x = 1:N; y = x;
[X,Y] = meshgrid(x,y);
R = sqrt((2.*X-N-1).^2+(2.*Y-N-1).^2)/N;
Theta = atan2((N-1-2.*Y+2),(2.*X-N+1-2));
R = (R<=1).*R;
Z = sum(Product(:)); % calculate the moments
cnt = nnz(R)+1; % count the number of pixels inside the unit circle
Z = (n+1)*Z/cnt; % normalize the amplitude of moments
A = abs(Z); % calculate the amplitude of the moment
Phi = angle(Z)*180/pi; % calculate the phase of the mement (in degrees)
%*******************************************************************************
Reference:
[1] Zernike Moments, version 1.5 (15.1 KB) by Amir Tahmasbi ,"MATLAB Code for the Fast Calculation of Zernike Moments of order n and repetition m on NxN images",Available:https://in.mathworks.com/matlabcentral/fileexchange/38900-zernike-moments
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

댓글을 달려면 로그인하십시오.

arun anoop m 2019년 9월 9일
편집: arun anoop m 2019년 9월 9일
One more thing sir,
The program will only for black and white images. So if u need to show other images, has to do the following,
p = im2bw(a,0.5);
figure(1);subplot(2,3,1);imshow(p);
title('Horizontal oval');
p = logical(not(p));
tic
[~, AOH, PhiOH] = Zernikmoment(p,n,m); % Call Zernikemoment fuction
Elapsed_time = toc;
xlabel({['A = ' num2str(AOH)]; ['\phi = ' num2str(PhiOH)]});
Actually i am searching a code for getting Angle(A) and magnitude(Phi) as image output. I dont know how to call array function in another file.
If all the programs are in same file, can use the following code,
figure,imshow(uint8(A)),title('Zernike Moment Angle');
xlabel({['A = ' num2str(AOH)]; ['\phi = ' num2str(PhiOH)]});
Reference:
[1] Zernike Moments, version 1.5 (15.1 KB) by Amir Tahmasbi ,"MATLAB Code for the Fast Calculation of Zernike Moments of order n and repetition m on NxN images",Available:https://in.mathworks.com/matlabcentral/fileexchange/38900-zernike-moments

댓글을 달려면 로그인하십시오.

### 범주

Find more on Zernike Polynomials in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by