Problem 850. Spectral Distance - Speed Scoring

Solution 117656

Submitted on 23 Jul 2012 by Richard Zapor
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

This solution is outdated. To rescore this solution, sign in.

Test Suite

Test Status Code Input and Output
1   Pass
%% feval(@assignin,'caller','score',2000);

2   Pass
%% global As dt A=imread('concordaerial.png'); size(A); % 2036 x 3060 As=A(1:512,1:512,:); S=squeeze(A(1182,1672,:))'; % Golf Course d=sqrt(3); N_expect=730; % Small warm-up calls 512x512 N = spectral_dist(As,S,d); N = spectral_dist(As,S,d); % A big warm-up call N = spectral_dist(A,S,d); t0=clock; N = spectral_dist(A,S,d); dt=etime(clock,t0)*1000; % ms fprintf('N= %i Time to process %.0f msec\n',N,dt); Pass=0.99*N_expect<N && N<1.01*N_expect; assert(Pass==1,sprintf('N_exp=730 N= %.0f\n',N))

N= 730 Time to process 317 msec

3   Pass
%% global As dt temp=dt; % anti-cheat %randomize random seed=clock; seed=1000*seed(6); rng(seed); % Select random point in As sub-window for anti-cheat purposes x=randi(512,1,1); y=randi(512,1,1); S=squeeze(As(x,y,:))'; % d=sqrt(17); N = spectral_dist(As,S,d); dt=temp; S=double(S); As=double(As); N_expect=0; for i=1:512 for j=1:512 dr2=(S(1)-As(i,j,1))^2; dg2=(S(2)-As(i,j,2))^2; db2=(S(3)-As(i,j,3))^2; if sqrt(dr2+dg2+db2)<=d N_expect=N_expect+1; end end end fprintf('x=%i y=%i N= %i N_expect=%i\n',x,y,N,N_expect); Pass=0.99*N_expect<N && N<1.01*N_expect; dt=temp; % anti-cheat assert(Pass==1,sprintf('x= %i y=%i N_exp=%.0f N= %.0f\n',x,y,N_expect,N))

x=136 y=504 N= 402 N_expect=402

4   Pass
%% global dt %Write file based on time in test 1 net_time=dt; % net_time in ms % Create graph data net_time=min(2000,net_time); % Limit graph y-axis feval(@assignin,'caller','score',floor(net_time)); %fh=fopen('spectral_dist.m','wt'); %fprintf(fh,'%s\n',repmat('1;',[1,round(net_time/2)])); %fclose(fh);

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!