0001 function [selclstrs,clstrs]=findlaserboardpoints(angleVector,rangeMatrix,laserDivisor,clstrs,tiest,riest,Nci,BoardCorners,thresholds,manselen,debug,manclstrs)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064 if ~exist('debug','var') || isempty(debug)
0065 debug=0;
0066 end
0067
0068 if ~exist('manclstrs','var') || isempty(manclstrs)
0069 getperf=0;
0070 else
0071 getperf=1;
0072 end
0073
0074 if ~exist('manselen','var') || isempty(manselen)
0075 manselen=0;
0076 end
0077
0078
0079 if isempty(tiest)
0080 iestflag=0;
0081 else
0082 iestflag=1;
0083 end
0084
0085
0086 if isfield(thresholds,'fthhi')
0087 checksus=1;
0088 else
0089 checksus=0;
0090 end
0091
0092
0093 fthlo=thresholds.fthlo;
0094 if checksus
0095 fthhi=thresholds.fthhi;
0096 end
0097
0098
0099 if iestflag
0100 iestthlo=thresholds.iestthlo;
0101 if checksus
0102 iestthhi=thresholds.iestthhi;
0103 end
0104 end
0105
0106 lenth=thresholds.lenth;
0107
0108
0109 noscans=size(rangeMatrix,1);
0110
0111
0112 fscores=getpecscores2(angleVector,rangeMatrix,laserDivisor);
0113 clstrfscores=getclstrscores(clstrs,fscores);
0114 clstrfscoresth=clstrfscores;
0115 clstrfscoresth(clstrfscoresth<fthlo)=0;
0116
0117
0118
0119
0120 vscans=~isnan(Nci(1,:))';
0121
0122 noccmask=zeros(size(rangeMatrix));
0123 noccmask(vscans,:)=1;
0124 noccmask=getclstrscores(clstrs,noccmask);
0125
0126 if iestflag
0127
0128
0129 initestdebug=0;
0130 if debug
0131 debin=input('Do you want to display the boards in the laser scans? (y/n,[]=n)','s');
0132 if debin=='y'
0133 initestdebug=1;
0134 end
0135 end
0136
0137
0138 iestscores=getinitestscore(tiest,riest,Nci,BoardCorners,angleVector,rangeMatrix,initestdebug);
0139 clstriestscores=getclstrscores(clstrs,iestscores);
0140 clstriestscoresth=clstriestscores;
0141 clstriestscoresth(clstriestscoresth<iestthlo)=0;
0142 else
0143 clstriestscores=noccmask;
0144 clstriestscoresth=clstriestscores;
0145 end
0146
0147
0148 lengths=getclstrlengths(angleVector,rangeMatrix,clstrs);
0149 clstrscoresi=clstrfscoresth.*clstriestscoresth;
0150
0151 [m,mi]=max(clstrscoresi.*logical(lengths),[],2);
0152 lind=sub2ind(size(lengths),(1:noscans)',mi);
0153 lind(m==0)=[];
0154 lenvec=lengths(lind);
0155
0156
0157 lenvec=sort(lenvec);
0158 np=0.99*length(lenvec);
0159 lenbar=interp1(lenvec,np);
0160
0161 lengthscores=1-abs(lengths-lenbar)./lenbar;
0162 lengthscores(lengthscores<0)=0;
0163
0164
0165 lengthscoresth=lengthscores;
0166 lengthscoresth(lengthscoresth<lenth)=0;
0167
0168
0169
0170 clstrscores=clstrfscoresth.*clstriestscoresth.*lengthscoresth;
0171 [maxscores,selclstrs]=max(clstrscores,[],2);
0172
0173
0174 sucscans=logical(maxscores);
0175 si=sub2ind(size(lengths),(1:noscans)',selclstrs);
0176 if checksus
0177 if iestflag
0178 susscans=(clstrfscores(si)<fthhi | clstriestscores(si)<iestthhi) & sucscans;
0179 else
0180 susscans=clstrfscores(si)<fthhi & sucscans;
0181 end
0182 end
0183 fscans=vscans&(~sucscans);
0184
0185
0186 if ~exist('riest','var') || isempty(riest)
0187 riest=angvec2dcm([0;0;0]);
0188 end
0189
0190 if checksus && ~isempty(find(susscans,1))
0191 disp('Please validate the selected board lines in the following scans:');
0192 for cntr=find(susscans')
0193 figure;
0194 img=GetImage(cntr);
0195 if ~isempty(img);
0196 subplot 121;
0197 end
0198 orientation=dcm2angvec(riest);
0199 orientation=orientation(3);
0200 dispclstrscore(angleVector+orientation,rangeMatrix(cntr,:),clstrs(cntr,:));
0201 title(['Scan: ',num2str(cntr)]);
0202 if ~isempty(img)
0203 subplot 122;
0204 imshow(img,[]);
0205 end
0206 fprintf('The automatically selected cluster is %d.',selclstrs(cntr));
0207 if isempty(img)
0208 fprintf('Image does not exist.');
0209 end
0210 fprintf('\n');
0211 mansel=input('If necessary, select a different one ([]=no change,0=none):');
0212 close;
0213 if ~isempty(mansel)
0214 selclstrs(cntr)=mansel;
0215 sucscans(cntr)=logical(mansel);
0216 end
0217 end
0218 end
0219
0220
0221 if ~isempty(find(fscans,1)) && manselen
0222 manselyn=input('\nWould you like to manually select the failed scans? (y/n,[]=n)','s');
0223 if manselyn=='y'
0224 f=figure;
0225 uisuspend(f);
0226 for cntr=find(fscans')
0227 fprintf('Select points from scan no %d.',cntr);
0228 img=GetImage(cntr);
0229 if ~isempty(img);
0230 maximize(f);
0231 subplot 122;
0232 imshow(img,[]);
0233 subplot 121;
0234 else
0235 fprintf('Image does not exist.');
0236 end
0237 fprintf('\n');
0238 orientation=dcm2angvec(riest);
0239 orientation=orientation(3);
0240 selind = SelectLaserPoints(angleVector+orientation,rangeMatrix(cntr,:));
0241 clf;
0242 if isempty(selind)
0243 continue;
0244 end
0245 if ~selind
0246 break;
0247 end
0248 clstrs(cntr,:)=selind+1;
0249 selclstrs(cntr)=2;
0250 sucscans(cntr)=1;
0251 end
0252 close(f);
0253 end
0254 end
0255
0256 selclstrs=selclstrs.*sucscans;
0257
0258
0259
0260
0261
0262 debugscans=1:noscans;
0263
0264 if getperf
0265 figure;
0266 manclstrscores=getclstrscores(clstrs,manclstrs);
0267
0268 manclstrscoresth=manclstrscores;
0269 manclstrscoresth(manclstrscoresth<1.5)=0;
0270 [benchscores,benchvec]=max(manclstrscoresth,[],2);
0271 benchvec=benchvec.*logical(benchscores);
0272 scannos=(1:noscans)';
0273 bind=sub2ind(size(manclstrscores),scannos(benchvec>0),benchvec(benchvec>0));
0274 manclstrscoresb=zeros(size(manclstrscores));
0275 manclstrscoresb(bind)=1;
0276 scatter3(clstrfscores(:),clstriestscores(:),lengthscores(:),20,manclstrscoresb(:),'filled');
0277 xlabel('Frequency');
0278 ylabel('InitEst');
0279 zlabel('Length');
0280 set(gcf,'renderer','opengl');
0281
0282 fprintf('\n');
0283 notruepos=nnz((benchvec==selclstrs).*vscans.*benchvec)
0284 notrueneg=nnz((benchvec==selclstrs).*vscans.*(~benchvec))
0285 falsepos=find((benchvec~=selclstrs).*vscans.*(~benchvec))
0286 falseneg=find((benchvec~=selclstrs).*vscans.*benchvec)
0287 noinvscans=nnz(~vscans)
0288 fprintf('\n');
0289 falsescans=find((benchvec~=selclstrs).*vscans);
0290 nofalsescans=nnz((benchvec~=selclstrs).*vscans)
0291 debugscans=falsescans';
0292 end
0293
0294 if debug
0295 if ~getperf
0296 debin=input('Do you want to display all scans? (y/n,[]=n)','s');
0297 else
0298 debin='y';
0299 end
0300 if debin=='y'
0301 figure;
0302 for cntr=debugscans
0303 clf;
0304 dispclstrscore(angleVector,rangeMatrix(cntr,:),clstrs(cntr,:));
0305 title(num2str(cntr));
0306 disp(['Selected cluster is ',num2str(selclstrs(cntr)),'.']);
0307 end
0308 end
0309 end