Changeset 1163
- Timestamp:
- Jul 25, 2024, 8:36:17 PM (5 months ago)
- Location:
- trunk/src
- Files:
-
- 3 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/filter_tps.m
r1161 r1163 93 93 ind_sel= find(~FF & Coord(:,1)>=SubRange(1,1,isub) & Coord(:,1)<=SubRange(1,2,isub) & Coord(:,2)>=SubRange(2,1,isub) & Coord(:,2)<=SubRange(2,2,isub));% indices of vectors in the subdomain #isub 94 94 check_partial_domain=sum(SubRange(:,1,isub)> MinCoord' | SubRange(:,2,isub)< MaxCoord'); 95 % isub96 % numel(ind_sel)97 95 98 96 % if no vector in the subdomain #isub, skip the subdomain -
trunk/src/filter_tps_3D.m
r1162 r1163 66 66 CentreX=reshape(CentreX,1,[]);% X positions of subdomain centres 67 67 CentreY=reshape(CentreY,1,[]);% Y positions of subdomain centres 68 CentreZ=reshape(CentreZ,1,[]);% Ypositions of subdomain centres68 CentreZ=reshape(CentreZ,1,[]);% Z positions of subdomain centres 69 69 70 70 %% smoothing parameter: CHANGED 03 May 2024 TO GET RESULTS INDEPENDENT OF SUBDOMAINSIZE … … 92 92 SubRange(1,:,isub)=[CentreX(isub)-0.55*Siz(1) CentreX(isub)+0.55*Siz(1)];%bounds of subdomain #isub in x coordinate 93 93 SubRange(2,:,isub)=[CentreY(isub)-0.55*Siz(2) CentreY(isub)+0.55*Siz(2)];%bounds of subdomain #isub in y coordinate 94 SubRange(3,:,isub)=[CentreZ(isub)-0.55*Siz(3) CentreZ(isub)+0.55*Siz(3)];%bounds of subdomain #isub in y coordinate 94 95 ind_sel=0;%initialize set of vector indices in the subdomain 95 96 %increase iteratively the subdomain if it contains less than -
trunk/src/mouse_motion.m
r1158 r1163 265 265 ibx2=floor((par_civ.CorrBoxSize(1)-1)/2); 266 266 iby2=floor((par_civ.CorrBoxSize(2)-1)/2); 267 isx2= floor((par_civ.SearchBoxSize(1)-1)/2);268 isy2= floor((par_civ.SearchBoxSize(2)-1)/2);267 isx2=par_civ.SearchRange(1); 268 isy2=par_civ.SearchRange(2); 269 269 hhh=findobj(CurrentAxes,'Tag','PIV_box_marker'); 270 270 hhhh=findobj(CurrentAxes,'Tag','PIV_search_marker'); -
trunk/src/series/civ_3D.m
r1161 r1163 190 190 Data.VarAttribute{7}.Role='ancillary'; 191 191 Data.VarAttribute{8}.Role='errorflag'; 192 Data.Coord_z=j1_series_Civ1;192 % Data.Coord_z=j1_series_Civ1; 193 193 % path for output nc file 194 194 OutputPath=fullfile(Param.OutputPath,num2str(Param.Experiment),num2str(Param.Device),[Param.OutputSubDir Param.OutputDirExt]); … … 230 230 par_civ1.ImageHeight=FileInfo.Height;npy=FileInfo.Height; 231 231 par_civ1.ImageWidth=FileInfo.Width;npx=FileInfo.Width; 232 SearchRange_z= floor(Param.ActionInput.Civ1.SearchBoxSize(3)/2);232 SearchRange_z=Param.ActionInput.Civ1.SearchRange(3); 233 233 par_civ1.Dz=Param.ActionInput.Civ1.Dz; 234 234 par_civ1.ImageA=zeros(2*SearchRange_z+1,npy,npx); … … 296 296 par_civ1.ImageA=zeros(2*SearchRange_z+1,npy,npx);%image block initiation 297 297 par_civ1.ImageB=zeros(2*SearchRange_z+1,npy,npx); 298 298 Data.Coord_z=SearchRange_z+1:par_civ1.Dz:NbSlice-1; 299 299 z_index=1;%first vertical block centered at image index z_index=SearchRange_z+1 300 300 for iz=1:2*SearchRange_z+1 … … 315 315 end 316 316 % loop on slices 317 317 318 for z_index=2:floor((NbSlice-SearchRange_z)/par_civ1.Dz)% loop on slices 318 319 par_civ1.ImageA=circshift(par_civ1.ImageA,-par_civ1.Dz,1);%shift the indices in the image block upward by par_civ1.Dz 319 320 par_civ1.ImageB=circshift(par_civ1.ImageB,-par_civ1.Dz,1); 320 321 for iz=1:par_civ1.Dz %read the new images at the end of the image block 322 image_index=z_index*par_civ1.Dz+SearchRange_z-par_civ1.Dz+iz+1; 323 if image_index<=size(j1_series_Civ1,1) 321 324 j_image_index=j1_series_Civ1(z_index*par_civ1.Dz+SearchRange_z-par_civ1.Dz+iz+1,1) 322 ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(1,ifield),[],j_image_index);% 325 ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(1,ifield),[],j_image_index);% 323 326 A= read_image(ImageName_A,FileType_A); 324 327 ImageName_B=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_series_Civ1(1,ifield),[],j_image_index); 325 328 B= read_image(ImageName_B,FileType_B); 329 else 330 A=zeros(1,size(par_civ1.ImageA,2),size(par_civ1.ImageA,3)); 331 B=zeros(1,size(par_civ1.ImageA,2),size(par_civ1.ImageA,3)); 332 end 326 333 par_civ1.ImageA(2*SearchRange_z+1-par_civ1.Dz+iz,:,:) = A; 327 334 par_civ1.ImageB(2*SearchRange_z+1-par_civ1.Dz+iz,:,:) = B; … … 338 345 Data.Civ1_Y=npy-Data.Civ1_Y+1;%reverse y 339 346 [npz,npy,npx]=size(Data.Civ1_X); 340 Data.Coord_z=SearchRange_z+1:par_civ1.Dz:NbSlice-1;347 341 348 % Data.Coord_y=flip(1:npy); 342 349 % Data.Coord_x=1:npx; … … 422 429 % list the variables to record 423 430 nbvar=length(Data.ListVarName); 424 Data.ListVarName=[Data.ListVarName {'Civ1_U_smooth','Civ1_V_smooth','Civ1_SubRange','Civ1_NbCentres','Civ1_Coord_tps','Civ1_U_tps','Civ1_V_tps'}]; 425 Data.VarDimName=[Data.VarDimName {'nb_vec_1','nb_vec_1',{'nb_coord','nb_bounds','nb_subdomain_1'},'nb_subdomain_1',... 426 {'nb_tps_1','nb_coord','nb_subdomain_1'},{'nb_tps_1','nb_subdomain_1'},{'nb_tps_1','nb_subdomain_1'}}]; 431 Data.ListVarName=[Data.ListVarName {'Civ1_U_smooth','Civ1_V_smooth','Civ1_W_smooth'}]; 432 Data.VarDimName=[Data.VarDimName {{'npz','npy','npx'},{'npz','npy','npx'},{'npz','npy','npx'}}]; 427 433 Data.VarAttribute{nbvar+1}.Role='vector_x'; 428 434 Data.VarAttribute{nbvar+2}.Role='vector_y'; 429 Data.VarAttribute{nbvar+5}.Role='coord_tps'; 430 Data.VarAttribute{nbvar+6}.Role='vector_x'; 431 Data.VarAttribute{nbvar+7}.Role='vector_y'; 432 Data.Civ1_U_smooth=Data.Civ1_U; % zeros(size(Data.Civ1_X)); 433 Data.Civ1_V_smooth=Data.Civ1_V; %zeros(size(Data.Civ1_X)); 435 Data.VarAttribute{nbvar+5}.Role='vector_z'; 436 Data.Civ1_U_smooth=Data.Civ1_U; 437 Data.Civ1_V_smooth=Data.Civ1_V; 438 Data.Civ1_W_smooth=Data.Civ1_W; 434 439 if isfield(Data,'Civ1_FF') 435 440 ind_good=find(Data.Civ1_FF==0); 436 441 else 437 ind_good=1:numel(Data.Civ1_X); 442 disp_uvmat('ERROR','detection of error vectors (FIX operation) needed before PATCH' ,checkrun) 443 return 438 444 end 439 445 if isempty(ind_good) … … 443 449 444 450 % perform Patch calculation using the UVMAT fct 'filter_tps' 445 446 [Data.Civ1_SubRange,Data.Civ1_NbCentres,Data.Civ1_Coord_tps,Data.Civ1_U_tps,Data.Civ1_V_tps,~,Ures, Vres,~,FFres]=... 447 filter_tps([Data.Civ1_X(ind_good) Data.Civ1_Y(ind_good)],Data.Civ1_U(ind_good),Data.Civ1_V(ind_good),[],Data.Patch1_SubDomainSize,Data.Patch1_FieldSmooth,Data.Patch1_MaxDiff); 448 Data.Civ1_U_smooth(ind_good)=Ures;% take the interpolated (smoothed) velocity values for good vectors, keep civ1 data for the other 449 Data.Civ1_V_smooth(ind_good)=Vres; 451 Civ1_Z=0.5*Data.Civ1_W(ind_good); 452 for iz=1:numel(Data.Coord_z) 453 Civ1_Z(iz,:,:)=Civ1_Z(iz,:,:)+Data.Coord_z(iz); 454 end 455 [Data.Civ1_SubRange,Data.Civ1_NbCentres,Data.Civ1_Coord_tps,Data.Civ1_U_tps,Data.Civ1_V_tps,Data.Civ1_W_tps,... 456 Data.Civ1_U_smooth(ind_good),Data.Civ1_V_smooth(ind_good),Data.Civ1_V_smooth(ind_good),FFres]=... 457 filter_tps_3D([Data.Civ1_X(ind_good) Data.Civ1_Y(ind_good)],Civ_1_Z,Data.Civ1_U(ind_good),Data.Civ1_V(ind_good),Data.Civ1_W(ind_good),Data.Patch1_SubDomainSize,Data.Patch1_FieldSmooth,Data.Patch1_MaxDiff); 450 458 Data.Civ1_FF(ind_good)=uint8(FFres); 451 459 time_patch1=toc(tstart_patch1); … … 778 786 ibx2=floor(par_civ.CorrBoxSize(1)/2); 779 787 iby2=floor(par_civ.CorrBoxSize(2)/2); 780 isx2= floor(par_civ.SearchBoxSize(1)/2);781 isy2= floor(par_civ.SearchBoxSize(2)/2);782 isz2= floor(par_civ.SearchBoxSize(3)/2);788 isx2=par_civ.SearchRange(1); 789 isy2=par_civ.SearchRange(2); 790 isz2=par_civ.SearchRange(3); 783 791 kref=isz2+1;%middle index of the z slice 784 792 shiftx=round(par_civ.SearchBoxShift(:,1));%use the input shift estimate, rounded to the next integer value … … 891 899 % end 892 900 893 npxycorr= par_civ.SearchBoxSize(1:2)-par_civ.CorrBoxSize(1:2)+1;894 result_conv=zeros([ par_civ.SearchBoxSize(3)npxycorr]);%initialise the conv product895 max_xy=zeros( par_civ.SearchBoxSize(3),1);%initialise the max correlation vs z901 npxycorr=2*par_civ.SearchRange(1:2)+1; 902 result_conv=zeros([2*par_civ.SearchRange(3)+1 npxycorr]);%initialise the conv product 903 max_xy=zeros(2*par_civ.SearchRange(3)+1,1);%initialise the max correlation vs z 896 904 xk=ones(npz,1);%initialise the x displacement corresponding to the max corr 897 905 yk=ones(npz,1);%initialise the y displacement corresponding to the max corr -
trunk/src/series/civ_input.m
r1161 r1163 79 79 set(handles.title_z,'Visible','on') 80 80 set(handles.num_CorrBoxSize_3,'Visible','on') 81 set(handles.num_Search BoxSize_3,'Visible','on')81 set(handles.num_SearchRange_3,'Visible','on') 82 82 set(handles.num_SearchBoxShift_3,'Visible','on') 83 83 set(handles.num_Dz,'Visible','on') … … 119 119 return 120 120 end 121 if isfield(Data,'.Civ1_ImageA') 122 %[PathCiv1_ImageA,Civ1_ImageA,FileExtA]=fileparts(Data.Civ1_ImageA);%look for the source image A 123 %[PathCiv1_ImageB,Civ1_ImageB,FileExtA]=fileparts(Data.Civ1_ImageB);%look for the source image B 124 end 125 if isfield(Data,'Civ2_ImageA') 126 %[PathCiv2_ImageA,Civ2_ImageA,FileExtA]=fileparts(Data.Civ2_ImageA); 127 %[PathCiv2_ImageB,Civ2_ImageB,FileExtA]=fileparts(Data.Civ2_ImageB); 128 end 121 129 122 if size(Param.InputTable,1)==1 130 if isfield(Data,'.Civ1_ImageA') 131 series('display_file_name',hhseries,Data.Civ1_ImageA,'append');%append the image series to the input list 132 [~,~,~,~,~,~,~,~,NomTypeImaA]=fileparts_uvmat(Data.Civ1_ImageA); 133 % [~,~,~,~,~,~,~,~,NomTypeImaB]=fileparts_uvmat(Data.Civ1_ImageB); 134 elseif isfield(Data,'Civ2_ImageA') 135 series('display_file_name',hhseries,Data.Civ2_ImageA,'append');%append the image series to the input list 136 [~,~,~,~,~,~,~,~,NomTypeImaA]=fileparts_uvmat(Data.Civ2_ImageA); 137 %[RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomTypeImaB]=fileparts_uvmat(Data.Civ2_ImageB); 123 124 Param.InputTable(2,:)=Param.InputTable(1,:); 125 set(hhseries.InputTable,'Data',Param.InputTable) 126 if isfield(Data,'Civ2_ImageA') 127 ImageName=Data.Civ2_ImageA; 128 elseif isfield(Data,'Civ1_ImageA') 129 ImageName=Data.Civ1_ImageA; 138 130 end 139 end 140 141 iview_image=2;%line # for the input images 131 series('display_file_name',hhseries,ImageName,1);%append the image series to the input list 132 [~,~,~,~,~,~,~,~,NomTypeImaA]=fileparts_uvmat(ImageName); 133 134 % elseif isfield(Data,'Civ2_ImageA') 135 % series('display_file_name',hhseries,Data.Civ2_ImageA,'append');%append the image series to the input list 136 % [~,~,~,~,~,~,~,~,NomTypeImaA]=fileparts_uvmat(Data.Civ2_ImageA); 137 % 138 % end 139 end 140 141 iview_image=1;%line # for the input images 142 142 otherwise 143 143 % if ~strcmp(FileType,'image') … … 162 162 return 163 163 end 164 MaxIndex_i=Param.IndexRange.MaxIndex_i( iview_image);165 MinIndex_i=Param.IndexRange.MinIndex_i( iview_image);164 MaxIndex_i=Param.IndexRange.MaxIndex_i(1); 165 MinIndex_i=Param.IndexRange.MinIndex_i(1); 166 166 MaxIndex_j=1;%default 167 167 MinIndex_j=1; … … 262 262 for index = 1:ind_opening 263 263 set(handles.(ListOptions{index}),'value',0) 264 end 265 for index = ind_opening+1:6 266 set(handles.(ListOptions{index}),'value',1) 267 end 264 set(handles.(ListOptions{index}),'String',regexprep(ListOptions{index},'Check','redo ')) 265 end 266 % for index = ind_opening+1:6 267 % set(handles.(ListOptions{index}),'value',1) 268 % end 268 269 set(handles.CheckCiv3,'Visible','off')% make visible the switch 'iterate/repet' for Civ2. 269 270 set(handles.CheckCiv3,'Value',0)% select'iterate/repet' by default … … 272 273 set(handles.(ListOptions{index}),'value',0) 273 274 end 274 for index = 4:6275 set(handles.(ListOptions{index}),'value',1)276 end275 % for index = 4:6 276 % set(handles.(ListOptions{index}),'value',1) 277 % end 277 278 set(handles.CheckCiv3,'Visible','on')% make visible the switch 'iterate/repet' for Civ2. 278 279 set(handles.CheckCiv3,'Value',1)% select'iterate/repet' by default … … 290 291 if ~checkrefresh && isfield(Param,'ActionInput')&& strcmp(Param.ActionInput.Program,Param.Action.ActionName)% the program fits with the stored data 291 292 fill_GUI(Param.ActionInput,hObject);%fill the GUI with the parameters retrieved from the input Param 293 294 if isfield(Param.ActionInput,'Civ1')&& isfield(Param.ActionInput.Civ1,'SearchBoxSize') 295 SearchRange=round((Param.ActionInput.Civ1.SearchBoxSize-Param.ActionInput.Civ1.CorrBoxSize)/2); 296 set(handles.num_SearchRange_1(1),'String',num2str(SearchRange(1))) 297 set(handles.num_SearchRange_2(1),'String',num2str(SearchRange(2))) 298 end 299 if isfield(Param.ActionInput,'Civ2')&& isfield(Param.ActionInput.Civ2,'SearchBoxSize') 300 SearchRange=round((Param.ActionInput.Civ2.SearchBoxSize-Param.ActionInput.Civ2.CorrBoxSize)/2); 301 set(handles.num_SearchRange_1(2),'String',num2str(SearchRange(1))) 302 set(handles.num_SearchRange_2(2),'String',num2str(SearchRange(2))) 303 end 292 304 hcheckgrid=findobj(handles.civ_input,'Tag','CheckGrid'); 293 305 for ilist=1:numel(hcheckgrid) … … 416 428 %Param.CheckCiv1=1; 417 429 Param.Civ1.CorrBoxSize=[31 31 1]; 418 Param.Civ1.Search BoxSize=[61 61 5];430 Param.Civ1.SearchRange=[15 15 2]; 419 431 Param.Civ1.SearchBoxShift=[0 0]; 420 432 Param.Civ1.CorrSmooth=1; … … 439 451 %Param.CheckCiv2=1; 440 452 Param.Civ2.CorrBoxSize=[21 21]; 441 Param.Civ2.Search BoxSize=[27 27];453 Param.Civ2.SearchRange=[3 3]; 442 454 Param.Civ2.CorrSmooth=1; 443 455 Param.Civ2.Dx=10; … … 515 527 %------------------------------------------------------------------------ 516 528 update_CivOptions(handles,0) 529 update_frame(handles,'CheckCiv1') 530 517 531 518 532 %------------------------------------------------------------------------ … … 521 535 %------------------------------------------------------------------------ 522 536 update_CivOptions(handles,0) 537 update_frame(handles,'CheckFix1') 523 538 524 539 %------------------------------------------------------------------------ … … 527 542 %------------------------------------------------------------------------ 528 543 update_CivOptions(handles,0) 544 update_frame(handles,'CheckPatch1') 545 529 546 530 547 %------------------------------------------------------------------------ … … 533 550 %------------------------------------------------------------------------ 534 551 update_CivOptions(handles,0) 552 update_frame(handles,'CheckCiv2') 535 553 536 554 %------------------------------------------------------------------------ … … 539 557 %------------------------------------------------------------------------ 540 558 update_CivOptions(handles,0) 559 update_frame(handles,'CheckFix2') 541 560 542 561 %------------------------------------------------------------------------ … … 545 564 %------------------------------------------------------------------------ 546 565 update_CivOptions(handles,0) 566 update_frame(handles,'CheckPatch2') 567 568 function update_frame(handles,option) 569 if get(handles.(option),'Value') 570 option=regexprep(option,'Check',''); 571 set(handles.(option),'Visible','on') 572 children=get(handles.(option),'children'); 573 set(children,'Enable','on') 574 else 575 option=regexprep(option,'Check',''); 576 set(handles.(option),'Visible','off') 577 end 547 578 548 579 %------------------------------------------------------------------------ … … 591 622 for ilist=1:length(options) 592 623 if checkbox(ilist) 593 set(handles.(options{ilist}),'Visible','on') 624 % set(handles.(options{ilist}),'Visible','on') 625 set(handles.(options{ilist}),'Enable','on') 626 % set(handles.(['Check' options{ilist}]),'Strin 594 627 else 595 set(handles.(options{ilist}),'Visible','off') 628 % set(handles.(options{ilist}),'Visible','off') 629 set(handles.(options{ilist}),'Enable','off') 596 630 end 597 631 end … … 608 642 checkeven=(mod(ActionInput.Civ1.CorrBoxSize,2)==0); 609 643 ActionInput.Civ1.CorrBoxSize(checkeven)=ActionInput.Civ1.CorrBoxSize(checkeven)+1;% set correlation box sizes to odd values 610 ActionInput.Civ1.SearchBoxSize(1:2)=max(ActionInput.Civ1.SearchBoxSize(1:2),ActionInput.Civ1.CorrBoxSize(1:2)+8);% insure that the search box size is large enough611 checkeven=(mod(ActionInput.Civ1.SearchBoxSize,2)==0);612 ActionInput.Civ1.SearchBoxSize(checkeven)=ActionInput.Civ1.SearchBoxSize(checkeven)+1;% set search box sizes to odd values644 %ActionInput.Civ1.SearchBoxSize(1:2)=max(ActionInput.Civ1.SearchBoxSize(1:2),ActionInput.Civ1.CorrBoxSize(1:2)+8);% insure that the search box size is large enough 645 %checkeven=(mod(ActionInput.Civ1.SearchBoxSize,2)==0); 646 %ActionInput.Civ1.SearchBoxSize(checkeven)=ActionInput.Civ1.SearchBoxSize(checkeven)+1;% set search box sizes to odd values 613 647 end 614 648 if isfield(ActionInput,'Civ2') 615 649 checkeven=(mod(ActionInput.Civ2.CorrBoxSize,2)==0); 616 650 ActionInput.Civ2.CorrBoxSize(checkeven)=ActionInput.Civ2.CorrBoxSize(checkeven)+1;% set correlation box sizes to odd values 617 ActionInput.Civ2.SearchBoxSize=max(ActionInput.Civ2.SearchBoxSize,ActionInput.Civ2.CorrBoxSize+4);618 checkeven=(mod(ActionInput.Civ2.SearchBoxSize,2)==0);619 ActionInput.Civ2.SearchBoxSize(checkeven)=ActionInput.Civ2.SearchBoxSize(checkeven)+1;% set search box sizes to odd values651 %ActionInput.Civ2.SearchBoxSize=max(ActionInput.Civ2.SearchBoxSize,ActionInput.Civ2.CorrBoxSize+4); 652 % checkeven=(mod(ActionInput.Civ2.SearchBoxSize,2)==0); 653 %ActionInput.Civ2.SearchBoxSize(checkeven)=ActionInput.Civ2.SearchBoxSize(checkeven)+1;% set search box sizes to odd values 620 654 end 621 655 … … 1002 1036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1003 1037 %------------------------------------------------------------------------ 1004 % --- Executes on button press in SearchRange: determine the search range num_Search BoxSize_1,num_SearchBoxSize_21038 % --- Executes on button press in SearchRange: determine the search range num_SearchRange_1,num_SearchRange_2 1005 1039 function SearchRange_Callback(hObject, eventdata, handles) 1006 1040 %------------------------------------------------------------------------ … … 1024 1058 1025 1059 %------------------------------------------------------------------------ 1026 % --- determine the search range num_Search BoxSize_1,num_SearchBoxSize_2 and shift1060 % --- determine the search range num_SearchRange_1,num_SearchRange_2 and shift 1027 1061 function get_search_range(hObject, eventdata, handles) 1028 1062 %------------------------------------------------------------------------ … … 1056 1090 set(handles.num_SearchBoxShift_1,'String',num2str(shiftx)); 1057 1091 set(handles.num_SearchBoxShift_2,'String',num2str(shifty)); 1058 set(handles.num_Search BoxSize_1,'String',num2str(isx));1059 set(handles.num_Search BoxSize_2,'String',num2str(isy));1092 set(handles.num_SearchRange_1,'String',num2str(isx)); 1093 set(handles.num_SearchRange_2,'String',num2str(isy)); 1060 1094 end 1061 1095 … … 1087 1121 currentdir=pwd; 1088 1122 cd(Path);%move in the dir of the root name filebase 1089 gridfiles=dir([Name '_*grid_*. grid']);%look for grid files1123 gridfiles=dir([Name '_*grid_*.nc']);%look for grid files 1090 1124 cd(currentdir);%come back to the current working directory 1091 1125 if ~isempty(gridfiles) … … 1168 1202 function CheckGrid_Callback(hObject, eventdata, handles) 1169 1203 %------------------------------------------------------------------------ 1170 value=get(hObject,'Value'); 1171 hparent=get(hObject,'parent');%handles of the parent panel 1172 hchildren=get(hparent,'children'); 1173 handle_txtbox=findobj(hchildren,'tag','Grid');% look for the grid name box in the same panel 1174 handle_dx=findobj(hchildren,'tag','num_Dx'); 1175 handle_dy=findobj(hchildren,'tag','num_Dy'); 1176 handle_title_dx=findobj(hchildren,'tag','title_Dx'); 1177 handle_title_dy=findobj(hchildren,'tag','title_Dy'); 1178 testgrid=0; 1179 filegrid=''; 1180 if value 1181 hseries=findobj(allchild(0),'Tag','series'); 1204 hparent=get(hObject,'parent'); 1205 PanelName=get(hparent,'tag'); 1206 handle_txtbox=handles.Grid 1207 if strcmp(PanelName,'civ2') 1208 handle_txtbox=handle_txtbox(2); 1209 end 1210 % hchildren=get(hparent,'children'); 1211 % handle_txtbox=findobj(hchildren,'tag','Grid');% look for the grid name box in the same panel 1212 % handle_NbSlice=findobj(hchildren,'tag','num_NbSlice');% look for the mask name box in the same panel 1213 testgrid=false; 1214 corrstatus='on'; 1215 if get(hObject,'Value')% if the checkbox is activated 1216 hseries=findobj(allchild(0),'Tag','series'); 1182 1217 hhseries=guidata(hseries); 1183 1218 InputTable=get(hhseries.InputTable,'Data'); 1184 ind_A=1;% line index of the (first) image series 1185 if strcmp(InputTable{1,5},'.nc'); 1186 ind_A=2; 1187 end 1188 filebase=InputTable{ind_A,1}; 1189 [nbslice, flag_grid]=get_grid(filebase,handles);% look for a grid with appropriate name 1190 if isequal(flag_grid,1) 1191 filegrid=[num2str(nbslice) 'grid']; 1192 testgrid=1; 1193 else % browse for a grid 1194 filegrid=get(hObject,'UserData');%look for previous grid name stored as UserData 1195 if exist(filegrid,'file') 1196 filebase=filegrid; 1197 end 1198 filegrid = uigetfile_uvmat('pick a grid file .grid:',filebase,'.grid'); 1199 set(hObject,'UserData',filegrid);%store for future use 1200 if ~isempty(filegrid) 1201 testgrid=1; 1202 end 1203 set(hObject,'UserData',filegrid);%store for future use 1219 % browse for a grid file 1220 filegrid= uigetfile_uvmat('pick a grid netcdf file (made by script_makegrid.m):',InputTable{1,1},'.nc'); 1221 if ~isempty(filegrid) 1222 [FilePath,FileName,FileExt]=fileparts(filegrid); 1223 Data=nc2struct(filegrid); 1224 if isfield(Data,'Grid') 1225 testgrid=true; 1226 end 1227 if isfield(Data,'CorrBox') 1228 corrstatus='off'; 1229 end 1204 1230 end 1205 1231 end 1206 1232 if testgrid 1207 set(handle_dx,'Visible','off');1208 set(handle_dy,'Visible','off');1209 set(handle_title_dy,'Visible','off');1210 set(handle_title_dx,'Visible','off');1211 1233 set(handle_txtbox,'Visible','on') 1212 1234 set(handle_txtbox,'String',filegrid) 1213 else 1214 set(h Object,'Value',0);1215 set(handle_dx,'Visible','on'); 1216 set(handle _dy,'Visible','on');1217 set(handle _title_dy,'Visible','on');1218 set(h andle_title_dx,'Visible','on');1235 set(handles.num_Dx,'Visible','off') 1236 set(handles.num_Dy,'Visible','off') 1237 else 1238 set(handles.num_Dx,'Visible','on') 1239 set(handles.num_Dy,'Visible','on') 1240 set(hObject,'Value',0) 1219 1241 set(handle_txtbox,'Visible','off') 1220 1242 end 1221 1243 1244 set(handles.num_CorrBoxSize_1,'Visible',corrstatus) 1245 set(handles.num_CorrBoxSize_2,'Visible',corrstatus) 1246 1247 1222 1248 %% if hObject is on the checkciv1 frame, duplicate action for checkciv2 frame 1223 PanelName=get(hparent,'tag');1224 if strcmp(PanelName,'Civ1')1225 hchildren=get(handles.Civ2,'children');1226 handle_checkbox=findobj(hchildren,'tag','CheckGrid');1227 handle_txtbox=findobj(hchildren,'tag','Grid');1228 handle_dx=findobj(hchildren,'tag','num_Dx');1229 handle_dy=findobj(hchildren,'tag','num_Dy');1230 handle_title_dx=findobj(hchildren,'tag','title_Dx');1231 handle_title_dy=findobj(hchildren,'tag','title_Dy');1232 1233 if testgrid1234 set(handle_checkbox,'Value',1);1235 set(handle_dx,'Visible','off');1236 set(handle_dy,'Visible','off');1237 set(handle_title_dx,'Visible','off');1238 set(handle_title_dy,'Visible','off');1239 set(handle_txtbox,'Visible','on')1240 set(handle_txtbox,'String',filegrid)1241 end1242 end1249 % PanelName=get(hparent,'tag'); 1250 % if strcmp(PanelName,'Civ1') 1251 % hchildren=get(handles.Civ2,'children'); 1252 % handle_checkbox=findobj(hchildren,'tag','CheckGrid'); 1253 % handle_txtbox=findobj(hchildren,'tag','Grid'); 1254 % handle_dx=findobj(hchildren,'tag','num_Dx'); 1255 % handle_dy=findobj(hchildren,'tag','num_Dy'); 1256 % handle_title_dx=findobj(hchildren,'tag','title_Dx'); 1257 % handle_title_dy=findobj(hchildren,'tag','title_Dy'); 1258 % %set(handle_checkbox,'UserData',filegrid);%store for future use 1259 % if testgrid 1260 % set(handle_checkbox,'Value',1); 1261 % set(handle_dx,'Visible','off'); 1262 % set(handle_dy,'Visible','off'); 1263 % set(handle_title_dx,'Visible','off'); 1264 % set(handle_title_dy,'Visible','off'); 1265 % set(handle_txtbox,'Visible','on') 1266 % set(handle_txtbox,'String',filegrid) 1267 % end 1268 % end 1243 1269 set(handles.ConfigSource,'String','NEW') 1244 1270 set(handles.OK,'BackgroundColor',[1 0 1]) … … 1701 1727 %% Civ param 1702 1728 % lists of parameters to enter 1703 ListParamNum={'CorrBoxSize','Search BoxSize','SearchBoxShift','Dx','Dy','Dz','MinIma','MaxIma'};% list of numerical values (to transform in strings)1729 ListParamNum={'CorrBoxSize','SearchRange','SearchBoxShift','Dx','Dy','Dz','MinIma','MaxIma'};% list of numerical values (to transform in strings) 1704 1730 ListParamValue={'CorrSmooth','CheckGrid','CheckMask','CheckThreshold'}; 1705 1731 ListParamString={'Grid','Mask'}; … … 1738 1764 function fill_panel(Data,handles,panel,ListParamNum,ListParamValue,ListParamString) 1739 1765 children=get(handles.(panel),'children');%handles of the children of the input GUI with handle 'GUI_handle' 1766 set(children,'enable','off') 1767 set(handles.(panel),'Visible','on') 1740 1768 handles_panel=[]; 1741 1769 for ichild=1:numel(children) … … 1812 1840 check_input=0; 1813 1841 if isfield(Param,'ActionInput') 1814 if isfield(Param.ActionInput,'Program')&& strcmp(Param.ActionInput.Program,'civ_series')1842 if isfield(Param.ActionInput,'Program')&& ismember(Param.ActionInput.Program,{'civ_series','civ_3D'}) 1815 1843 fill_GUI(Param.ActionInput,handles.civ_input)% fill the elements of the GUI series with the input parameters 1816 1844 set(handles.ConfigSource,'String',filexml) 1817 1845 check_input=1; 1846 if isfield(Param.ActionInput,'Civ1')&& isfield(Param.ActionInput.Civ1,'SearchBoxSize') 1847 SearchRange=round((Param.ActionInput.Civ1.SearchBoxSize-Param.ActionInput.Civ1.CorrBoxSize)/2); 1848 set(handles.num_SearchRange_1(1),'String',num2str(SearchRange(1))) 1849 set(handles.num_SearchRange_2(1),'String',num2str(SearchRange(2))) 1850 end 1851 if isfield(Param.ActionInput,'Civ2')&& isfield(Param.ActionInput.Civ2,'SearchBoxSize') 1852 SearchRange=round((Param.ActionInput.Civ2.SearchBoxSize-Param.ActionInput.Civ2.CorrBoxSize)/2); 1853 set(handles.num_SearchRange_1(2),'String',num2str(SearchRange(1))) 1854 set(handles.num_SearchRange_2(2),'String',num2str(SearchRange(2))) 1855 end 1818 1856 update_CivOptions(handles,0) 1819 1857 end … … 1875 1913 1876 1914 1877 function num_CorrBoxSize_3_Callback(hObject, eventdata, handles)1878 1879 1880 function num_SearchBoxSize_3_Callback(hObject, eventdata, handles)1881 1915 1882 1916 … … 1886 1920 % --- Executes on selection change in field_ref2. 1887 1921 function field_ref2_Callback(hObject, eventdata, handles) 1922 1923 1924 1925 function num_SearchRange_3_Callback(hObject, eventdata, handles) 1926 % hObject handle to num_SearchRange_3 (see GCBO) 1927 % eventdata reserved - to be defined in a future version of MATLAB 1928 % handles structure with handles and user data (see GUIDATA) 1929 1930 % Hints: get(hObject,'String') returns contents of num_SearchRange_3 as text 1931 % str2double(get(hObject,'String')) returns contents of num_SearchRange_3 as a double -
trunk/src/series/civ_series.m
r1162 r1163 75 75 if isfield(Data,'ActionInput') && isfield(Data.ActionInput,'PairIndices') && strcmp(Data.ActionInput.PairIndices.ListPairMode,'pair j1-j2') 76 76 Data.IndexRange_j='off';%no j index display in series 77 % if isfield(Data.ActionInput.PairIndices,'ListPairCiv2')78 % str_civ=Data.ActionInput.PairIndices.ListPairCiv2;79 % else80 % str_civ=Data.ActionInput.PairIndices.ListPairCiv1;81 % end82 % r=regexp(str_civ,'^j= (?<num1>[a-z])-(?<num2>[a-z])','names');83 % if isempty(r)84 % r=regexp(str_civ,'^j= (?<num1>[A-Z])-(?<num2>[A-Z])','names');85 % if isempty(r)86 % r=regexp(str_civ,'^j= (?<num1>\d+)-(?<num2>\d+)','names');87 % end88 % end89 % if ~isempty(r)90 % Data.j_index_1=stra2num(r.num1);91 % Data.j_index_2=stra2num(r.num2);92 % end93 77 else 94 78 Data.IndexRange_j='on';% j index display in series if relevant … … 361 345 ImageName_A=Param.ActionInput.RefFile; 362 346 else 363 ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(ifield),[],j1_series_Civ1(ifield));347 ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(ifield),[],j1_series_Civ1(ifield)); 364 348 end 365 349 if strcmp(FileExt_A,'.nc')% case of input images in format netcdf … … 393 377 end 394 378 ImageName_B=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_series_Civ1(ifield),[],j2_series_Civ1(ifield)); 395 if strcmp(FileExt_B,'.nc') % case of input images in format netcdf 396 FieldName_B=Param.InputFields.FieldName; 397 [DataIn,~,~,errormsg]=nc2struct(ImageName_B,{FieldName_B}); 398 par_civ1.ImageB=DataIn.(FieldName_B); 399 else % usual image formats for image B 400 if isempty(FileType_B) 379 if isempty(FileType_B)% determine the image type for the first field 401 380 [FileInfo_B,VideoObject_B]=get_file_info(ImageName_B); 402 381 FileType_B=FileInfo_B.FileType; … … 407 386 end 408 387 [par_civ1.ImageB,VideoObject_B] = read_image(ImageName_B,FileType_B,VideoObject_B,FrameIndex_B_Civ1(ifield)); 409 end410 388 catch ME % display errors in reading input images 411 389 if ~isempty(ME.message) … … 414 392 end 415 393 end 416 par_civ1.ImageWidth=size(par_civ1.ImageA,2);417 par_civ1.ImageHeight=size(par_civ1.ImageA,1);394 % par_civ1.ImageWidth=size(par_civ1.ImageA,2); 395 % par_civ1.ImageHeight=size(par_civ1.ImageA,1); 418 396 list_param=(fieldnames(Param.ActionInput.Civ1))'; 419 397 list_param(strcmp('TestCiv1',list_param))=[];% remove the parameter TestCiv1 from the list … … 460 438 Data.VarAttribute{5}.Role='ancillary'; 461 439 Data.VarAttribute{6}.Role='errorflag'; 440 462 441 % case of mask 463 442 if par_civ1.CheckMask&&~isempty(par_civ1.Mask) 464 if isfield(par_civ1,'NbSlice') 465 [RootPath_mask,SubDir_mask,RootFile_mask,~,~,~,~,Ext_mask]=fileparts_uvmat(Param.ActionInput.Civ1.Mask); 443 [RootPath_mask,SubDir_mask,RootFile_mask,~,~,~,~,Ext_mask]=fileparts_uvmat(Param.ActionInput.Civ1.Mask); 444 j1=1; 445 if ~isempty(j1_series_Civ1) 446 j1=j1_series_Civ1(ifield); 447 end 448 if ~isempty(i2_series_Civ1)% case of volume,masks act on different j levels 449 maskname=fullfile_uvmat(RootPath_mask,SubDir_mask,RootFile_mask,Ext_mask,'_1',j1); 450 elseif isfield(par_civ1,'NbSlice') 466 451 i1_mask=mod(i1-1,par_civ1.NbSlice)+1; 467 452 maskname=fullfile_uvmat(RootPath_mask,SubDir_mask,RootFile_mask,Ext_mask,'_1',i1_mask); … … 489 474 end 490 475 end 491 if strcmp(Param.ActionInput.ListCompareMode, 'PIV volume') 492 % Data.ListVarName=[Data.ListVarName 'Civ1_Z']; 493 % Data.Civ1_X=[];Data.Civ1_Y=[];Data.Civ1_Z=[]; 494 % Data.Civ1_U=[];Data.Civ1_V=[];Data.Civ1_C=[]; 495 % for ivol=1:NbSlice 496 % % caluclate velocity data (y and v in indices, reverse to y component) 497 % [xtable, ytable, utable, vtable, ctable, F, result_conv, errormsg] = civ (par_civ1); 498 % if ~isempty(errormsg) 499 % disp_uvmat('ERROR',errormsg,checkrun) 500 % return 501 % end 502 % Data.Civ1_X=[Data.Civ1_X reshape(xtable,[],1)]; 503 % Data.Civ1_Y=[Data.Civ1_Y reshape(Param.Civ1.ImageHeight-ytable+1,[],1)]; 504 % Data.Civ1_Z=[Data.Civ1_Z ivol*ones(numel(xtable),1)];% z=image index in image coordinates 505 % Data.Civ1_U=[Data.Civ1_U reshape(utable,[],1)]; 506 % Data.Civ1_V=[Data.Civ1_V reshape(-vtable,[],1)]; 507 % Data.Civ1_C=[Data.Civ1_C reshape(ctable,[],1)]; 508 % Data.Civ1_FF=[Data.Civ1_FF reshape(F,[],1)]; 509 % end 510 else %usual PIV 511 % caluclate velocity data (y and v in indices, reverse to y component) 512 tstart_civ1=tic; 513 [xtable, ytable, utable, vtable, ctable, FF, result_conv, errormsg] = civ (par_civ1); 514 if ~isempty(errormsg) 515 disp_uvmat('ERROR',errormsg,checkrun) 516 return 517 end 518 Data.Civ1_X=reshape(xtable,[],1); 519 Data.Civ1_Y=reshape(par_civ1.ImageHeight-ytable+1,[],1); 520 Data.Civ1_U=reshape(utable,[],1); 521 Data.Civ1_V=reshape(-vtable,[],1); 522 Data.Civ1_C=reshape(ctable,[],1); 523 Data.Civ1_FF=reshape(FF,[],1); 524 time_civ1=toc(tstart_civ1); 525 end 476 477 % case of input grid 478 if par_civ1.CheckGrid &&~isempty(par_civ1.Grid) 479 GridData=nc2struct(Param.ActionInput.Civ1.Grid); 480 par_civ1.Grid=GridData.Grid; 481 par_civ1.CorrBoxSize=GridData.CorrBox; 482 end 483 484 % caluclate velocity data 485 tstart_civ1=tic; 486 [Data.Civ1_X,Data.Civ1_Y,Data.Civ1_U,Data.Civ1_V,Data.Civ1_C,Data.Civ1_FF, result_conv, errormsg] = civ (par_civ1); 487 if ~isempty(errormsg) 488 disp_uvmat('ERROR',errormsg,checkrun) 489 return 490 end 491 526 492 else% we use existing Civ1 data 527 493 if exist('ncfile','var') … … 603 569 604 570 % perform Patch calculation using the UVMAT fct 'filter_tps' 605 [Data.Civ1_SubRange,Data.Civ1_NbCentres,Data.Civ1_Coord_tps,Data.Civ1_U_tps,Data.Civ1_V_tps, tild,Ures, Vres,tild,FFres]=...571 [Data.Civ1_SubRange,Data.Civ1_NbCentres,Data.Civ1_Coord_tps,Data.Civ1_U_tps,Data.Civ1_V_tps,~,Ures, Vres,~,FFres]=... 606 572 filter_tps([Data.Civ1_X(ind_good) Data.Civ1_Y(ind_good)],Data.Civ1_U(ind_good),Data.Civ1_V(ind_good),[],Data.Patch1_SubDomainSize,Data.Patch1_FieldSmooth,Data.Patch1_MaxDiff); 607 573 Data.Civ1_U_smooth(ind_good)=Ures;% take the interpolated (smoothed) velocity values for good vectors, keep civ1 data for the other … … 637 603 end 638 604 [FileInfo_A,VideoObject_A]=get_file_info(ImageName_A_Civ2); 639 par_civ2.ImageWidth=FileInfo_A.Width; 640 par_civ2.ImageHeight=FileInfo_A.Height; 641 if isfield(par_civ2,'Grid')% grid points set as input file 642 if ischar(par_civ2.Grid)%read the grid file if the input is a file name 643 par_civ2.Grid=dlmread(par_civ2.Grid); 644 par_civ2.Grid(1,:)=[];%the first line must be removed (heading in the grid file) 645 end 605 [npy_ima,npx_ima]=size(par_civ2.ImageA(:,:)); 606 % par_civ2.ImageWidth=FileInfo_A.Width; 607 % par_civ2.ImageHeight=FileInfo_A.Height; 608 609 if par_civ2.CheckGrid &&~isempty(par_civ2.Grid) % case of input grid 610 GridData=nc2struct(Param.ActionInput.Civ2.Grid); 611 par_civ2.Grid=GridData.Grid; 612 par_civ2.CorrBoxSize=GridData.CorrBox; 613 646 614 else% automatic grid 647 minix=floor(par_civ2.Dx/2)-0.5; 648 maxix=minix+par_civ2.Dx*floor((par_civ2.ImageWidth-1)/par_civ2.Dx); 649 miniy=floor(par_civ2.Dy/2)-0.5; 650 maxiy=minix+par_civ2.Dy*floor((par_civ2.ImageHeight-1)/par_civ2.Dy); 651 [GridX,GridY]=meshgrid(minix:par_civ2.Dx:maxix,miniy:par_civ2.Dy:maxiy); 615 nbinterv_x=floor((npx_ima-1)/par_civ2.Dx); 616 gridlength_x=nbinterv_x*par_civ2.Dx; 617 minix=ceil((npx_ima-gridlength_x)/2); 618 nbinterv_y=floor((npy_ima-1)/par_civ2.Dy); 619 gridlength_y=nbinterv_y*par_civ2.Dy; 620 miniy=ceil((npy_ima-gridlength_y)/2); 621 [GridX,GridY]=meshgrid(minix:par_civ2.Dx:npx_ima-1,miniy:par_civ2.Dy:npy_ima-1); 622 par_civ2.Grid=zeros(numel(GridX),2); 652 623 par_civ2.Grid(:,1)=reshape(GridX,[],1); 653 par_civ2.Grid(:,2)=reshape(GridY,[],1); 654 end 655 end 656 624 par_civ2.Grid(:,2)=reshape(GridY,[],1);% increases with array index 625 626 end 627 end 628 657 629 % get the guess from patch1 or patch2 (case 'CheckCiv3') 658 if CheckInputFile % read input images (except in mode Test where it is introduced directly in Param.ActionInput.Civ1.ImageNameA and B) 659 if isfield (par_civ2,'CheckCiv3') && par_civ2.CheckCiv3 %get the guess from patch2 660 SubRange= Data.Civ2_SubRange; 661 NbCentres=Data.Civ2_NbCentres; 662 Coord_tps=Data.Civ2_Coord_tps; 663 U_tps=Data.Civ2_U_tps; 664 V_tps=Data.Civ2_V_tps; 665 CivStage=Data.CivStage;%store the current CivStage 666 Civ1_Dt=Data.Civ2_Dt; 667 Data=[];%reinitialise the result structure Data 668 Data.ListGlobalAttribute={'Conventions','Program','CivStage'}; 669 Data.Conventions='uvmat/civdata';% states the conventions used for the description of field variables and attributes 670 Data.Program='civ_series'; 671 Data.CivStage=CivStage+1;%update the current civStage after reinitialisation of Data 672 Data.ListVarName={}; 673 Data.VarDimName={}; 674 else % get the guess from patch1 675 SubRange= Data.Civ1_SubRange; 676 NbCentres=Data.Civ1_NbCentres; 677 Coord_tps=Data.Civ1_Coord_tps; 678 U_tps=Data.Civ1_U_tps; 679 V_tps=Data.Civ1_V_tps; 680 Civ1_Dt=Data.Civ1_Dt; 681 Data.CivStage=4; 682 end 683 else 684 SubRange= par_civ2.Civ1_SubRange; 685 NbCentres=par_civ2.Civ1_NbCentres; 686 Coord_tps=par_civ2.Civ1_Coord_tps; 687 U_tps=par_civ2.Civ1_U_tps; 688 V_tps=par_civ2.Civ1_V_tps; 689 Civ1_Dt=par_civ2.Civ1_Dt; 690 Civ2_Dt=par_civ2.Civ1_Dt; 630 % if CheckInputFile % read input images (except in mode Test where it is introduced directly in Param.ActionInput.Civ1.ImageNameA and B) 631 if isfield (par_civ2,'CheckCiv3') && par_civ2.CheckCiv3 %get the guess from patch2 632 SubRange= Data.Civ2_SubRange; 633 NbCentres=Data.Civ2_NbCentres; 634 Coord_tps=Data.Civ2_Coord_tps; 635 U_tps=Data.Civ2_U_tps; 636 V_tps=Data.Civ2_V_tps; 637 CivStage=Data.CivStage;%store the current CivStage 638 Civ1_Dt=Data.Civ2_Dt; 639 Data=[];%reinitialise the result structure Data 640 Data.ListGlobalAttribute={'Conventions','Program','CivStage'}; 641 Data.Conventions='uvmat/civdata';% states the conventions used for the description of field variables and attributes 642 Data.Program='civ_series'; 643 Data.CivStage=CivStage+1;%update the current civStage after reinitialisation of Data 691 644 Data.ListVarName={}; 692 645 Data.VarDimName={}; 693 end 646 else % get the guess from patch1 647 SubRange= Data.Civ1_SubRange; 648 NbCentres=Data.Civ1_NbCentres; 649 Coord_tps=Data.Civ1_Coord_tps; 650 U_tps=Data.Civ1_U_tps; 651 V_tps=Data.Civ1_V_tps; 652 Civ1_Dt=Data.Civ1_Dt; 653 Data.CivStage=4; 654 end 655 % else 656 % SubRange= par_civ2.Civ1_SubRange; 657 % NbCentres=par_civ2.Civ1_NbCentres; 658 % Coord_tps=par_civ2.Civ1_Coord_tps; 659 % U_tps=par_civ2.Civ1_U_tps; 660 % V_tps=par_civ2.Civ1_V_tps; 661 % Civ1_Dt=par_civ2.Civ1_Dt; 662 % Civ2_Dt=par_civ2.Civ1_Dt; 663 % Data.ListVarName={}; 664 % Data.VarDimName={}; 665 % end 694 666 Shiftx=zeros(size(par_civ2.Grid,1),1);% shift expected from civ1 data 695 667 Shifty=zeros(size(par_civ2.Grid,1),1); … … 709 681 epoints = par_civ2.Grid(ind_sel,:);% coordinates of interpolation sites (measurement grids) 710 682 ctrs=Coord_tps(1:nbvec_sub,:,isub) ;%(=initial points) ctrs 711 nbval(ind_sel)=nbval(ind_sel)+1;% records the number of values for each interpolation point (in case of subdomain overlap)712 683 EM = tps_eval(epoints,ctrs);% thin plate spline (tps) coefficient 713 Shiftx(ind_sel)=Shiftx(ind_sel)+EM*U_tps(1:nbvec_sub+3,isub);%velocity shift estimated by tps from civ1 714 Shifty(ind_sel)=Shifty(ind_sel)+EM*V_tps(1:nbvec_sub+3,isub); 684 CentreX=(SubRange(1,1,isub)+SubRange(1,2,isub))/2; %x posiion of the subdomain center 685 CentreY=(SubRange(2,1,isub)+SubRange(2,2,isub))/2; %y posiion of the subdomain center 686 xwidth=(SubRange(1,2,isub)-SubRange(1,1,isub))/pi; 687 ywidth=(SubRange(2,2,isub)-SubRange(2,1,isub))/pi; 688 x_dist=(epoints(:,1)-CentreX)/xwidth; 689 y_dist=(epoints(:,2)-CentreY)/ywidth; 690 weight=cos(x_dist).*cos(y_dist);%weighting fct =1 at the rectangle center and 0 at edge 691 nbval(ind_sel)=nbval(ind_sel)+weight;% records the number of values for each interpolation point (in case of subdomain overlap) 692 Shiftx(ind_sel)=Shiftx(ind_sel)+weight.*(EM*U_tps(1:nbvec_sub+3,isub));%velocity shift estimated by tps from civ1 693 Shifty(ind_sel)=Shifty(ind_sel)+weight.*(EM*V_tps(1:nbvec_sub+3,isub)); 715 694 if par_civ2.CheckDeformation 716 695 [EMDX,EMDY] = tps_eval_dxy(epoints,ctrs);%2D matrix of distances between extrapolation points epoints and spline centres (=site points) ctrs 717 DUDX(ind_sel)=DUDX(ind_sel)+EMDX*U_tps(1:nbvec_sub+3,isub); 718 DUDY(ind_sel)=DUDY(ind_sel)+EMDY*U_tps(1:nbvec_sub+3,isub); 719 DVDX(ind_sel)=DVDX(ind_sel)+EMDX*V_tps(1:nbvec_sub+3,isub); 720 DVDY(ind_sel)=DVDY(ind_sel)+EMDY*V_tps(1:nbvec_sub+3,isub); 721 end 722 end 723 end 724 i1=i1_series_Civ2(ifield); 725 i2=i1; 726 if ~isempty(i2_series_Civ2) 727 i2=i2_series_Civ1(ifield); 728 end 729 j1=1; 730 if ~isempty(j1_series_Civ2) 731 j1=j1_series_Civ1(ifield); 732 end 733 j2=j1; 734 if ~isempty(j2_series_Civ2) 735 j2=j2_series_Civ2(ifield); 736 end 737 if par_civ2.CheckMask&&~isempty(par_civ2.Mask) 738 if isfield(par_civ2,'NbSlice') 739 [RootPath_mask,SubDir_mask,RootFile_mask,~,~,~,~,Ext_mask]=fileparts_uvmat(Param.ActionInput.Civ2.Mask); 696 DUDX(ind_sel)=DUDX(ind_sel)+weight.*(EMDX*U_tps(1:nbvec_sub+3,isub)); 697 DUDY(ind_sel)=DUDY(ind_sel)+weight.*(EMDY*U_tps(1:nbvec_sub+3,isub)); 698 DVDX(ind_sel)=DVDX(ind_sel)+weight.*(EMDX*V_tps(1:nbvec_sub+3,isub)); 699 DVDY(ind_sel)=DVDY(ind_sel)+weight.*(EMDY*V_tps(1:nbvec_sub+3,isub)); 700 end 701 end 702 end 703 Shiftx(nbval>0)=Shiftx(nbval>0)./nbval(nbval>0); 704 Shifty(nbval>0)=Shifty(nbval>0)./nbval(nbval>0); 705 706 % introduce mask 707 if par_civ2.CheckMask && ~isempty(par_civ2.Mask) 708 [RootPath_mask,SubDir_mask,RootFile_mask,~,~,~,~,Ext_mask]=fileparts_uvmat(Param.ActionInput.Civ2.Mask); 709 if ~isempty(i2_series_Civ2) % we do PIV among indices i, at given indices j (volume scan), mask depends on position j 710 j1=1; 711 if ~isempty(j1_series_Civ2) 712 j1=j1_series_Civ1(ifield); 713 end 714 maskname=fullfile_uvmat(RootPath_mask,SubDir_mask,RootFile_mask,Ext_mask,'_1',j1); 715 elseif isfield(par_civ2,'NbSlice') 716 i1=i1_series_Civ2(ifield); 740 717 i1_mask=mod(i1-1,par_civ2.NbSlice)+1; 741 718 maskname=fullfile_uvmat(RootPath_mask,SubDir_mask,RootFile_mask,Ext_mask,'_1',i1_mask); … … 747 724 else 748 725 if exist(maskname,'file') 749 try 750 par_civ2.Mask=imread(maskname);%update the mask, an store it for future use 751 catch ME 752 if ~isempty(ME.message) 753 errormsg=['error reading input image: ' ME.message]; 754 disp_uvmat('ERROR',errormsg,checkrun) 755 return 726 try 727 par_civ2.Mask=imread(maskname);%update the mask, an store it for future use 728 catch ME 729 if ~isempty(ME.message) 730 errormsg=['error reading input image: ' ME.message]; 731 disp_uvmat('ERROR',errormsg,checkrun) 732 return 733 end 756 734 end 757 end758 735 else 759 736 par_civ2.Mask=[]; … … 772 749 end 773 750 end 774 par_civ2.SearchBoxShift=(Civ2_Dt/Civ1_Dt)*[Shiftx(nbval>=1)./nbval(nbval>=1) Shifty(nbval>=1)./nbval(nbval>=1)]; 751 par_civ2.SearchBoxShift=zeros(size(par_civ2.Grid)); 752 par_civ2.SearchBoxShift(:,1)=(Civ2_Dt/Civ1_Dt)*Shiftx; 753 par_civ2.SearchBoxShift(:,2)=(Civ2_Dt/Civ1_Dt)*Shifty; 775 754 % shift the grid points by half the expected shift to provide the correlation box position in image A 776 par_civ2.Grid=[par_civ2.Grid(nbval>=1,1)-par_civ2.SearchBoxShift(:,1)/2 par_civ2.Grid(nbval>=1,2)-par_civ2.SearchBoxShift(:,2)/2]; 755 %par_civ2.Grid=[par_civ2.Grid(nbval>=1,1)-par_civ2.SearchBoxShift(:,1)/2 par_civ2.Grid(nbval>=1,2)-par_civ2.SearchBoxShift(:,2)/2]; 756 777 757 if par_civ2.CheckDeformation 778 par_civ2.DUDX =DUDX(nbval>=1)./nbval(nbval>=1);779 par_civ2.DUDY =DUDY(nbval>=1)./nbval(nbval>=1);780 par_civ2.DVDX =DVDX(nbval>=1)./nbval(nbval>=1);781 par_civ2.DVDY =DVDY(nbval>=1)./nbval(nbval>=1);782 end 783 758 par_civ2.DUDX(nbval>0)=DUDX(nbval>0)./nbval(nbval>0); 759 par_civ2.DUDY(nbval>0)=DUDY(nbval>0)./nbval(nbval>0); 760 par_civ2.DVDX(nbval>0)=DVDX(nbval>0)./nbval(nbval>0); 761 par_civ2.DVDY(nbval>0)=DVDY(nbval>0)./nbval(nbval>0); 762 end 763 784 764 % calculate velocity data (y and v in image indices, reverse to y component) 785 786 [ xtable, ytable, utable, vtable, ctable, FF,result_conv,errormsg] = civ (par_civ2);787 765 766 [Data.Civ2_X,Data.Civ2_Y,Data.Civ2_U,Data.Civ2_V,Data.Civ2_C,Data.Civ2_FF,~, errormsg] = civ (par_civ2); 767 788 768 list_param=(fieldnames(Param.ActionInput.Civ2))'; 789 769 list_param(strcmp('TestCiv2',list_param))=[];% remove the parameter TestCiv2 from the list … … 806 786 end 807 787 Data.ListGlobalAttribute=[Data.ListGlobalAttribute Civ2_param]; 808 788 809 789 nbvar=numel(Data.ListVarName); 810 790 % define the Civ2 variable (if Civ2 data are not replaced from previous calculation) … … 819 799 Data.VarAttribute{nbvar+6}.Role='errorflag'; 820 800 end 821 Data.Civ2_X=reshape(xtable,[],1);822 Data.Civ2_Y=reshape(size(par_civ2.ImageA,1)-ytable+1,[],1);823 Data.Civ2_U=reshape(utable,[],1);824 Data.Civ2_V=reshape(-vtable,[],1);825 Data.Civ2_C=reshape(ctable,[],1);826 Data.Civ2_FF=reshape(FF,[],1);827 801 disp('civ2 performed') 828 802 time_civ2=toc(tstart_civ2); … … 837 811 end 838 812 end 839 813 840 814 %% Fix2 841 815 if isfield (Param.ActionInput,'Fix2') … … 847 821 Data.(Fix2_param{ilist})=Param.ActionInput.Fix2.(list_param{ilist}); 848 822 end 849 Data.ListGlobalAttribute=[Data.ListGlobalAttribute Fix2_param]; 823 Data.ListGlobalAttribute=[Data.ListGlobalAttribute Fix2_param]; 850 824 Data.Civ2_FF=double(detect_false(Param.ActionInput.Fix2,Data.Civ2_C,Data.Civ2_U,Data.Civ2_V,Data.Civ2_FF)); 851 825 Data.CivStage=Data.CivStage+1; … … 916 890 disp(['time other ' num2str((time_total-time_input-time_civ1-time_patch1-time_civ2-time_patch2),2) ' s']) 917 891 end 918 end919 end920 921 922 % 'civ': function piv.m adapted from PIVlab http://pivlab.blogspot.com/923 %--------------------------------------------------------------------------924 % function [xtable ytable utable vtable typevector] = civ (image1,image2,ibx,iby step, subpixfinder, mask, roi)925 %926 % OUTPUT:927 % xtable: set of x coordinates928 % ytable: set of y coordinates929 % utable: set of u displacements (along x)930 % vtable: set of v displacements (along y)931 % ctable: max image correlation for each vector932 % typevector: set of flags, =1 for good, =0 for NaN vectors933 %934 %INPUT:935 % par_civ: structure of input parameters, with fields:936 % .ImageA: first image for correlation (matrix)937 % .ImageB: second image for correlation(matrix)938 % .CorrBoxSize: 1,2 vector giving the size of the correlation box in x and y939 % .SearchBoxSize: 1,2 vector giving the size of the search box in x and y940 % .SearchBoxShift: 1,2 vector or 2 column matrix (for civ2) giving the shift of the search box in x and y941 % .CorrSmooth: =1 or 2 determines the choice of the sub-pixel determination of the correlation max942 % .ImageWidth: nb of pixels of the image in x943 % .Dx, Dy: mesh for the PIV calculation944 % .Grid: grid giving the PIV calculation points (alternative to .Dx .Dy): centres of the correlation boxes in Image A945 % .Mask: name of a mask file or mask image matrix itself946 % .MinIma: thresholds for image luminosity947 % .MaxIma948 % .CheckDeformation=1 for subpixel interpolation and image deformation (linear transform)949 % .DUDX: matrix of deformation obtained from patch at each grid point950 % .DUDY951 % .DVDX:952 % .DVDY953 954 function [xtable,ytable,utable,vtable,ctable,FF,result_conv,errormsg] = civ (par_civ)955 956 %% prepare measurement grid957 if isfield(par_civ,'Grid')% grid points set as input, central positions of the sub-images in image A958 if ischar(par_civ.Grid)%read the grid file if the input is a file name (grid in x, y image coordinates)959 par_civ.Grid=dlmread(par_civ.Grid);960 par_civ.Grid(1,:)=[];%the first line must be removed (heading in the grid file)961 end962 % else par_civ.Grid is already an array, no action here963 else% automatic grid in x, y image coordinates964 nbinterv_x=floor((par_civ.ImageWidth-1)/par_civ.Dx);965 gridlength_x=nbinterv_x*par_civ.Dx;966 minix=ceil((par_civ.ImageWidth-gridlength_x)/2);967 nbinterv_y=floor((par_civ.ImageHeight-1)/par_civ.Dy);968 gridlength_y=nbinterv_y*par_civ.Dy;969 miniy=ceil((par_civ.ImageHeight-gridlength_y)/2);970 [GridX,GridY]=meshgrid(minix:par_civ.Dx:par_civ.ImageWidth-1,miniy:par_civ.Dy:par_civ.ImageHeight-1);971 par_civ.Grid(:,1)=reshape(GridX,[],1);972 par_civ.Grid(:,2)=reshape(GridY,[],1);% increases with array index973 %974 % minix=floor(par_civ.Dx/2)-0.5;975 % maxix=minix+par_civ.Dx*floor((par_civ.ImageWidth-1)/par_civ.Dx);976 % miniy=floor(par_civ.Dy/2)-0.5;% first automatic grid point at half the mesh Dy977 % maxiy=minix+par_civ.Dy*floor((par_civ.ImageHeight-1)/par_civ.Dy);978 % [GridX,GridY]=meshgrid(minix:par_civ.Dx:maxix,miniy:par_civ.Dy:maxiy);979 % par_civ.Grid(:,1)=reshape(GridX,[],1);980 % par_civ.Grid(:,2)=reshape(GridY,[],1);% increases with array index981 end982 nbvec=size(par_civ.Grid,1);983 984 %% prepare correlation and search boxes985 ibx2=floor(par_civ.CorrBoxSize(1)/2);986 iby2=floor(par_civ.CorrBoxSize(2)/2);987 isx2=floor(par_civ.SearchBoxSize(1)/2);988 isy2=floor(par_civ.SearchBoxSize(2)/2);989 shiftx=round(par_civ.SearchBoxShift(:,1));%use the input shift estimate, rounded to the next integer value990 shifty=-round(par_civ.SearchBoxShift(:,2));% sign minus because image j index increases when y decreases991 if numel(shiftx)==1% case of a unique shift for the whole field( civ1)992 shiftx=shiftx*ones(nbvec,1);993 shifty=shifty*ones(nbvec,1);994 end995 %TODO: shift the origin by -shift/2996 997 %% Array initialisation and default output if par_civ.CorrSmooth=0 (just the grid calculated, no civ computation)998 xtable=round(par_civ.Grid(:,1)+0.5)-0.5;999 ytable=round(par_civ.ImageHeight-par_civ.Grid(:,2)+0.5)-0.5;% y index corresponding to the position in image coordiantes1000 utable=shiftx;%zeros(nbvec,1);1001 vtable=shifty;%zeros(nbvec,1);1002 ctable=zeros(nbvec,1);1003 FF=zeros(nbvec,1);1004 result_conv=[];1005 errormsg='';1006 1007 %% prepare mask1008 if isfield(par_civ,'Mask') && ~isempty(par_civ.Mask)1009 if strcmp(par_civ.Mask,'all')1010 return % get the grid only, no civ calculation1011 elseif ischar(par_civ.Mask)1012 par_civ.Mask=imread(par_civ.Mask);% read the mask if not allready done1013 end1014 end1015 check_MinIma=isfield(par_civ,'MinIma');% test for image luminosity threshold1016 check_MaxIma=isfield(par_civ,'MaxIma') && ~isempty(par_civ.MaxIma);1017 1018 par_civ.ImageA=sum(double(par_civ.ImageA),3);%sum over rgb component for color images1019 par_civ.ImageB=sum(double(par_civ.ImageB),3);1020 [npy_ima,npx_ima]=size(par_civ.ImageA);1021 if ~isequal(size(par_civ.ImageB),[npy_ima npx_ima])1022 errormsg='image pair with unequal size';1023 return1024 end1025 1026 %% Apply mask1027 % Convention for mask, IDEAS NOT IMPLEMENTED1028 % mask >200 : velocity calculated1029 % 200 >=mask>150;velocity not calculated, interpolation allowed (bad spots)1030 % 150>=mask >100: velocity not calculated, nor interpolated1031 % 100>=mask> 20: velocity not calculated, impermeable (no flux through mask boundaries)1032 % 20>=mask: velocity=01033 checkmask=0;1034 MinA=min(min(par_civ.ImageA));1035 %MinB=min(min(par_civ.ImageB));1036 %check_undefined=false(size(par_civ.ImageA));1037 if isfield(par_civ,'Mask') && ~isempty(par_civ.Mask)1038 checkmask=1;1039 if ~isequal(size(par_civ.Mask),[npy_ima npx_ima])1040 errormsg='mask must be an image with the same size as the images';1041 return1042 end1043 check_undefined=(par_civ.Mask<200 & par_civ.Mask>=20 );1044 end1045 1046 %% compute image correlations: MAINLOOP on velocity vectors1047 corrmax=0;1048 sum_square=1;% default1049 mesh=1;% default1050 CheckDeformation=isfield(par_civ,'CheckDeformation')&& par_civ.CheckDeformation==1;1051 if CheckDeformation1052 mesh=0.25;%mesh in pixels for subpixel image interpolation (x 4 in each direction)1053 par_civ.CorrSmooth=2;% use SUBPIX2DGAUSS (take into account more points near the max)1054 end1055 1056 if par_civ.CorrSmooth~=0 % par_civ.CorrSmooth=0 implies no civ computation (just input image and grid points given)1057 for ivec=1:nbvec1058 iref=round(par_civ.Grid(ivec,1)+0.5);% xindex on the image A for the middle of the correlation box1059 jref=round(par_civ.ImageHeight-par_civ.Grid(ivec,2)+0.5);% j index for the middle of the correlation box in the image A1060 FF(ivec)=0;1061 subrange1_x=iref-ibx2:iref+ibx2;% x indices defining the first subimage1062 subrange1_y=jref-iby2:jref+iby2;% y indices defining the first subimage1063 subrange2_x=iref+shiftx(ivec)-isx2:iref+shiftx(ivec)+isx2;%x indices defining the second subimage1064 subrange2_y=jref+shifty(ivec)-isy2:jref+shifty(ivec)+isy2;%y indices defining the second subimage1065 image1_crop=MinA*ones(numel(subrange1_y),numel(subrange1_x));% default value=min of image A1066 image2_crop=MinA*ones(numel(subrange2_y),numel(subrange2_x));% default value=min of image A1067 check1_x=subrange1_x>=1 & subrange1_x<=par_civ.ImageWidth;% check which points in the subimage 1 are contained in the initial image 11068 check1_y=subrange1_y>=1 & subrange1_y<=par_civ.ImageHeight;1069 check2_x=subrange2_x>=1 & subrange2_x<=par_civ.ImageWidth;% check which points in the subimage 2 are contained in the initial image 21070 check2_y=subrange2_y>=1 & subrange2_y<=par_civ.ImageHeight;1071 image1_crop(check1_y,check1_x)=par_civ.ImageA(subrange1_y(check1_y),subrange1_x(check1_x));%extract a subimage (correlation box) from image A1072 image2_crop(check2_y,check2_x)=par_civ.ImageB(subrange2_y(check2_y),subrange2_x(check2_x));%extract a larger subimage (search box) from image B1073 if checkmask1074 mask1_crop=ones(numel(subrange1_y),numel(subrange1_x));% default value=1 for mask1075 mask2_crop=ones(numel(subrange2_y),numel(subrange2_x));% default value=1 for mask1076 mask1_crop(check1_y,check1_x)=check_undefined(subrange1_y(check1_y),subrange1_x(check1_x));%extract a mask subimage (correlation box) from image A1077 mask2_crop(check2_y,check2_x)=check_undefined(subrange2_y(check2_y),subrange2_x(check2_x));%extract a mask subimage (search box) from image B1078 sizemask=sum(sum(mask1_crop))/(numel(subrange1_y)*numel(subrange1_x));%size of the masked part relative to the correlation sub-image1079 if sizemask > 1/2% eliminate point if more than half of the correlation box is masked1080 FF(ivec)=1; %1081 utable(ivec)=NaN;1082 vtable(ivec)=NaN;1083 else1084 image1_crop=image1_crop.*~mask1_crop;% put to zero the masked pixels (mask1_crop='true'=1)1085 image2_crop=image2_crop.*~mask2_crop;1086 image1_mean=mean(mean(image1_crop))/(1-sizemask);1087 image2_mean=mean(mean(image2_crop))/(1-sizemask);1088 end1089 else1090 image1_mean=mean(mean(image1_crop));1091 image2_mean=mean(mean(image2_crop));1092 end1093 %threshold on image minimum1094 if FF(ivec)==01095 if check_MinIma && (image1_mean < par_civ.MinIma || image2_mean < par_civ.MinIma)1096 FF(ivec)=1;1097 %threshold on image maximum1098 elseif check_MaxIma && (image1_mean > par_civ.MaxIma || image2_mean > par_civ.MaxIma)1099 FF(ivec)=1;1100 end1101 if FF(ivec)==11102 utable(ivec)=NaN;1103 vtable(ivec)=NaN;1104 else1105 %mask1106 if checkmask1107 image1_crop=(image1_crop-image1_mean).*~mask1_crop;%substract the mean, put to zero the masked parts1108 image2_crop=(image2_crop-image2_mean).*~mask2_crop;1109 else1110 image1_crop=(image1_crop-image1_mean);1111 image2_crop=(image2_crop-image2_mean);1112 end1113 %deformation1114 if CheckDeformation1115 xi=(1:mesh:size(image1_crop,2));1116 yi=(1:mesh:size(image1_crop,1))';1117 [XI,YI]=meshgrid(xi-ceil(size(image1_crop,2)/2),yi-ceil(size(image1_crop,1)/2));1118 XIant=XI-par_civ.DUDX(ivec)*XI+par_civ.DUDY(ivec)*YI+ceil(size(image1_crop,2)/2);1119 YIant=YI+par_civ.DVDX(ivec)*XI-par_civ.DVDY(ivec)*YI+ceil(size(image1_crop,1)/2);1120 image1_crop=interp2(image1_crop,XIant,YIant);1121 image1_crop(isnan(image1_crop))=0;1122 xi=(1:mesh:size(image2_crop,2));1123 yi=(1:mesh:size(image2_crop,1))';1124 image2_crop=interp2(image2_crop,xi,yi,'*spline');1125 image2_crop(isnan(image2_crop))=0;1126 end1127 sum_square=sum(sum(image1_crop.*image1_crop));1128 %reference: Oliver Pust, PIV: Direct Cross-Correlation1129 %%%%%% correlation calculation1130 result_conv= conv2(image2_crop,flip(flip(image1_crop,2),1),'valid');1131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%1132 corrmax= max(max(result_conv));1133 1134 %result_conv=(result_conv/corrmax); %normalize, peak=always 2551135 %Find the correlation max, at 2551136 [y,x] = find(result_conv==corrmax,1);1137 subimage2_crop=image2_crop(y:y+2*iby2/mesh,x:x+2*ibx2/mesh);%subimage of image 2 corresponding to the optimum displacement of first image1138 sum_square=sum_square*sum(sum(subimage2_crop.*subimage2_crop));% product of variances of image 1 and 21139 sum_square=sqrt(sum_square);% srt of the variance product to normalise correlation1140 if ~isempty(y) && ~isempty(x)1141 try1142 if par_civ.CorrSmooth==11143 [vector,FF(ivec)] = SUBPIXGAUSS (result_conv,x,y);1144 elseif par_civ.CorrSmooth==21145 [vector,FF(ivec)] = SUBPIX2DGAUSS (result_conv,x,y);1146 else1147 [vector,FF(ivec)] = quadr_fit(result_conv,x,y);1148 end1149 utable(ivec)=vector(1)*mesh+shiftx(ivec);1150 vtable(ivec)=vector(2)*mesh+shifty(ivec);1151 xtable(ivec)=iref+utable(ivec)/2-0.5;% convec flow (velocity taken at the point middle from imgae 1 and 2)1152 ytable(ivec)=jref+vtable(ivec)/2-0.5;% and position of pixel 1=0.5 (convention for image coordinates=0 at the edge)1153 iref=round(xtable(ivec)+0.5);% nearest image index for the middle of the vector1154 jref=round(ytable(ivec)+0.5);1155 % eliminate vectors located in the mask1156 if checkmask && (iref<1 || jref<1 ||iref>npx_ima || jref>npy_ima ||( par_civ.Mask(jref,iref)<200 && par_civ.Mask(jref,iref)>=100))1157 utable(ivec)=0;1158 vtable(ivec)=0;1159 FF(ivec)=1;1160 end1161 ctable(ivec)=corrmax/sum_square;% correlation value1162 catch ME1163 FF(ivec)=1;1164 disp(ME.message)1165 end1166 else1167 FF(ivec)=1;1168 end1169 end1170 end1171 end1172 end1173 result_conv=result_conv*corrmax/sum_square;% keep the last (not normalised) correlation matrix for output1174 1175 %------------------------------------------------------------------------1176 % --- Find the maximum of the correlation function with subpixel resolution1177 % make a fit with a gaussian curve from the three correlation values across the max, along each direction.1178 % OUPUT:1179 % vector = optimum displacement vector with subpixel correction1180 % FF =flag: =0 OK1181 % =1 , max too close to the edge of the search box (1 pixel margin)1182 % INPUT:1183 % result_conv: 2D correlation fct1184 % x,y: position of the maximum correlation at integer values1185 1186 function [vector,FF] = SUBPIXGAUSS (result_conv,x,y)1187 %------------------------------------------------------------------------1188 % vector=[0 0]; %default1189 FF=true;% error flag for vector truncated by the limited search box1190 [npy,npx]=size(result_conv);1191 1192 peaky = y; peakx=x;1193 if y < npy && y > 1 && x < npx-1 && x > 11194 FF=false; % no error by the limited search box1195 max_conv=result_conv(y,x);% max correlation1196 %peak2noise= max(4,max_conv/std(reshape(result_conv,1,[])));% ratio of max conv to standard deviation of correlations (estiamtion of noise level), set to value 4 if it is too low1197 peak2noise=100;% TODO: make this threshold more precise, depending on the image noise1198 result_conv=result_conv*peak2noise/max_conv;% renormalise the correlation with respect to the noise1199 result_conv(result_conv<1)=1; %set to 1 correlation values smaller than 1 (=0 by discretisation, to avoid divergence in the log)1200 1201 f0 = log(result_conv(y,x));1202 f1 = log(result_conv(y-1,x));1203 f2 = log(result_conv(y+1,x));1204 peaky = peaky+ (f1-f2)/(2*f1-4*f0+2*f2);1205 f1 = log(result_conv(y,x-1));1206 f2 = log(result_conv(y,x+1));1207 peakx = peakx+ (f1-f2)/(2*f1-4*f0+2*f2);1208 end1209 1210 vector=[peakx-floor(npx/2)-1 peaky-floor(npy/2)-1];1211 1212 %------------------------------------------------------------------------1213 % --- Find the maximum of the correlation function after interpolation1214 function [vector,FF] = SUBPIX2DGAUSS (result_conv,x,y)1215 %------------------------------------------------------------------------1216 % vector=[0 0]; %default1217 FF=true;1218 peaky=y;1219 peakx=x;1220 [npy,npx]=size(result_conv);1221 if (x < npx) && (y < npy) && (x > 1) && (y > 1)1222 FF=false;1223 max_conv=result_conv(y,x);% max correlation1224 peak2noise= max(4,max_conv/std(reshape(result_conv,1,[])));% ratio of max conv to standard deviation of correlations (estiamtion of noise level), set to value 4 if it is too low1225 result_conv=result_conv*peak2noise/max_conv;% renormalise the correlation with respect to the noise1226 result_conv(result_conv<1)=1; %set to 1 correlation values smaller than 1 (=0 by discretisation, to avoid divergence in the log)1227 for i=-1:11228 for j=-1:11229 %following 15 lines based on H. Nobach and M. Honkanen (2005)1230 % Two-dimensional Gaussian regression for sub-pixel displacement1231 % estimation in particle image velocimetry or particle position1232 % estimation in particle tracking velocimetry1233 % Experiments in Fluids (2005) 38: 511-5151234 c10(j+2,i+2)=i*log(result_conv(y+j, x+i));1235 c01(j+2,i+2)=j*log(result_conv(y+j, x+i));1236 c11(j+2,i+2)=i*j*log(result_conv(y+j, x+i));1237 c20(j+2,i+2)=(3*i^2-2)*log(result_conv(y+j, x+i));1238 c02(j+2,i+2)=(3*j^2-2)*log(result_conv(y+j, x+i));1239 end1240 end1241 c10=(1/6)*sum(sum(c10));1242 c01=(1/6)*sum(sum(c01));1243 c11=(1/4)*sum(sum(c11));1244 c20=(1/6)*sum(sum(c20));1245 c02=(1/6)*sum(sum(c02));1246 deltax=(c11*c01-2*c10*c02)/(4*c20*c02-c11*c11);1247 deltay=(c11*c10-2*c01*c20)/(4*c20*c02-c11*c11);1248 if abs(deltax)<11249 peakx=x+deltax;1250 end1251 if abs(deltay)<11252 peaky=y+deltay;1253 end1254 end1255 vector=[peakx-floor(npx/2)-1 peaky-floor(npy/2)-1];1256 1257 %------------------------------------------------------------------------1258 % --- Find the maximum of the correlation function after quadratic interpolation1259 function [vector,F] = quadr_fit(result_conv,x,y)1260 [npy,npx]=size(result_conv);1261 if x<4 || y<4 || npx-x<4 ||npy-y <41262 F=1;1263 vector=[x y];1264 else1265 F=0;1266 x_ind=x-4:x+4;1267 y_ind=y-4:y+4;1268 x_vec=0.25*(x_ind-x);1269 y_vec=0.25*(y_ind-y);1270 [X,Y]=meshgrid(x_vec,y_vec);1271 coord=[reshape(X,[],1) reshape(Y,[],1)];1272 result_conv=reshape(result_conv(y_ind,x_ind),[],1);1273 1274 1275 % n=numel(X);1276 % x=[X Y];1277 % X=X-0.5;1278 % Y=Y+0.5;1279 % y = (X.*X+2*Y.*Y+X.*Y+6) + 0.1*rand(n,1);1280 p = polyfitn(coord,result_conv,2);1281 A(1,1)=2*p.Coefficients(1);1282 A(1,2)=p.Coefficients(2);1283 A(2,1)=p.Coefficients(2);1284 A(2,2)=2*p.Coefficients(4);1285 vector=[x y]'-A\[p.Coefficients(3) p.Coefficients(5)]';1286 vector=vector'-[floor(npx/2) floor(npy/2)]-1 ;1287 % zg = polyvaln(p,coord);1288 % figure1289 % surf(x_vec,y_vec,reshape(zg,9,9))1290 % hold on1291 % plot3(X,Y,reshape(result_conv,9,9),'o')1292 % hold off1293 end1294 1295 1296 function FF=detect_false(Param,C,U,V,FFIn)1297 FF=FFIn;%default, good vectors1298 % FF=1, for correlation max at edge, not set in this function1299 % FF=2, for too small correlation1300 % FF=3, for velocity outside bounds1301 % FF=4 for exclusion by difference with the smoothed field, set by call to function filter_tps1302 1303 if isfield (Param,'MinCorr')1304 FF(C<Param.MinCorr & FFIn==0)=2;1305 end1306 if (isfield(Param,'MinVel')&&~isempty(Param.MinVel))||(isfield (Param,'MaxVel')&&~isempty(Param.MaxVel))1307 Umod= U.*U+V.*V;1308 if isfield (Param,'MinVel')&&~isempty(Param.MinVel)1309 U2Min=Param.MinVel*Param.MinVel;1310 FF(Umod<U2Min & FFIn==0)=3;1311 end1312 if isfield (Param,'MaxVel')&&~isempty(Param.MaxVel)1313 U2Max=Param.MaxVel*Param.MaxVel;1314 FF(Umod>U2Max & FFIn==0)=3;1315 892 end 1316 893 end … … 1378 955 end 1379 956 1380 1381 1382 957 function FF=detect_false(Param,C,U,V,FFIn) 958 FF=FFIn;%default, good vectors 959 % FF=1, for correlation max at edge, not set in this function 960 % FF=2, for too small correlation 961 % FF=3, for velocity outside bounds 962 % FF=4 for exclusion by difference with the smoothed field, set by call to function filter_tps 963 964 if isfield (Param,'MinCorr') 965 FF(C<Param.MinCorr & FFIn==0)=2; 966 end 967 if (isfield(Param,'MinVel')&&~isempty(Param.MinVel))||(isfield (Param,'MaxVel')&&~isempty(Param.MaxVel)) 968 Umod= U.*U+V.*V; 969 if isfield (Param,'MinVel')&&~isempty(Param.MinVel) 970 U2Min=Param.MinVel*Param.MinVel; 971 FF(Umod<U2Min & FFIn==0)=3; 972 end 973 if isfield (Param,'MaxVel')&&~isempty(Param.MaxVel) 974 U2Max=Param.MaxVel*Param.MaxVel; 975 FF(Umod>U2Max & FFIn==0)=3; 976 end 977 end 978 979 980 -
trunk/src/series/extract_multitif.m
r1149 r1163 85 85 ParamOut.OutputDirExt='.png';%set the output dir extension 86 86 ParamOut.OutputFileMode='NbSlice';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice 87 ParamOut.CheckOverwriteVisible='on'; % manage the overwrite of existing files (default= 1)87 ParamOut.CheckOverwriteVisible='on'; % manage the overwrite of existing files (default='off') 88 88 ParamOut.CPUTime=10;% expected time for writting the output of one source image ( in minute) 89 89 %% root input file(s) and type 90 90 91 % check the existence of the first file in the series 91 first_j=[];% note that the function will propose to cover the whole range of indices 92 if isfield(Param.IndexRange,'MinIndex_j'); first_j=Param.IndexRange.MinIndex_j; end 92 first_j=[];% note that the function will propose to cover the whole range of indices 93 if isfield(Param.IndexRange,'MinIndex_j') 94 first_j=Param.IndexRange.MinIndex_j; 95 else 96 msgbox_uvmat('ERROR',['select a multitif file labeled by a number, like im@0001.tif ']) 97 return 98 end 93 99 PairString=''; 94 100 if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end … … 99 105 msgbox_uvmat('WARNING',['the first input file ' FirstFileName ' does not exist']) 100 106 end 101 ParamOut.NbSlice=Param.IndexRange.MaxIndex_i; 102 %% check the validity of input file types 103 FileInfo=get_file_info(FirstFileName); 104 if ~strcmp(FileInfo.FileType,'multimage') 107 FileInfo=get_file_info(FirstFileName); 108 if ~strcmp(FileInfo.FileType,'multimage')%check the validity of input file types 105 109 msgbox_uvmat('ERROR',['invalid file type input: ' FileInfo.FileType ' not a tiff image series']) 106 110 return 107 111 end 112 113 ParamOut.NbSlice=Param.IndexRange.MaxIndex_i; 114 108 115 ParamOut.ActionInput.XmlFile=uigetfile_uvmat('pick xml file for timing',fileparts(fileparts(FirstFileName)),'.xml'); 109 116 return -
trunk/src/series/extract_rdvision.m
r1161 r1163 71 71 ParamOut.ProjObject='off';...%can use projection object(option 'off'/'on', 72 72 ParamOut.Mask='off';...%can use mask option (option 'off'/'on', 'off' by default) 73 ParamOut.CPUTime=0.1;% expected time for writting one image ( in minute) 73 ParamOut.CheckOverwriteVisible='on'; % manage the overwrite of existing files (default=1) 74 ParamOut.CPUTime=0.25;% expected time for writting one image ( in minute) 74 75 ParamOut.OutputDirExt='.extract';%set the output dir extension 75 76 ParamOut.OutputSubDirMode='one'; %output folder given by the folder name of the first input line … … 159 160 timestamp(ii)=m.Data(ii).timestamp; 160 161 end 162 163 % 164 % %%%%%BRICOLAGE EXP40 165 % ind1=5*59-10; 166 % ind2=12*59-10; 167 % ind3=119*59-10; 168 % ind4=483*59-10; 169 % timestamp=[timestamp(1:ind4) timestamp(ind4) timestamp(ind4+1:end)]; 170 % timestamp=[timestamp(1:ind3) timestamp(ind3) timestamp(ind3+1:end)]; 171 % timestamp=[timestamp(1:ind2) timestamp(ind2) timestamp(ind2+1:end)]; 172 % timestamp=[timestamp(1:ind1) timestamp(ind1) timestamp(ind1+1:end)]; 173 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%% 174 175 161 176 if ParamOut.ActionInput.Createxml 162 177 ParamOut.ActionInput.XmlData.Camera.BurstTiming=time2xmlburst(timestamp,ParamOut.ActionInput.BurstLength); … … 174 189 difftime=timestamp-timexml; 175 190 %if max(difftime)>0.01 191 176 192 figure 177 193 plot(timestamp,difftime) … … 367 383 end 368 384 369 [BinList,errormsg]=binread_rdv_series(RootPath,SeqData,m.Data,nbfield2,NomTypeNew,Param.IndexRange.first_i,Param.IndexRange.last_i );385 [BinList,errormsg]=binread_rdv_series(RootPath,SeqData,m.Data,nbfield2,NomTypeNew,Param.IndexRange.first_i,Param.IndexRange.last_i,Param.CheckOverwrite); 370 386 if ~isempty(errormsg) 371 387 disp_uvmat('ERROR',errormsg,checkrun) … … 387 403 388 404 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 389 function [BinList,errormsg]=binread_rdv_series(PathDir,SeqData,SqbData,nbfield2,NomTypeNew,first,last )405 function [BinList,errormsg]=binread_rdv_series(PathDir,SeqData,SqbData,nbfield2,NomTypeNew,first,last,checkoverwrite) 390 406 % BINREAD_RDV Permet de lire les fichiers bin g???n???r???s par Hiris ??? partir du 391 407 % fichier seq associ???. … … 442 458 bin_file_counter=0; 443 459 %for ii=1:SeqData.nb_frames 460 %%%%%BRICOLAGE EXP40 461 ind1=5*59-10; 462 ind2=12*59-10; 463 ind3=119*59-10; 464 ind4=483*59-10; 465 444 466 for ii=first:last 445 467 j1=[]; 468 iinew=ii; 469 % %%%%%BRICOLAGE EXP40 470 % switch ii 471 % case ii>=ind1 && ii<ind2 472 % iinew=ii+1; 473 % case ii>=ind2 && ii<ind3 474 % iinew=ii+2; 475 % case ii>=ind3 && ii<ind4 476 % iinew=ii+3; 477 % case ii>=ind4 && ii<ind3 478 % iinew=ii+4; 479 % end 480 % %%%%%%%%% 446 481 if ~isequal(nbfield2,1) 447 j1=mod(ii-1,nbfield2)+1; 448 end 449 i1=floor((ii-1)/nbfield2)+1; 482 j1=mod(iinew-1,nbfield2)+1; 483 end 484 i1=floor((iinew-1)/nbfield2)+1; 485 450 486 OutputFile=fullfile_uvmat(PathDir,FileDir,'img','.png',NomTypeNew,i1,[],j1);% TODO: set NomTypeNew from SeqData.mode 451 487 fname=fullfile(binrepertoire,sprintf('%s%.5d.bin',SeqData.binfile,SqbData(ii).file_idx)); 452 if exist(OutputFile,'file')% do not recreate existing image file488 if ~checkoverwrite && exist(OutputFile,'file') % manage the overwrite of existing files (default=1) % manage the overwrite of existing files (default=1)exist(OutputFile,'file')% do not recreate existing image file 453 489 fid=0; 454 490 else -
trunk/src/uvmat.m
r1162 r1163 2063 2063 set(hhseries.ActionName,'Value',index_action); 2064 2064 series('ActionName_Callback',hObject,[],hhseries); %file input with xml reading in uvmat, show the image in phys coordinates 2065 series('ActionInput_Callback',hObject,[],hhseries); %open the menu or options from INPUT in series 2065 2066 end 2066 2067
Note: See TracChangeset
for help on using the changeset viewer.