Code covered by the BSD License  

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Zernike Moments

4.2 | 13 ratings Rate this file 128 Downloads (last 30 days) File Size: 15.1 KB File ID: #38900 Version: 1.5
image thumbnail

Zernike Moments



05 Nov 2012 (Updated )

MATLAB Code for the Fast Calculation of Zernike Moments of order n and repetition m on NxN images.

| Watch this File

File Information

This submission includes 3 mfiles and 6 image files:
1- Zernike_main.m (The main script that takes care of everything)
2- Zernikmoment.m (Calculates the Zernike moments for an NxN ROI)
3- radialpoly.m (Calculates the radial polynomials which are prerequisites for calculating Zernike moments)
4- Six .png files to test the code.
When you run the Zernike_main.m, it will calculate the Zernike moments of order n=4 and repetition m=2 for the input images. Since the first row images are just the rotated versions of a unique object (oval), the magnitudes of the Zernike moments for these three images are the same. In addition, the differences between the phases of the moments are proportional to the rotation angles of the images. Expectedly, the Zernike moments of two different shapes (e.g. oval and rectangle) are totally different. The reason of this behavior is the ability of Zernike moments in describing the shape of objects.

License agreement: To acknowledge the use of the code please cite the following papers:

A. Tahmasbi, F. Saki, S. B. Shokouhi, Classification of Benign and Malignant Masses Based on Zernike Moments, Comput. Biol. Med., vol. 41, no. 8, pp. 726-735, 2011.

F. Saki, A. Tahmasbi, H. Soltanian-Zadeh, S. B. Shokouhi, Fast opposite weight learning rules with application in breast cancer diagnosis, Comput. Biol. Med., vol. 43, no. 1, pp. 32-41, 2013.

Required Products MATLAB
MATLAB release MATLAB 7.11 (R2010b)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (48)
02 May 2016 Tatiara Régis

I have been reading the article you sent me.

Thank you.


Comment only
28 Apr 2016 Swati Vyas

Very informative...I Love the code..

Comment only
06 Apr 2016 Amir Tahmasbi

Hi Tatiara,

Here is the main publication I was referring to:

Hope this helps.


Comment only
06 Apr 2016 Tatiara Régis

Dear Tahmasbi,

I believe have located the article in:


Comment only
05 Apr 2016 Tatiara Régis

Dear Tahmasbi,
good afternoon!
The link sends detailed study on the frequency of Zernike Moments mainly seemed to be broken.
Please could you tell me the title of the publication?
I'm trying to implement the Zernike moments for fingerprints of microorganisms. I read some of his works and certainly I will quote them in my works. For then enrich my knowledge on the subject.

Comment only
26 Sep 2015 Rashi BN

good one

Comment only
30 Aug 2015 Vijayalakshmi Mahesh

Hi Amir,

Can you please help me in constructing the Zernike moment based kernels . These kernels when convolved with an image should detect the edge of it.

Thanks in advance

Comment only
05 May 2015 Manpreet

Can you provide me the help how to reconstruct the signal back after applying Zernike.

Comment only
13 Apr 2015 Sumeet padhi

sir please tell me how can i count the zernike moment at some predefined points using ur code.thank u

11 Mar 2015 Meghana Dinesh


I want to use your code in my application to match templates. I have explained my issue here:

I am not very familiar with Image Moments so this might seem very trivial to you. The outputs A and phi are almost similar for images with and without noise (shown in screenshot on that link). Is this beyond the scope of your code? Is there anything I can alter so it can solve my issue?


Comment only
11 Mar 2015 Meghana Dinesh  
11 Mar 2015 Meghana Dinesh

* 'A' seems very similar

01 Feb 2015 tripti

tripti (view profile)

Hi Amir,

This code is excellent.
My doubt is how to use zernike moment for classification in back propagation algorithm. please help

Comment only
01 Feb 2015 Amir Tahmasbi

Hi Yijun,

Thanks for your feedback. I think the code should work for MxN images with minor modifications. I will try to incorporate this feature into the next update of the code.

Unfortunately, I don't have the code for Pseudo-Zernike moments.


Comment only
30 Jan 2015 Yijun Yan

Hi Amir,

This code is excellent.
But I wonder if it works well for the image with size M*N?
And do you happen to have the code for Pseudo-Zernike moment?


13 Dec 2014 Amir Tahmasbi

Hi Satya,

Can you please be a little more specific about what you mean by the "kernel"? My understanding is that you what to plot the radial polynomials. Is this correct?


Comment only
10 Dec 2014 satya singh

dear amir,
can you please provide codes for plotting the kernel

Comment only
31 Jul 2014 Amir Tahmasbi

Hi Frederik,

Thank you for your interest in my code. I have addressed your concerns as follows:

