getmisscrnrs

PURPOSE ^

GETMISSCRNRS fills in the gaps in the grid by linear interpolation.

SYNOPSIS ^

function [gridout,nointerpolations]=getmisscrnrs(grid,debug)

DESCRIPTION ^

 GETMISSCRNRS fills in the gaps in the grid by linear interpolation.
 
 GETMISSCRNRS successively inerpolates missing points by fitting a least
 square line of the row and column the missing point belongs to and then
 storing the point as the intersection of the two lines.
 
 USAGE:
     [gridout,nointerpolations]=getmisscrnrs(grid);
 
 INPUTS:
     grid: output of FILTERGRID
 
 OUTPUTS:
     gridout: grid with the missing corners interpolated
 
     nointerpolations: the number of interpolations is used to detect the
     quality of the chessboard detection by FINDCORNERS

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [gridout,nointerpolations]=getmisscrnrs(grid,debug)
0002 % GETMISSCRNRS fills in the gaps in the grid by linear interpolation.
0003 %
0004 % GETMISSCRNRS successively inerpolates missing points by fitting a least
0005 % square line of the row and column the missing point belongs to and then
0006 % storing the point as the intersection of the two lines.
0007 %
0008 % USAGE:
0009 %     [gridout,nointerpolations]=getmisscrnrs(grid);
0010 %
0011 % INPUTS:
0012 %     grid: output of FILTERGRID
0013 %
0014 % OUTPUTS:
0015 %     gridout: grid with the missing corners interpolated
0016 %
0017 %     nointerpolations: the number of interpolations is used to detect the
0018 %     quality of the chessboard detection by FINDCORNERS
0019 
0020 %Function that interpolates the positions of missing corners
0021 if ~exist('debug','var') || isempty(debug)
0022     debug=0;
0023 end
0024 
0025 % comment the line to allow debugging
0026 debug=0;
0027 
0028 gridout=grid;
0029 nointerpolations=0;
0030 
0031 for x=1:size(gridout,1)
0032     for y=1:size(gridout,2)
0033         if gridout(x,y,1)==0
0034             nzerrowx=gridout(x,:,1);
0035             nzerrowx=nzerrowx(nzerrowx>0);
0036             nzerrowy=gridout(x,:,2);
0037             nzerrowy=nzerrowy(nzerrowy>0);
0038             nzercolx=gridout(:,y,1);
0039             nzercolx=nzercolx(nzercolx>0);
0040             nzercoly=gridout(:,y,2);
0041             nzercoly=nzercoly(nzercoly>0);
0042             if length(nzerrowx)<2 || length(nzercolx)<2
0043                 % cannot process grid
0044                 gridout=[];
0045                 return;
0046             end
0047             nointerpolations=nointerpolations+1;
0048             P1=polyfit(nzerrowy,nzerrowx,1);
0049             P2=polyfit(nzercolx,nzercoly,1);
0050             eqnsmat=[1,-P1(1);-P2(1),1];
0051             bmat=[P1(2);P2(2)];
0052             gridout(x,y,:)=eqnsmat\bmat;
0053             if debug
0054                 close all;
0055                 figure;
0056                 hold on;
0057                 plot(nzerrowy,polyval(P1,nzerrowy));
0058                 plot(polyval(P2,nzercolx),nzercolx);
0059                 plot(gridout(:,:,2),gridout(:,:,1),'+');
0060             end
0061         end
0062     end
0063 end

Generated on Sun 04-Apr-2010 17:13:59 by m2html © 2005