what is zernike moments?

조회 수: 27 (최근 30일)
Mansoor ahmadi
Mansoor ahmadi 2015년 1월 20일
편집: 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.
sorry for my bad English!
thanks in advance.
a=imread('Oval_H.png');
p = im2bw(a,0.5);
a=imread('4.png');
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;
Rad = radialpoly(R,n,m); % get the radial polynomial
Product = p(x,y).*Rad.*exp(-1i*m*Theta);
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)
%**********************************************************************************
function rad = radialpoly(r,n,m)
rad = zeros(size(r)); % Initilization
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));
rad = rad + c*r.^(n-2*s);
end
  댓글 수: 1
Mansoor ahmadi
Mansoor ahmadi 2015년 1월 21일
Please answer my above question if someone know!

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

답변 (5개)

student
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?

ancy micheal
ancy micheal 2017년 11월 21일
unable to execute : Undefined function or variable 'n'.

arun anoop m
arun anoop m 2019년 9월 9일

arun anoop m
arun anoop m 2019년 9월 9일
hello Mansoor sir,
your code is working fine
But you need to keep it as seperate files.
%*******************************************************************************
zerniketest.m
a=imread('Oval_H.png');
p = im2bw(a,0.5);
% a=imread('4.png');
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)]});
%*******************************************************************************
radialpoly.m
function rad = radialpoly(r,n,m)
rad = zeros(size(r)); % Initilization
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));
rad = rad + c*r.^(n-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;
Rad = radialpoly(R,n,m); % get the radial polynomial
Product = p(x,y).*Rad.*exp(-1i*m*Theta);
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

arun anoop m
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,
a=imread('flowers.jpg');
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');
instead
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

카테고리

Help CenterFile Exchange에서 Zernike Polynomials에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by