0001 function gridout=filtergrid(grid)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 gridout=grid;
0014 while 1
0015 row1count=0;
0016 row2count=0;
0017 col1count=0;
0018 col2count=0;
0019
0020 rowthresh=size(gridout,1)/2;
0021 colthresh=size(gridout,2)/2;
0022
0023 for y=1:size(gridout,2)
0024 if gridout(1,y)
0025 row1count=row1count+1;
0026 end
0027 if gridout(end,y)
0028 row2count=row2count+1;
0029 end
0030 end
0031 for x=1:size(gridout,1)
0032 if gridout(x,1)
0033 col1count=col1count+1;
0034 end
0035 if gridout(x,end)
0036 col2count=col2count+1;
0037 end
0038 end
0039
0040 row1count=row1count-rowthresh;
0041 row2count=row2count-rowthresh;
0042 col1count=col1count-colthresh;
0043 col2count=col2count-colthresh;
0044
0045
0046 [mincount,indx]=min([row1count,row2count,col1count,col2count]);
0047 if mincount<0
0048 switch indx
0049 case 1
0050 gridout(1,:,:)=[];
0051 case 2
0052 gridout(end,:,:)=[];
0053 case 3
0054 gridout(:,1,:)=[];
0055 case 4
0056 gridout(:,end,:)=[];
0057 end
0058 else
0059 break;
0060 end
0061 end