Cody

Problem 1000. Image Processing 004: Zernike Coefficients

Solution 3007675

Submitted on 29 Sep 2020 by Alfonso Nieto-Castanon
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.025954 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.7178 -0.9610 -0.0011 0.0000 -0.0007 -0.4594 -0.0018 0.0016 0.6786 -0.0018 Elapsed time is 0.028689 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.1839 0.0023 -0.0044 0.0019 0.0048 0.0000 0.7010 0.0032 0.7298 0.1528 -0.2638 -0.6991 -0.7450 0.0000 0.0047 Elapsed time is 0.014130 seconds.