1- Regarding “Product = p(x,y).*Rad.*exp(-1i*m*Theta);” I should say this is actually correct. Remember that the Zernike moments are calculated by multiplying the input image p(x,y) and the complex conjugate of 2-D Zernike basis functions (typically denoted by V_n,m = R_n,m(\rho) . exp(j m \theta). In other words, we have “Product = p(x,y) V*_m,n = p(x,y) . R_n,m(\rho) . exp( - j m \theta)” .The negative sign that you are refereeing to is, therefore, added due to the complex conjugate operator. For a clearer explanation please see my paper, p. 730, eq. 11 (available on-line at ). Also you can take a look at the classic paper on Zernike moments by Dr. Khotanzad, p. 490, eq. 5 (available on-line at ). You can further verify this using eq. 49 in the web page you sent me.
2- You are right. The mapping we have used in the code, loses the information of the corners of the image. This is, however, a common mapping strategy from the image space into the unit disk that researchers typically use for the calculation of the Zernike moments (see e.g. Dr. Khotanzad’s paper above). From a practical point of view, it usually does not cause any problem since the object of interest is scaled such that it is circumscribed by the unit disc.
3- The code can easily be generalized to the non-square shaped ROIs. Since this is a questions that many other people have also asked, I will update the code on the MATLAB central page for rectangular shaped images when I get a chance (probably in a few weeks). You can also do it yourself.
4- I can make some MxN test image sets, but I will need some time to do this. You can also make those images using the square images I put on the MATLAB central page (just add say 5 rows above and below the ROI). Then, you can rotate the object within the same ROI and verify if the magnitudes of the moments remain the same.

Comment only
29 Jul 2014 Frederik Kratzert

Hello Amir,
first of all, thanks for sharing your code.
secondly i would like to ask a question, in which i dont know if i make a mistake or you did in your code.

Product = p(x,y).*Rad.*exp(i*m*Theta)
to calculate the complex polynominal in all the formulars i found
(e.g: )
its written that j = sqrt(-1);
you wrote in your code -1*i instead, which is not the same. because sqrt(-1) is just the definition of the complex number to be i. so am i wrong or should it be:

Product = p(x,y).*Rad.*exp(i*m*Theta)

in your code, without the -1?

i hope its understandable what i want to say.

tanks again, frederik

Comment only
01 Jun 2014 fathi

fathi (view profile)

21 Apr 2014 fateme

fateme (view profile)

Thank you

27 Nov 2013 Dimitris Tsolakidis

Hello Amir. Thank you for your code. I have used your code to calculate zernike moments from an image, but i'm having problem reconstruct the image from it's moments. Could you provide me some help please?

19 Sep 2013 mariem farhat

Another question:

1. your code assume that the image is square; and if it wasn't?

2. I don't understand Product = p(x,y).*Vnm? why not Product = p.*Vnm;

Comment only
19 Sep 2013 mariem farhat

Thank you for the code.
But why in the image mapping you use (2.*X-N-1) and not (2.*X-N)?

Thank you!

Comment only
19 Sep 2013 mariem farhat  
21 Aug 2013 MUTHU RAM

Actually want to find the global features with zernike moments of the image but dono how to proceed with it??

Comment only
20 Aug 2013 MUTHU RAM

can Any one say how to find the Zernike moments for rgb image...Thanks in advance

Comment only
09 Aug 2013 dana Wang

Hi Tahmasbi,
Thank you for your code. can u please hepl me to modify your code substituding p(x/a+x1,y/a+x2) to p(x,y),where p(x,y) is original image, x1 and x2 are the centroid of p(x,y),x1=m10/m00,x2=m01/m00,a=sqrt(β/m00),β is a predetermined value. In fact, this is doing scale and translation normalization. Thank you very much.

Comment only
23 Jul 2013 Amir Tahmasbi

Hi Mitra,

1- It mainly depends on your application and you need some experience to pick the appropriate order (n) and repetition (m) for your moments. However, the rule of thumb is that the lower orders provide less information (details) but are more robust to noise. Higher orders, on the other hand, provide more information about the details of the object but are more sensitive to the measurement noise. An efficient way is to calculate the Zernike moments for a variety of m and n values. You may then apply a feature selection algorithm and remove the correlated features (moments). You can finally use a group of say 20 moments, which are reasonably uncorrelated, to pass to your classifier.

2- I think with appropriate preprocessing steps, the Zernike moments should be useful for Farsi digit recognition.


Comment only
18 Jul 2013 mitra Isaei

oh, excuse me. I understand my answer.
but I have other questions:
1.How do I understand What values are appropriate for Assignment to n and m?
I'm using zernike moment for handwritten farsi digits recognition.
2. Are features that obtain from Zernike moments, useful for classification in handwritten farsi digits recognition?

Comment only
18 Jul 2013 mitra Isaei

hi sir
your code calculates one Zernike moment and its magnitude. how to change this code to calculate more Zernike moments.

Comment only
11 Jul 2013 Amir Tahmasbi

Hi Shriniwas,

Yes, the code is capable of calculating the Zernike moments of any order and repetition. All you need to do is change m (repetition) and n (order). The default ones are n=4 and m=2. Hope this helps.


Comment only
02 Jul 2013 Shriniwas Chavan

Sir I am using zernike moment for handwritten character recognition, I have applied zernike moment in terms of geometric moment, but it is upto 3 and 4 order, i want to extend the code can your files can extend it or extract zernike moment

Comment only
16 Jun 2013 Reyadh

Reyadh (view profile)

Hi Amir
thanks for replay
I know what you say
now almost I have identification for some plamprints
I used high zernike order
and better database
also i maked unit disk for pic
I will make some addition and see what happen
Thanks you

Comment only
13 Jun 2013 Amir Tahmasbi

Hi Reyadh,

In principle, the Zernike moments can be extracted from any shape. However, in your case, there could be a variety of potential issues. First of all, you need to make sure the objects (palm prints) are of equal size within the ROI. If not, you need to equalize the size of your objects in all ROIs.

The other thing is that the palm prints are more complicated object than simple shapes, e.g. oval and circle. Thus, you might need to extract a set of higher order Zernike moments. You can then use these moments to classify the palm prints of different people more reliably.

FYI, the magnitude of the Zernike moments of two similar shapes might be slightly vary due to the pixelation and noise. But the difference should be insignificant.


Comment only
08 Jun 2013 Reyadh

Reyadh (view profile)

08 Jun 2013 Reyadh

Reyadh (view profile)

hello Tamanna
I used your zernike to find zernike moment for palmprint
but there are some problem
when use for that A=0,Theta=0
I make some changed to the code
I replaced p = logical(not(p));
to p=im2double(p);
and it is work after that with palmprint and your pics nad values equal with yours
but the problem the values does not equal for same person palmprint
any help?

Comment only
04 May 2013 Amir Tahmasbi

Hi Tareq

Thanks! The input arguments "m" and "n" are scalars. This means that if you would like to extract say 32 moments, you need to have a "for loop" in which you change "n" and "m", and call the Zernikemoment(p, n, m). Depending on your application you can either change "n" from y to 32+y or use different combinations of "m" and "n". For more information, see Table 1 in page 731 of this article:

Hope this helps.

Comment only
30 Apr 2013 Frb

Frb (view profile)

30 Apr 2013 Tareq Al-Zubaidi

nice job,,, one question, if we say 32 moments so i expect when I call [ZOH AOH PhiOH] = Zernikmoment(p,n,m);

the ZOH to be an array of 32 ? or what 32 moments mean here ?

Comment only
15 Apr 2013 Amir Tahmasbi

Hi Tamanna,

The Zernike moments are rotation-invariant, no question on it! So, if you use the sample pictures included in the package, you will see this feature.

The reason that you are getting different results for the abs of Zernike moments is explained as follows. The MATLAB function "imrotate" does not preserve the size of an object in the ROI. Please note that the ROI size will be the same but the original image will be shrank in the new ROI. Thus, you are changing the object size that alters the abs of the Zernike moments. Hope this helps.


Comment only
10 Apr 2013 tamanna

hey..can u please help me to identify that how this code is invariant to rotation..

because if i apply 'imrotate' with 30 or 45 degree on an image, then the result is different.

Comment only
02 Apr 2013 Amir Tahmasbi

Hi Anandh,

Yes, that is correct. By changing 'n' you can change the order of the Zernike moments to generate a set of say 32 features. However, you should keep in mind that also the variable 'm' (i.e. the repetition of moments) plays an important rule in the behavior of the moments. Hence, 'm' should be selected adaptively by changing 'n'. To find a suitable repetition for your proposed order, please see:

Hope this helps! Let me know if you have any other concerns.


Comment only
02 Apr 2013 Anandh

Anandh (view profile)

Hi Amir,

Am new to this Zernike Moments. I tried to understand your code. I have few doubts. How to find 32 order features for a given image? Is it by varying the number 'n'? Please reply.

Comment only
21 Dec 2012 Cobi Biton  
15 Nov 2012 Amir Tahmasbi

Thanks guys! Chris: I refer you to one of our papers in which we normalize the ROIs before extracting the Zernike moments (i.e. we remove the dependency of Zernike moments on the translation and scaling of object in the preprocessing step). Here it is:

Another way is to use the Zernike moment invariants explained nicely here:

Comment only
14 Nov 2012 Chris

Chris (view profile)

Good job!And, how is the zernike moment invariants

06 Nov 2012 Fatemeh Saki

Nice job!! Thank you so much.

02 Jan 2013 1.1

Removed several minor mistakes in the description of the file.

21 Jan 2013 1.2

Rephrased the summary for clarity.

31 May 2013 1.3

Added more sample shapes with different rotation angles.

02 Oct 2014 1.4

Just updated the description.

20 Nov 2014 1.5

- Updated to make the submission available as a toolbox in MATLAB R2014b.
- Minor enhancements in the comments.

Contact us