Changeset 238 for trunk/src/pivlab.m
 Timestamp:
 Apr 18, 2011, 10:42:29 PM (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/pivlab.m
r236 r238 90 90 result_conv=(result_conv/corrmax)*255; %normalize, peak=always 255 91 91 %Find the correlation max, at 255 92 [y,x] = find(result_conv==255 );93 if ~isnan(y) & ~isnan(x)92 [y,x] = find(result_conv==255,1); 93 if ~isnan(y) && ~isnan(x) 94 94 try 95 95 if subpixfinder==1 96 [vector ] = SUBPIXGAUSS (result_conv,x,y);96 [vector,F(ivec)] = SUBPIXGAUSS (result_conv,x,y); 97 97 elseif subpixfinder==2 98 [vector ] = SUBPIX2DGAUSS (result_conv,x,y);98 [vector,F(ivec)] = SUBPIX2DGAUSS (result_conv,x,y); 99 99 end 100 100 sum_square=sum(sum(image1_crop.*image1_crop)); 101 101 ctable(ivec)=corrmax/sum_square;% correlation value 102 if vector(1)>shiftx+isx2ibx2+subpixfinder  vector(2)>shifty+isy2iby2+subpixfinder103 F(ivec)=2;%vector reaches the border of the search zone104 end102 % if vector(1)>shiftx+isx2ibx2+subpixfinder  vector(2)>shifty+isy2iby2+subpixfinder 103 % F(ivec)=2;%vector reaches the border of the search zone 104 % end 105 105 catch ME 106 106 vector=[0 0]; %if something goes wrong with cross correlation..... … … 125 125 126 126 127 function [vector] = SUBPIXGAUSS (result_conv,x,y) 127 function [vector,F] = SUBPIXGAUSS (result_conv,x,y) 128 vector=[0 0]; %default 129 F=0; 130 [npy,npx]=size(result_conv); 128 131 129 if size(x,1)>1 %if there are more than 1 peaks just take the first 130 x=x(1:1); 131 end 132 if size(y,1)>1 %if there are more than 1 peaks just take the first 133 y=y(1:1); 134 end 135 if (x <= (size(result_conv,1)1)) && (y <= (size(result_conv,1)1)) && (x >= 1) && (y >= 1) 132 % if (x <= (size(result_conv,1)1)) && (y <= (size(result_conv,1)1)) && (x >= 1) && (y >= 1) 136 133 %the following 8 lines are copyright (c) 1998, Uri Shavit, Roi Gurka, Alex Liberzon, Technion Israel Institute of Technology 137 134 %http://urapiv.wordpress.com 138 f0 = log(result_conv(y,x)); 139 f1 = log(result_conv(y1,x)); 140 f2 = log(result_conv(y+1,x)); 141 peaky = y+ (f1f2)/(2*f14*f0+2*f2); 142 f0 = log(result_conv(y,x)); 143 f1 = log(result_conv(y,x1)); 144 f2 = log(result_conv(y,x+1)); 145 peakx = x+ (f1f2)/(2*f14*f0+2*f2); 146 [npy,npx]=size(result_conv); 135 peaky = y; 136 if y <= npy1 && y >= 1 137 f0 = log(result_conv(y,x)); 138 f1 = log(result_conv(y1,x)); 139 f2 = log(result_conv(y+1,x)); 140 peaky = peaky+ (f1f2)/(2*f14*f0+2*f2); 141 else 142 F=2; % warning flag for vector truncated by the limited search box 143 end 144 peakx=x; 145 if x <= npx1 && x >= 1 146 f0 = log(result_conv(y,x)); 147 f1 = log(result_conv(y,x1)); 148 f2 = log(result_conv(y,x+1)); 149 peakx = peakx+ (f1f2)/(2*f14*f0+2*f2); 150 else 151 F=2; % warning flag for vector truncated by the limited search box 152 end 147 153 vector=[peakxfloor(npx/2)1 peakyfloor(npy/2)1]; 148 else149 vector=[NaN NaN];150 end154 % else 155 % vector=[NaN NaN]; 156 % end 151 157 152 function [vector ] = SUBPIX2DGAUSS (result_conv,x,y)153 if size(x,1)>1 %if there are more than 1 peaks just take the first154 x=x(1:1);155 end 156 if size(y,1)>1 %if there are more than 1 peaks just take the first 157 y=y(1:1);158 end 159 if (x <= (size(result_conv,1)1)) && (y <= (size(result_conv,1)1)) && (x >= 1) && (y >= 1) 158 function [vector,F] = SUBPIX2DGAUSS (result_conv,x,y) 159 vector=[0 0]; %default 160 F=2; 161 peaky=y; 162 peakx=x; 163 [npy,npx]=size(result_conv); 164 if (x <= npx1) && (y <= npy1) && (x >= 1) && (y >= 1) 165 F=0; 160 166 for i=1:1 161 167 for j=1:1 … … 181 187 deltax=(c11*c012*c10*c02)/(4*c20*c02c11^2); 182 188 deltay=(c11*c102*c01*c20)/(4*c20*c02c11^2); 183 peakx=x+deltax; 184 peaky=y+deltay; 185 186 [npy,npx]=size(result_conv); 187 vector=[peakxfloor(npx/2)1 peakyfloor(npy/2)1]; 188 % SubpixelX=peakx(ibx/2)SubPixOffset; 189 % SubpixelY=peaky(iby/2)SubPixOffset; 190 % vector=[SubpixelX, SubpixelY]; 191 else 192 vector=[NaN NaN]; 189 if abs(deltax)<1 190 peakx=x+deltax; 191 end 192 if abs(deltay)<1 193 peaky=y+deltay; 194 end 193 195 end 196 vector=[peakxfloor(npx/2)1 peakyfloor(npy/2)1];
Note: See TracChangeset
for help on using the changeset viewer.