CHESSCORNERFILTER filters Harris corners for chessboard corners. CHESSCORNERFILTER takes as input the image, the sobel edge image and the Harris corner points and outputs of the corner points that passed the filter the number of those points and the peak directions for each of the points. The peak direction is used by the grid extraction (refer to Bachelor Thesis by Abdallah Kassir 2009). The details of the filter are applied in the function VALIDCORNER USAGE: [crnrs,nocrnrs,peaklocs]=chesscornerfilter(img,imgedge,crnrpts,debug) INPUTS: img: original grayscale image imgedge: Sobel edge image crnrpts: output of GETCRNRPTS OUTPUTS: crnrs: 2xN array of corners that passed the filter nocrnrs: number of corners found peaklocs: required by GETGRID
0001 function [crnrs,nocrnrs,peaklocs]=chesscornerfilter(img,imgedge,crnrpts,debug) 0002 % CHESSCORNERFILTER filters Harris corners for chessboard corners. 0003 % 0004 % CHESSCORNERFILTER takes as input the image, the sobel edge image and 0005 % the Harris corner points and outputs of the corner points that passed 0006 % the filter the number of those points and the peak directions for each 0007 % of the points. The peak direction is used by the grid extraction (refer 0008 % to Bachelor Thesis by Abdallah Kassir 2009). 0009 % 0010 % The details of the filter are applied in the function VALIDCORNER 0011 % 0012 % USAGE: 0013 % [crnrs,nocrnrs,peaklocs]=chesscornerfilter(img,imgedge,crnrpts,debug) 0014 % 0015 % INPUTS: 0016 % img: original grayscale image 0017 % 0018 % imgedge: Sobel edge image 0019 % 0020 % crnrpts: output of GETCRNRPTS 0021 % 0022 % OUTPUTS: 0023 % crnrs: 2xN array of corners that passed the filter 0024 % 0025 % nocrnrs: number of corners found 0026 % 0027 % peaklocs: required by GETGRID 0028 0029 if ~exist('debug','var') || isempty(debug) 0030 debug=0; 0031 end 0032 0033 % comment the line to allow debugging 0034 debug=0; 0035 0036 % get sweepmatrices, precalculation of these matrices allows for much 0037 % faster program execution 0038 [sweepmatx,sweepmaty]=sweepmatrix(img); 0039 0040 % set output values 0041 nocrnrs=0; 0042 crnrs=[]; 0043 peaklocs=[]; 0044 0045 i=0; 0046 0047 % loop over all points 0048 for indx=1:size(crnrpts,2) 0049 x=crnrpts(1,indx); 0050 y=crnrpts(2,indx); 0051 0052 % extract appropriate window size 0053 win=getwin(img,[x;y],crnrpts); 0054 0055 % check window size 0056 if win<3 0057 continue; 0058 end 0059 imgcrop=img(x-win:x+win,y-win:y+win); 0060 imgedgecrop=imgedge(x-win:x+win,y-win:y+win); 0061 sweepmatxcrop=sweepmatx(1:round(1.3*win),:); 0062 sweepmatycrop=sweepmaty(1:round(1.3*win),:); 0063 0064 % apply filter 0065 [valid,plocs]=validcorner(imgcrop,imgedgecrop,sweepmatxcrop,sweepmatycrop); 0066 if valid 0067 i=i+1; 0068 crnrs(1,i)=x; 0069 crnrs(2,i)=y; 0070 nocrnrs=nocrnrs+1; 0071 peaklocs(:,i)=plocs; 0072 % elseif x==129 0073 % close all; 0074 % imshow(imgcrop,[]); 0075 % keyboard; 0076 end 0077 end 0078 0079 % debugging 0080 if debug 0081 close all; 0082 figure;imshow(img);hold on; 0083 plot(crnrpts(2,:),crnrpts(1,:),'+'); 0084 plot(crnrs(2,:),crnrs(1,:),'o','color','red'); 0085 pause; 0086 end