Changeset 238 for trunk/src/pivlab.m


Ignore:
Timestamp:
Apr 18, 2011, 10:42:29 PM (13 years ago)
Author:
sommeria
Message:

various bug corrections

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/pivlab.m

    r236 r238  
    9090        result_conv=(result_conv/corrmax)*255; %normalize, peak=always 255
    9191        %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)
    9494            try
    9595                if subpixfinder==1
    96                     [vector] = SUBPIXGAUSS (result_conv,x,y);
     96                    [vector,F(ivec)] = SUBPIXGAUSS (result_conv,x,y);
    9797                elseif subpixfinder==2
    98                     [vector] = SUBPIX2DGAUSS (result_conv,x,y);
     98                    [vector,F(ivec)] = SUBPIX2DGAUSS (result_conv,x,y);
    9999                end
    100100                sum_square=sum(sum(image1_crop.*image1_crop));
    101101                ctable(ivec)=corrmax/sum_square;% correlation value
    102                 if vector(1)>shiftx+isx2-ibx2+subpixfinder || vector(2)>shifty+isy2-iby2+subpixfinder
    103                     F(ivec)=-2;%vector reaches the border of the search zone
    104                 end
     102%                 if vector(1)>shiftx+isx2-ibx2+subpixfinder || vector(2)>shifty+isy2-iby2+subpixfinder
     103%                     F(ivec)=-2;%vector reaches the border of the search zone
     104%                 end
    105105            catch ME
    106106                vector=[0 0]; %if something goes wrong with cross correlation.....
     
    125125
    126126
    127 function [vector] = SUBPIXGAUSS (result_conv,x,y)
     127function [vector,F] = SUBPIXGAUSS (result_conv,x,y)
     128vector=[0 0]; %default
     129F=0;
     130[npy,npx]=size(result_conv);
    128131
    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)
    136133    %the following 8 lines are copyright (c) 1998, Uri Shavit, Roi Gurka, Alex Liberzon, Technion – Israel Institute of Technology
    137134    %http://urapiv.wordpress.com
    138     f0 = log(result_conv(y,x));
    139     f1 = log(result_conv(y-1,x));
    140     f2 = log(result_conv(y+1,x));
    141     peaky = y+ (f1-f2)/(2*f1-4*f0+2*f2);
    142     f0 = log(result_conv(y,x));
    143     f1 = log(result_conv(y,x-1));
    144     f2 = log(result_conv(y,x+1));
    145     peakx = x+ (f1-f2)/(2*f1-4*f0+2*f2);
    146     [npy,npx]=size(result_conv);
     135    peaky = y;
     136    if y <= npy-1 && y >= 1
     137        f0 = log(result_conv(y,x));
     138        f1 = log(result_conv(y-1,x));
     139        f2 = log(result_conv(y+1,x));
     140        peaky = peaky+ (f1-f2)/(2*f1-4*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 <= npx-1 && x >= 1
     146        f0 = log(result_conv(y,x));
     147        f1 = log(result_conv(y,x-1));
     148        f2 = log(result_conv(y,x+1));
     149        peakx = peakx+ (f1-f2)/(2*f1-4*f0+2*f2);
     150    else
     151        F=-2; % warning flag for vector truncated by the limited search box
     152    end
    147153    vector=[peakx-floor(npx/2)-1 peaky-floor(npy/2)-1];
    148 else
    149     vector=[NaN NaN];
    150 end
     154% else
     155%     vector=[NaN NaN];
     156% end
    151157
    152 function [vector] = SUBPIX2DGAUSS (result_conv,x,y)
    153 if size(x,1)>1 %if there are more than 1 peaks just take the first
    154     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)
     158function [vector,F] = SUBPIX2DGAUSS (result_conv,x,y)
     159vector=[0 0]; %default
     160F=-2;
     161peaky=y;
     162peakx=x;
     163[npy,npx]=size(result_conv);
     164if (x <= npx-1) && (y <= npy-1) && (x >= 1) && (y >= 1)
     165    F=0;
    160166    for i=-1:1
    161167        for j=-1:1
     
    181187    deltax=(c11*c01-2*c10*c02)/(4*c20*c02-c11^2);
    182188    deltay=(c11*c10-2*c01*c20)/(4*c20*c02-c11^2);
    183     peakx=x+deltax;
    184     peaky=y+deltay;
    185    
    186     [npy,npx]=size(result_conv);
    187     vector=[peakx-floor(npx/2)-1 peaky-floor(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
    193195end
     196vector=[peakx-floor(npx/2)-1 peaky-floor(npy/2)-1];
Note: See TracChangeset for help on using the changeset viewer.