VALIDCORNER checks if the input corner belongs to a chessboard. VALIDCORNER is used to indicate if a corner is a chessboard corner. It takes as input the cropped image and cropped edge image around the corner. To ensure fast program execution sweepmatx and sweepmaty have been used. They are necessary input to this function. USAGE: [valid,peaklocs]=validcorner(img,imgedge,sweepmatx,sweepmaty); INPUTS: img: cropped grayscale image imgedge: cropped Sobel edge image sweepmatx: cropped sweepmatrix x, this is used for fast radial summation sweepmatx: cropped sweepmatrix y, this is used for fast radial summation OUTPUTS valid: scalar indicating wether the point is a chessboard corner of not, 1: yes, 0: no peaklocs: required by GETGRID
0001 function [valid,peaklocs]=validcorner(img,imgedge,sweepmatx,sweepmaty,debug) 0002 % VALIDCORNER checks if the input corner belongs to a chessboard. 0003 % 0004 % VALIDCORNER is used to indicate if a corner is a chessboard corner. It 0005 % takes as input the cropped image and cropped edge image around the 0006 % corner. To ensure fast program execution sweepmatx and sweepmaty have 0007 % been used. They are necessary input to this function. 0008 % 0009 % USAGE: 0010 % [valid,peaklocs]=validcorner(img,imgedge,sweepmatx,sweepmaty); 0011 % 0012 % INPUTS: 0013 % img: cropped grayscale image 0014 % 0015 % imgedge: cropped Sobel edge image 0016 % 0017 % sweepmatx: cropped sweepmatrix x, this is used for fast radial summation 0018 % 0019 % sweepmatx: cropped sweepmatrix y, this is used for fast radial summation 0020 % 0021 % 0022 % OUTPUTS 0023 % valid: scalar indicating wether the point is a chessboard corner of not, 1: yes, 0: no 0024 % 0025 % peaklocs: required by GETGRID 0026 0027 % validcorner parameters 0028 imadjsca=0.8; % larger adjust scalars corresponds to less adjustment 0029 imeadjsca=1.8; 0030 intth=0.5; 0031 0032 0033 if ~exist('debug','var') || isempty(debug) 0034 debug=0; 0035 end 0036 0037 peaklocs=[]; 0038 0039 if debug 0040 close all; 0041 end 0042 0043 %Adjust windowed image 0044 imgedge=adjimg(imgedge,imeadjsca); %edge images need less adjustment than imgn 0045 0046 if debug 0047 figure;imshow(imgedge); 0048 end 0049 0050 [theta,edgevalue,thetasmd,edgevaluesmd]=circsweep(imgedge,sweepmatx,sweepmaty); 0051 0052 0053 0054 maxtab=peakdet(edgevalue); 0055 0056 0057 if size(maxtab,1)~=4 %Check if peaks equal 4 0058 valid=0; 0059 return; 0060 end 0061 0062 peaklocs=maxtab(:,1); 0063 0064 maxtabsmd=peakdet(edgevaluesmd); 0065 if size(maxtabsmd,1)~=2 %Check if peaks equal 2 0066 valid=0; 0067 return; 0068 end 0069 0070 0071 img=adjimg(img,imadjsca); 0072 [theta,intvalue,thetasmd,intvaluesmd]=circsweep(img,sweepmatx,sweepmaty); 0073 % intth=(max(intvaluesmd)-min(intvaluesmd))/2; 0074 0075 %Work with summed arrays 0076 peaks=maxtabsmd(:,2); 0077 locs=maxtabsmd(:,1); 0078 0079 0080 peaks=peaks'; 0081 locs=locs'; 0082 0083 % sort peak locations 0084 locs=sort(locs); 0085 0086 0087 crn1=mean(intvaluesmd([1:locs(1),locs(2):length(intvaluesmd)])); 0088 crn2=mean(intvaluesmd(locs(1):locs(2))); 0089 0090 0091 %Check if squares have enough intensity difference 0092 if abs(crn1-crn2)>intth 0093 valid=1; 0094 else 0095 valid=0; 0096 end