Changeset 231 for trunk/src/pivlab.m
- Timestamp:
- Apr 5, 2011, 12:46:34 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/pivlab.m
r227 r231 19 19 % mask: =[] for no mask 20 20 % roi: 4 element vector defining a region of interest: x position, y position, width, height, (in image indices), for the whole image, roi=[]; 21 function [xtable ytable utable vtable ctable typevector ] = pivlab (image1,image2,ibx2,iby2,isx2,isy2,shiftx,shifty, PointCoord, subpixfinder,mask)21 function [xtable ytable utable vtable ctable typevector result_conv errormsg] = pivlab (image1,image2,ibx2,iby2,isx2,isy2,shiftx,shifty, GridIndices, subpixfinder,mask) 22 22 %this funtion performs the DCC PIV analysis. Recent window-deformation 23 23 %methods perform better and will maybe be implemented in the future. 24 errormsg=''; 24 25 warning off %MATLAB:log:logOfZero 25 % if numel(roi)>0 26 % xroi=roi(1); 27 % yroi=roi(2); 28 % widthroi=roi(3); 29 % heightroi=roi(4); 30 % image1_roi=double(image1(yroi:yroi+heightroi,xroi:xroi+widthroi)); 31 % image2_roi=double(image2(yroi:yroi+heightroi,xroi:xroi+widthroi)); 32 % else 26 [npy_ima npx_ima]=size(image1); 27 if ~isequal(size(image1),size(image2)) 28 errormsg='image pair with unequal size'; 29 return 30 end 33 31 xroi=0; 34 32 yroi=0; 35 33 image1_roi=double(image1); 36 34 image2_roi=double(image2); 37 % end38 35 if numel(mask)>0 39 36 cellmask=mask; 40 mask=zeros(size(image1 _roi));37 mask=zeros(size(image1)); 41 38 for i=1:size(cellmask,1); 42 39 masklayerx=cellmask{i,1}; 43 40 masklayery=cellmask{i,2}; 44 mask = mask + poly2mask(masklayerx-xroi,masklayery-yroi, size(image1_roi,1),size(image1_roi,2)); %kleineres eingangsbild und maske geshiftet41 mask = mask + poly2mask(masklayerx-xroi,masklayery-yroi,npy_ima,npx_ima); %kleineres eingangsbild und maske geshiftet 45 42 end 46 43 else 47 mask=zeros(size(image1 _roi));44 mask=zeros(size(image1)); 48 45 end 49 46 mask(mask>1)=1; 50 % ibx=2*ibx2-1%ibx and iby odd, reduced by 1 if even 51 % iby=2*iby2-1 47 48 % ibx=2*ibx2-1;%ibx and iby odd, reduced by 1 if even 49 % iby=2*iby2-1; 52 50 % miniy=1+iby2 53 51 % minix=1+ibx2 … … 77 75 image2_roi=padarray(image2_roi,[iby2 ibx2], min(min(image1_roi))); 78 76 mask=padarray(mask,[iby2 ibx2],0); 79 SubPixOffset=0.5;%odd values chosen for ibx and iby80 81 nbvec=size( PointCoord,1);77 %SubPixOffset=0.5;%odd values chosen for ibx and iby 78 79 nbvec=size(GridIndices,1); 82 80 xtable=zeros(nbvec,1); 83 81 ytable=xtable; … … 96 94 %% MAINLOOP 97 95 for ivec=1:nbvec 98 iref=PointCoord(ivec,1); 99 jref=PointCoord(ivec,2); 96 iref=GridIndices(ivec,1); 97 jref=GridIndices(ivec,2); 98 %jref=npy_ima-PointCoord(ivec,2)+1; 100 99 image1_crop=image1_roi(jref-iby2:jref+iby2,iref-ibx2:iref+ibx2); 101 100 image2_crop=image2_roi(jref+shifty-isy2:jref+shifty+isy2,iref+shiftx-isx2:iref+shiftx+isx2); 102 % n=round((j-miniy)/maxiy*100);103 % for i = minix:step:maxix % horizontal loop104 % nrx=nrx+1;%used to determine the pos of the vector in resulting matrix105 % if nrxreal < numelementsx106 % nrxreal=nrxreal+1;107 % else108 % nrxreal=1;109 % end110 % startpoint=[i j];111 % image1_crop=image1_roi(j:j+iby-1, i:i+ibx-1);112 % image2_crop=image2_roi(ceil(j-iby/2):ceil(j+1.5*iby-1), ceil(i-ibx/2):ceil(i+1.5*ibx-1));113 % corrmax=0;114 101 if mask(jref,iref)==0 115 102 %reference: Oliver Pust, PIV: Direct Cross-Correlation … … 121 108 corrmax= max(max(result_conv)); 122 109 result_conv=(result_conv/corrmax)*255; %normalize, peak=always 255 110 % result_conv=flipdim(result_conv,2);%reverse x direction 123 111 %Find the 255 peak 124 112 [y,x] = find(result_conv==255); … … 126 114 try 127 115 if subpixfinder==1 128 [vector] = SUBPIXGAUSS (result_conv, ibx,iby,x,y,SubPixOffset);116 [vector] = SUBPIXGAUSS (result_conv,x,y); 129 117 elseif subpixfinder==2 130 [vector] = SUBPIX2DGAUSS (result_conv, ibx,iby,x,y,SubPixOffset);118 [vector] = SUBPIX2DGAUSS (result_conv,x,y); 131 119 end 132 catch 133 vector=[NaN NaN]; %if something goes wrong with cross correlation..... 120 catch ME 121 errormsg=ME.message 122 vector=[0 0]; %if something goes wrong with cross correlation..... 134 123 end 135 124 else 136 vector=[ NaN NaN]; %if something goes wrong with cross correlation.....125 vector=[0 0]; %if something goes wrong with cross correlation..... 137 126 end 138 127 else %if mask was not 0 then 139 vector=[ NaN NaN];128 vector=[0 0]; 140 129 typevector(ivec)=0; 141 130 end 142 131 143 132 %Create the vector matrix x, y, u, v 144 xtable(ivec)= PointCoord(ivec,2);145 ytable(ivec)= PointCoord(ivec,1);133 xtable(ivec)=GridIndices(ivec,1); 134 ytable(ivec)=GridIndices(ivec,2); 146 135 utable(ivec)=vector(1); 147 136 vtable(ivec)=vector(2); 148 ctable(ivec)=corrmax/sum(sum(image1_crop.*image1_crop)); 149 end 150 % xtable=xtable-ibx2; 151 % ytable=ytable-iby2; 152 % 153 % xtable=xtable+xroi; 154 % ytable=ytable+yroi; 155 % 156 % utable(utable>ibx/1.5)=NaN; 157 % vtable(utable>ibx/1.5)=NaN; 158 % vtable(vtable>iby/1.5)=NaN; 159 % utable(vtable>iby/1.5)=NaN; 160 161 function [vector] = SUBPIXGAUSS (result_conv,ibx,iby,x,y,SubPixOffset) 137 sum_square=sum(sum(image1_crop.*image1_crop)); 138 ctable(ivec)=corrmax/sum_square; 139 end 140 result_conv=result_conv/255; 141 142 143 function [vector] = SUBPIXGAUSS (result_conv,x,y) 144 162 145 if size(x,1)>1 %if there are more than 1 peaks just take the first 163 146 x=x(1:1); … … 177 160 f2 = log(result_conv(y,x+1)); 178 161 peakx = x+ (f1-f2)/(2*f1-4*f0+2*f2); 179 % 180 SubpixelX=peakx-(ibx/2)-SubPixOffset; 181 SubpixelY=peaky-(iby/2)-SubPixOffset; 182 vector=[SubpixelX, SubpixelY]; 162 [npy,npx]=size(result_conv); 163 vector=[peakx-floor(npx/2)-1 peaky-floor(npy/2)-1]; 183 164 else 184 165 vector=[NaN NaN]; 185 166 end 186 167 187 function [vector] = SUBPIX2DGAUSS (result_conv, ibx,iby,x,y,SubPixOffset)168 function [vector] = SUBPIX2DGAUSS (result_conv,x,y) 188 169 if size(x,1)>1 %if there are more than 1 peaks just take the first 189 170 x=x(1:1); … … 213 194 c11=(1/4)*sum(sum(c11)); 214 195 c20=(1/6)*sum(sum(c20)); 215 c02=(1/6)*sum(sum(c02)); 216 %c00=(1/9)*sum(sum(c00)); 217 196 c02=(1/6)*sum(sum(c02)); 218 197 deltax=(c11*c01-2*c10*c02)/(4*c20*c02-c11^2); 219 198 deltay=(c11*c10-2*c01*c20)/(4*c20*c02-c11^2); 220 199 peakx=x+deltax; 221 200 peaky=y+deltay; 222 223 SubpixelX=peakx-(ibx/2)-SubPixOffset; 224 SubpixelY=peaky-(iby/2)-SubPixOffset; 225 vector=[SubpixelX, SubpixelY]; 201 202 [npy,npx]=size(result_conv); 203 vector=[peakx-floor(npx/2)-1 peaky-floor(npy/2)-1]; 204 % SubpixelX=peakx-(ibx/2)-SubPixOffset; 205 % SubpixelY=peaky-(iby/2)-SubPixOffset; 206 % vector=[SubpixelX, SubpixelY]; 226 207 else 227 208 vector=[NaN NaN];
Note: See TracChangeset
for help on using the changeset viewer.