Cody

Problem 908. AVIRIS Inscribed Rectangle Bit Mask - Speed Test

Solution 341638

Submitted on 29 Oct 2013 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
global dt dt=0; m=ones(5); m(7)=0; t0=clock; [idxtlc rmnr rmnc]=rect_mask(m); dt=etime(clock,t0)*1000; % ms dt [x y]=ind2sub(size(m),idxtlc); pass=~any(any(m(x:x+rmnr-1,y:y+rmnc-1)==0)); assert(rmnr*rmnc>=15,sprintf('Expected 15 pixels, only have %i\n',rmnr*rmnc)) assert(isequal(pass,1),sprintf('Not all non-zero [%i,%i] [%i,%i]\n',x,y,x+rmnr-1,y+rmnc-1)) fprintf('Time to process %.0f msec\n',dt); fprintf('idx=%i x=%i y=%i rect_nr=%i rect_nc=%i\n',idxtlc,x,y,rmnr,rmnc)

mm2 = 1 2 3 4 5 2 5 7 9 3 5 8 11 14 4 7 11 15 19 5 9 14 19 24 mvmax = 5 mvmax = 15 dt = 12.6030 Time to process 13 msec idx=3 x=3 y=1 rect_nr=3 rect_nc=5

2   Pass
%% m=ones(5); m(7)=0; m(11)=0; t0=clock; [idxtlc rmnr rmnc]=rect_mask(m); dt=etime(clock,t0)*1000; % ms dt [x y]=ind2sub(size(m),idxtlc); pass=~any(any(m(x:x+rmnr-1,y:y+rmnc-1)==0)); assert(rmnr*rmnc>=15,sprintf('Expected 15 pixels, only have %i\n',rmnr*rmnc)) assert(isequal(pass,1),sprintf('Not all non-zero [%i,%i] [%i,%i]\n',x,y,x+rmnr-1,y+rmnc-1)) fprintf('Time to process %.0f msec\n',dt); fprintf('idx=%i x=%i y=%i rect_nr=%i rect_nc=%i\n',idxtlc,x,y,rmnr,rmnc)

mm2 = 1 2 3 4 5 2 5 7 9 4 7 10 13 3 6 10 14 18 4 8 13 18 23 mvmax = 5 mvmax = 15 dt = 6.9850 Time to process 7 msec idx=3 x=3 y=1 rect_nr=3 rect_nc=5

3   Pass
%% m=zeros(6);m(15)=1; t0=clock; [idxtlc rmnr rmnc]=rect_mask(m); dt=etime(clock,t0)*1000; % ms dt [x y]=ind2sub(size(m),idxtlc); pass=~any(any(m(x:x+rmnr-1,y:y+rmnc-1)==0)); assert(rmnr*rmnc>=1,sprintf('Expected 1 pixel, only have %i\n',rmnr*rmnc)) assert(isequal(pass,1),sprintf('Not all non-zero [%i,%i] [%i,%i]\n',x,y,x+rmnr-1,y+rmnc-1)) fprintf('Time to process %.0f msec\n',dt); fprintf('idx=%i x=%i y=%i rect_nr=%i rect_nc=%i\n',idxtlc,x,y,rmnr,rmnc)

mm2 = 1 mvmax = 1 dt = 6.2230 Time to process 6 msec idx=15 x=3 y=3 rect_nr=1 rect_nc=1

4   Pass
%% m=ones(8); m(2,:)=0; m(7,:)=0; m(4,2)=0; m(5,7)=0; t0=clock; [idxtlc rmnr rmnc]=rect_mask(m); dt=etime(clock,t0)*1000; % ms dt [x y]=ind2sub(size(m),idxtlc); pass=~any(any(m(x:x+rmnr-1,y:y+rmnc-1)==0)); assert(rmnr*rmnc>=16,sprintf('Expected 16 pixels, only have %i\n',rmnr*rmnc)) assert(isequal(pass,1),sprintf('Not all non-zero [%i,%i] [%i,%i]\n',x,y,x+rmnr-1,y+rmnc-1)) fprintf('Time to process %.0f msec\n',dt); fprintf('idx=%i x=%i y=%i rect_nr=%i rect_nc=%i\n',idxtlc,x,y,rmnr,rmnc)

mm2 = 1 2 3 4 5 6 2 4 7 9 11 3 6 8 11 14 17 4 8 11 15 19 23 5 10 14 19 24 29 6 12 17 23 29 35 7 14 20 33 40 8 16 23 30 38 46 mvmax = 8 mvmax = 12 mvmax = 16 dt = 7.1250 Time to process 7 msec idx=19 x=3 y=3 rect_nr=4 rect_nc=4

5   Pass
%% % Load aviris file Layer 1 ; 1.8MB mat file global dt tic % approx 2.5 sec to write and load urlwrite('http://tinyurl.com/matlab-avmofL001','aviris_moffett_L001.mat'); toc load('aviris_moffett_L001.mat'); toc % Array variable is L001 %Files also posted are L010,L023,L157, and L158 with same tinyurl format % L010 and L023 have high contrast L157 and L158 are in atmospheric notch % Time Trial File 1924 x 753 t0=clock; [idxtlc rmnr rmnc]=rect_mask(L001); dt=etime(clock,t0)*1000; % ms [x y]=ind2sub(size(L001),idxtlc); pass=~any(any(L001(x:x+rmnr-1,y:y+rmnc-1)==0)); assert(rmnr*rmnc>=1282281,sprintf('Expected 1282281 pixels, only have %i\n',rmnr*rmnc)) assert(isequal(pass,1),sprintf('Not all non-zero [%i,%i] [%i,%i]\n',x,y,x+rmnr-1,y+rmnc-1)) fprintf('Time to process %.0f msec\n',dt); fprintf('idx=%i x=%i y=%i rect_nr=%i rect_nc=%i\n',idxtlc,x,y,rmnr,rmnc)

[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In urlwrite at 1 In verifyCode>evaluateCode at 231 In verifyCode at 40 In fevalJSON at 14] Elapsed time is 0.011223 seconds. [Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In verifyCode>evaluateCode at 231 In verifyCode at 40 In fevalJSON at 14] Elapsed time is 0.026698 seconds. [Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In rect_mask at 4 In verifyCode>evaluateCode at 231 In verifyCode at 40 In fevalJSON at 14] mm2 = 1 mvmax = 1 [Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In assert at 1 In verifyCode>evaluateCode at 231 In verifyCode at 40 In fevalJSON at 14] ans = 0 [Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In assert at 1 In verifyCode>evaluateCode at 231 In verifyCode at 40 In fevalJSON at 14] ans = 0 Time to process 10 msec idx=1 x=1 y=1 rect_nr=1 rect_nc=1

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

Suggested Problems

More from this Author241

Community Treasure Hunt

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

Start Hunting!