Cody

Problem 1000. Image Processing 004: Zernike Coefficients

Solution 3007681

Submitted on 29 Sep 2020 by Alfonso Nieto-Castanon
  • Size: 45
  • This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
M=zeros(256); terms=6; % Number of Terms to fit 0:terms-1 % Test Suite portion using zern_data_v01 [ ydim xdim ] = size(M); x = linspace(-1,1,xdim); y = linspace(1,-1,ydim); [X Y] = meshgrid(x,y); R = sqrt(X.^2 + Y.^2); T = atan2(Y,X); % Create surface z_fit=zeros(terms,1); % Map 0:9 to 1:10 z_fit(2)=1.0; % Build a Surface M = M + zern_data_v01(0,R,T); % Force NaN for non-data M(M==0)=NaN; M(M>0)=0; for term = 0:terms-1 M = M + z_fit(term+1) * zern_data_v01(term,R,T); % figure(3);imagesc(data_fit) % Visualization % pause (0.5) end % Data is a circle % Non-data is assigned NaN tic v = Zernike_Fit(M,terms,R,T) toc assert(max(abs(v-z_fit))<0.01,sprintf('v=%i %i %i %i %i %i',v))

v = 0.0000 1.0000 0.0000 0.0000 0.0000 -0.0000 Elapsed time is 0.052872 seconds.

2   Pass
M=zeros(256); terms=10; % Number of Terms to fit 0:terms-1 % Test Suite portion using zern_data_v01 [ ydim xdim ] = size(M); x = linspace(-1,1,xdim); y = linspace(1,-1,ydim); [X Y] = meshgrid(x,y); R = sqrt(X.^2 + Y.^2); T = atan2(Y,X); % Create surface z_fit= round(2*rand(terms,1)-1).*rand(terms,1); % Build a Surface M = M + zern_data_v01(0,R,T); % Force NaN for non-data M(M==0)=NaN; M(M>0)=0; for term = 0:terms-1 M = M + z_fit(term+1) * zern_data_v01(term,R,T); % figure(3);imagesc(data_fit) % Visualization % pause (0.5) end tic v = Zernike_Fit(M,terms,R,T) toc assert(max(abs(v-z_fit))<0.01)

v = -0.7444 0.4462 -0.0000 -0.3481 0.0000 0.5083 0.0000 0.5968 0.0000 -0.0000 Elapsed time is 0.040156 seconds.

3   Pass
M=zeros(128); terms=15; % Number of Terms to fit 0:terms-1 % Test Suite portion using zern_data_v01 [ ydim xdim ] = size(M); x = linspace(-1,1,xdim); y = linspace(1,-1,ydim); [X Y] = meshgrid(x,y); R = sqrt(X.^2 + Y.^2); T = atan2(Y,X); % Create surface z_fit= round(2*rand(terms,1)-1).*rand(terms,1); % Build a Surface M = M + zern_data_v01(0,R,T); % Force NaN for non-data M(M==0)=NaN; M(M>0)=0; for term = 0:terms-1 M = M + z_fit(term+1) * zern_data_v01(term,R,T); % figure(3);imagesc(data_fit) % Visualization % pause (0.5) end tic v = Zernike_Fit(M,terms,R,T) toc assert(max(abs(v-z_fit))<0.01)

v = 0.0000 0.5249 0.5569 -0.0000 0.9407 -0.0000 -0.7473 -0.8909 0.0000 0.8011 -0.0000 -0.3932 -0.0000 0.0000 0.0000 Elapsed time is 0.018922 seconds.

Suggested Problems

More from this Author246

Community Treasure Hunt

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

Start Hunting!