Code covered by the BSD License  

Highlights from
Zernike polynomials

4.66667

4.7 | 15 ratings Rate this file 63 Downloads (last 30 days) File Size: 6.84 KB File ID: #7687
image thumbnail

Zernike polynomials

by Paul Fricker

 

18 May 2005 (Updated 24 Oct 2011)

Zernike polynomials and functions (orthogonal basis on the unit circle).

| Watch this File

File Information
Description

ZERNFUN.m and ZERNFUN2.m compute the Zernike functions Znm(r,theta). These functions, which form an orthogonal basis on the unit circle, are used in disciplines such as astronomy, optics, optometry, and ophthalmology to characterize functions and data on a circular domain. ZERNPOL.m computes the Zernike polynomials Znm(r), which are the radial portion of the Zernike functions.

A MATLAB Digest article describing the use of the Zernike functions for analyzing optics data (using a LASIK surgery data as an example) also is available, on the File Exchange as a PDF,

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=19133&objectType=file

and in HTML at:

http://www.mathworks.com/company/newsletters/digest/2008/jan/zernike.html

Acknowledgements
This submission has inspired the following:
Zernike decomposition, Zernike Polynomial Coefficients for a given Wavefront using Matrix Inversion in Matlab, zernike3
MATLAB release MATLAB 7.3 (R2006b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (22)
23 Aug 2005 Jose Flores  
23 Apr 2006 Udai Kiran

this the function i was looking for past few weeks

15 Jun 2006 shijun xiang

Thanks

24 Jul 2006 hou xiaobing

thank you very much

27 Nov 2006 ravi bakaraju

thank u

08 Feb 2007 Bijan Nemati

Very helpful, fast, and complete. Examples in the comments are very helpful too.

15 Aug 2007 smiled fisher  
29 Aug 2007 Dong Liu

Why this error? Thank you!

??? Error: File: E:\zernike\zernpol.m Line: 151 Column: 25
"identifier" expected, "(" found.

18 Nov 2007 Mike lu

very helpful!It will be perfect if include the zernike annular polynomials

10 Dec 2007 Alex Cht.

Valuable work, thank you.

23 Jan 2008 sadegh sadeghian  
23 Jan 2008 sadeq sadeghian  
05 Feb 2008 hua housheng  
22 Feb 2008 Ping Su  
30 Jan 2009 Michael Black

Looks promising but I'm having a problem duplicating the LASIK example...I copied the lasik image and edited out the the lasik portion -- but all I get from the following is a big red blob -- not a decent reconstructed image...anybody know what's wrong?
    image=imread('zk_fig2_w.jpg');
    figure(1);
    I=im2double(image);
    imagesc(image);
    % make grid coordinate matrices expressed in polar coordinates
    L = size(I,1);
    X = -1:2/(L-1):1;
    [x,y] = meshgrid(X);
    x=x(:);
    y=y(:);
    [theta,r] = cart2pol(x,y);
    % Compute the required degree and order values from n=0-7, inclusive
    N = [];
    M = [];
    for n=0:7
        N = [N n*ones(1,n+1)];
        M = [M -n:2:n];
    end
    is_in_circle = ( r <= 1);
    Z = zernfun(N,M,r(is_in_circle),theta(is_in_circle));
    a = Z\I(is_in_circle);
    % Reconstruct image using Zernike coefficients
    r=NaN(size(I));
    r(is_in_circle) = Z*a;
    % rescale to 0-255 to display image
    figure(2);
    r = im2uint8(im2double(r));
    imshow(r);

13 Nov 2009 Alex Kararg

I am interested in extracting the 3D Zernike descriptors of 3D shapes? Do you happen to know if there is any Matlab code?

22 Jan 2010 Jeff

Paul, Thanks very much for this code. It is very much appreciated.

I think, however, that you have a bug in how you are normalizing your Zernike polynomials. Noll's paper shows that for terms with m=0 the normalization term should be (n+1)**0.5 and for terms with m!=0 the normalization term should be (2*(n+1))**0.5. In the routine zernpol.m you are normalizing all terms (including those with m=0) by (2*(n+1))**0.5.

Perhaps you have already fixed this? I have just downloaded it on 1-21-10 from this site. The creation date for the file I'm looking at is on Nov 13, 2006 12:56:48 PM.

30 Mar 2010 Elia

I am still becoming accustomed to MATLAB. When I run the zernfun.m by itself without any modifications, I get this error

??? Input argument "n" is undefined.
Error in ==> zernfun at 88
if ( ~any(size(n)==1) ) || ( ~any(size(m)==1) ).

However, when I initialized n, m, r, & theta, I get this error

??? Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)
to change the limit. Be aware that exceeding your available stack space can
crash MATLAB and/or your computer.

Error in ==> meshgrid

Does anybody have any thoughts about making zernfun.m to work? Any help would be greatly appreciated.

30 Aug 2010 Bob

Very great functions! But the normalization with the 'norm' - option seems to be wrong. I've changed in:

zernfun.m

% For the normalized polynomials the line 177:
y(:,j) = y(:,j)*sqrt((1+(m(j)~=0))*(n(j)+1)/pi);

% I have to replaced by:
if m(j)==0
        y(:,j) = y(:,j)*sqrt((n(j)+1));
else
        y(:,j) = y(:,j)*sqrt(2*(n(j)+1));
end

10 Mar 2011 Chauncey Graetzel

I was running into problems when using my fitted terms in another program: the same coefficients did not give the same surface.
I found the cause: the cosine and sine terms are inverted in zernfun. M>0 should be a cosine, while M<0 should be a sine.

I've corrected this, starting at line 193

if any(idx_pos)
    z(:,idx_pos) = y(:,idx_pos).*cos(theta*m(idx_pos)');
end
if any(idx_neg)
    z(:,idx_neg) = y(:,idx_neg).*sin(theta*-m(idx_neg)');
end

% note the required sign change "-m" in the sine term

14 Nov 2011 Vic

Thanks for the code! I have a question about the unit of the zernike polynomials generated by this code, is it in [number of waves] or [micrometer]?

Thanks again!

14 Nov 2011 Shahab

Hi,

Does anybody know about the discrete Zernike Transform (DZT)?
I am so eager to implement that.

thank you in advance

Please login to add a comment or rating.
Updates
13 Nov 2006

Update to the algorithm for computing powers of R (vector of radius values).
Update to current MATLAB release.
Replaced code in ZERNFUN2 with a call to ZERNFUN.

11 Mar 2008

Need to point to a MATLAB Digest article which is based on this submission.

24 Oct 2011

Updated Help documentation and screenshot.

Tag Activity for this File
Tag Applied By Date/Time
chemistry Paul Fricker 22 Oct 2008 07:48:58
physics Paul Fricker 22 Oct 2008 07:48:58
zernike Paul Fricker 22 Oct 2008 07:48:58
circular domain Paul Fricker 22 Oct 2008 07:48:58
orthogonal basis Paul Fricker 22 Oct 2008 07:48:58
optics Paul Fricker 22 Oct 2008 07:48:58
orthogonal basis Student Matlab 21 Jan 2011 00:37:56

Contact us at files@mathworks.com