Cody

Problem 908. AVIRIS Inscribed Rectangle Bit Mask - Speed Test

Solution 127660

Submitted on 14 Aug 2012 by @bmtran
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)

``` dt = 1.9880 Time to process 2 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)

``` dt = 0.0940 Time to process 0 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)

``` dt = 0.3340 Time to process 0 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)

``` dt = 0.0680 Time to process 0 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)

```Elapsed time is 1.661951 seconds. Elapsed time is 2.750725 seconds. Time to process 4 msec idx=63497 x=5 y=34 rect_nr=1911 rect_nc=671 ```

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);

``` ```