Changeset 227 for trunk/src/civ.m


Ignore:
Timestamp:
Mar 31, 2011, 1:42:51 PM (13 years ago)
Author:
sommeria
Message:

add function sub_field_series to apply the sub_field operation to a series of fileds (for instance subtracting a background to an image series)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/civ.m

    r225 r227  
    123123    catch
    124124        errormsg={' Unable to read the file PARAM.xml defining the civx binaries:'; lasterr};
     125        return
    125126    end
    126127else
    127128    errormsg=[xmlfile ' not found: path to civx binaries undefined'];
     129    return
    128130end
    129131
     
    13211323set(gcf,'Pointer','arrow')
    13221324
    1323 %------------------------------------------------------------------------
    1324 %  determine the list of index pairs of processing file
    1325 function [num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
    1326     find_pair_indices(handles,mode)
    1327 %------------------------------------------------------------------------
    1328 first_i=str2double(get(handles.first_i,'String'));%first index i
    1329 last_i=str2double(get(handles.last_i,'String'));%last index i
    1330 incr=str2double(get(handles.incr_i,'String'));% increment
    1331 num_i=first_i:incr:last_i;% list of i indices (reference values for each pair)
    1332 if isequal(get(handles.first_j,'Visible'),'on')
    1333     first_j=str2double(get(handles.first_j,'String'));%first index j
    1334     last_j=str2double(get(handles.last_j,'String'));%last index j
    1335     incr_j=str2double(get(handles.incr_j,'String'));% increment
    1336 else
    1337     first_j=1;
    1338     last_j=1;
    1339     incr_j=1;
    1340 end
    1341 num_j=[first_j:incr_j:last_j];% list of j indices (reference values for each pair)
    1342 list_civ1=get(handles.list_pair_civ1,'String');
    1343 index_civ1=get(handles.list_pair_civ1,'Value');
    1344 str_civ1=list_civ1{index_civ1};%string defining the image pairs for civ1
    1345 if isempty(str_civ1)||isequal(str_civ1,'')
    1346     msgbox_uvmat('ERROR','no image pair selected for civ1')
    1347     return
    1348 end
    1349 list_civ2=get(handles.list_pair_civ2,'String');
    1350 index_civ2=get(handles.list_pair_civ2,'Value');
    1351 if index_civ2>length(list_civ2)
    1352     list_civ2=list_civ1;
    1353     index_civ2=index_civ1;
    1354 end
    1355 str_civ2=list_civ2{index_civ2};%string defining the image pairs for civ2
    1356 if isempty(first_i)||isempty(first_j), msgbox_uvmat('ERROR','first field number not defined'),...
    1357         return,end;
    1358 if isequal(last_i,[])|| isequal(last_j,[]),msgbox_uvmat('ERROR','last field number not defined'),...
    1359         return,end;
    1360 if isequal(incr,[])|| isequal(incr_j,[]),msgbox_uvmat('ERROR','increment in field number not defined'),...
    1361         return,end;
    1362 if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
    1363         return,end;
    1364 if isequal (mode,'series(Di)')
    1365     %recognize the pair civ1 from the display
    1366     indsel=find((double(str_civ1)<48)|(double(str_civ1)>57));% character indices of non numerical characters
    1367     str_raw=str_civ1(indsel);
    1368     indsepar=find(str_raw=='|'); %character index of the separator
    1369     d1=str2double(str_civ1(indsel(indsepar-1)+1:indsel(indsepar)-1));
    1370     if indsepar==length(str_raw)
    1371         d2=str2double(str_civ1(indsel(indsepar)+1:end));
    1372     else
    1373         d2=str2double(str_civ1(indsel(indsepar)+1:indsel(indsepar+1)-1));
    1374     end
    1375     num1_civ1=num_i-d1;% set of first image numbers
    1376     num2_civ1=num_i+d2;
    1377     num_a_civ1=num_j;
    1378     num_b_civ1=num_j;
    1379    
    1380     %recognize the pair civ2 from the display
    1381     indsel=find((double(str_civ2)<48)|(double(str_civ2)>57));% character indices of non numerical characters
    1382     str_raw=str_civ2(indsel);
    1383     indsepar=find(str_raw=='|'); %character index of the separator
    1384     d1=str2double(str_civ2(indsel(indsepar-1)+1:indsel(indsepar)-1));
    1385     if indsepar==length(str_raw)
    1386         d2=str2double(str_civ2(indsel(indsepar)+1:end));
    1387     else
    1388         d2=str2double(str_civ2(indsel(indsepar)+1:indsel(indsepar+1)-1));
    1389     end
    1390     if isnan(d1)
    1391         num1_civ2=num_i;
    1392     else
    1393         num1_civ2=num_i-d1;% set of first image numbers
    1394     end
    1395     if isnan(d2)
    1396         num2_civ2=num_i;
    1397     else
    1398         num2_civ2=num_i+d2;
    1399     end
    1400     num_a_civ2=num_j;
    1401     num_b_civ2=num_j;
    1402    
    1403     % adjust the first and last field number
    1404     lastfield=str2double(get(handles.nb_field,'String'));
    1405     if isequal(lastfield,[])
    1406         indsel=find((num1_civ1 >= 1)&(num1_civ2 >= 1));
    1407     else
    1408         indsel=find((num2_civ1 <= lastfield)&(num2_civ2 <= lastfield)&(num1_civ1 >= 1)&(num1_civ2 >= 1));
    1409     end
    1410     if length(indsel)>=1
    1411         firstind=indsel(1);
    1412         lastind=indsel(end);
    1413         set(handles.first_i,'String',num2str(num_i(firstind)))%update the display of first and last fields
    1414         set(handles.last_i,'String',num2str(num_i(lastind)))
    1415         num_i=num_i(indsel);
    1416         num1_civ1=num1_civ1(indsel);
    1417         num1_civ2=num1_civ2(indsel);
    1418         num2_civ1=num2_civ1(indsel);
    1419         num2_civ2=num2_civ2(indsel);
    1420     end
    1421 elseif isequal (mode,'series(Dj)')
    1422     lastfield_j=str2double(get(handles.nb_field2,'String'));
    1423     num1_civ1=num_i;% set of first image numbers
    1424     num2_civ1=num_i;
    1425     num_a_civ1=num_j-floor(index_civ1/2)*ones(size(num_j));
    1426     num_b_civ1=num_j+ceil(index_civ1/2)*ones(size(num_j));
    1427     num1_civ2=num_i;
    1428     num2_civ2=num_i;
    1429     num_a_civ2=num_j-floor(index_civ2/2)*ones(size(num_j));
    1430     num_b_civ2=num_j+ceil(index_civ2/2)*ones(size(num_j));
    1431     % adjust the first and last field number
    1432     if isnan(lastfield_j)
    1433         indsel=find((num_a_civ1 >= 1)&(num_a_civ2 >= 1));
    1434     else
    1435         indsel=find((num_b_civ1 <= lastfield_j)&(num_b_civ2 <= lastfield_j)&(num_a_civ1 >= 1)&(num_a_civ2 >= 1));
    1436     end
    1437     if length(indsel)>=1
    1438         firstind=indsel(1);
    1439         lastind=indsel(end);
    1440         set(handles.first_j,'String',num2str(num_j(firstind)))%update the display of first and last fields
    1441         set(handles.last_j,'String',num2str(num_j(lastind)))
    1442         num_j=num_j(indsel);
    1443         num_a_civ1=num_a_civ1(indsel);
    1444         num_a_civ2=num_a_civ2(indsel);
    1445         num_b_civ1=num_b_civ1(indsel);
    1446         num_b_civ2=num_b_civ2(indsel);
    1447     end
    1448 elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)
    1449     num1_civ1=num_i;
    1450     num1_civ2=num_i;
    1451     displ_num=get(handles.list_pair_civ1,'UserData');
    1452     num2_civ1=num_i;
    1453     num_a_civ1=displ_num(1,index_civ1);
    1454     num_b_civ1=displ_num(2,index_civ1);
    1455     num2_civ2=num_i;
    1456     num_a_civ2=displ_num(1,index_civ2);
    1457     num_b_civ2=displ_num(2,index_civ2);
    1458 elseif isequal(mode,'displacement')
    1459     num1_civ1=num_i;
    1460     num2_civ1=num_i;
    1461     num_a_civ1=num_j;
    1462     num_b_civ1=num_j;
    1463     num1_civ2=num_i;
    1464     num2_civ2=num_i;
    1465     num_a_civ2=num_j;
    1466     num_b_civ2=num_j;
    1467 end
     1325
    14681326
    14691327
     
    15861444status_Callback(hObject, eventdata, handles)
    15871445end
     1446
    15881447%------------------------------------------------------------------------
    15891448% --- Lauch command called by RUN and BATCH: remote processing
     
    16451504%% set the list of files and check them
    16461505display('checking the files...')
     1506[ref_i,ref_j,errormsg]=find_ref_indices(handles);
     1507if ~isempty(errormsg)
     1508    msgbox_uvmat('ERROR',errormsg)
     1509    return
     1510end
    16471511[filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc]=...
    1648     set_civ_filenames(handles,box_test);
     1512    set_civ_filenames(handles,ref_i,ref_j,box_test);
    16491513set(handles.civ,'UserData',filecell);%store for futur use of status callback
    16501514if isempty(filecell)% (error message displayed in fct set_civ_filenames)
     
    16531517nbfield=numel(num1_civ1);
    16541518nbslice=numel(num_a_civ1);
    1655 
    16561519
    16571520%% read names of the .exe files for PIV and patch
     
    22482111        else       %run PIVlab if selected
    22492112            image1=imread(par_civ1.filename_ima_a);
    2250             image2=imread(par_civ1.filename_ima_b);         
    2251                [xtable ytable utable vtable ctable typevector] = pivlab (image1,image2,str2num(par_civ1.ibx), str2num(par_civ1.dx), 1, [], []);
     2113            image2=imread(par_civ1.filename_ima_b);     
     2114            stepx=str2num(par_civ1.dx);
     2115            stepy=str2num(par_civ1.dy);
     2116            ibx2=ceil(str2num(par_civ1.ibx)/2);
     2117            iby2=ceil(str2num(par_civ1.iby)/2);
     2118            isx2=ceil(str2num(par_civ1.isx)/2);
     2119            isy2=ceil(str2num(par_civ1.isy)/2);
     2120            shiftx=str2num(par_civ1.shiftx);
     2121            shifty=str2num(par_civ1.shifty);
     2122%             ibx=2*ibx2-1;%ibx and iby odd, reduced by 1 if even
     2123%             iby=2*iby2-1;
     2124            miniy=max(1+isy2-shifty,1+iby2);
     2125            minix=max(1+isx2-shiftx,1+ibx2);
     2126            maxiy=min(size(image1,1)-isy2-shifty,size(image1,1)-iby2);
     2127            maxix=min(size(image1,2)-isx2-shiftx,size(image1,2)-ibx2);
     2128%             maxix=stepx*(floor(size(image1_roi,2)/stepx))-(2*ibx2-2)+ibx2;
     2129            [GridX,GridY]=meshgrid(miniy:stepy:maxiy,minix:stepx:maxix);
     2130            PointCoord(:,1)=reshape(GridX,[],1);
     2131            PointCoord(:,2)=reshape(GridY,[],1);
     2132               [xtable ytable utable vtable ctable typevector] = pivlab (image1,image2,ibx2,iby2,isx2,isy2,shiftx,shifty,PointCoord, 1, []);
    22522133               Data.ListGlobalAttribute={'title','Time','Dt'};
    22532134               Data.title='PIVlab';
     
    23122193saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
    23132194
    2314 
    2315 
    2316 
     2195%------------------------------------------------------------------------
     2196% --- determine the list of reference indices of processing file
     2197function [ref_i,ref_j,errormsg]=find_ref_indices(handles)
     2198%------------------------------------------------------------------------
     2199errormsg=''; %default error message
     2200first_i=str2double(get(handles.first_i,'String'));%first index i
     2201last_i=str2double(get(handles.last_i,'String'));%last index i
     2202incr_i=str2double(get(handles.incr_i,'String'));% increment
     2203if isequal(get(handles.first_j,'Visible'),'on')
     2204    first_j=str2double(get(handles.first_j,'String'));%first index j
     2205    last_j=str2double(get(handles.last_j,'String'));%last index j
     2206    incr_j=str2double(get(handles.incr_j,'String'));% increment
     2207else
     2208    first_j=1;
     2209    last_j=1;
     2210    incr_j=1;
     2211end
     2212ref_i=first_i:incr_i:last_i;% list of i indices (reference values for each pair)
     2213ref_j=first_j:incr_j:last_j;% list of j indices (reference values for each pair)
     2214if isnan(first_i)||isnan(first_j)
     2215    errormsg='first field number not defined';
     2216elseif isnan(last_i)||isnan(last_j)
     2217    errormsg='last field number not defined';
     2218elseif isnan(incr_i)||isnan(incr_j)
     2219    errormsg='increment in field number not defined';
     2220elseif last_i < first_i || last_j < first_j
     2221    errormsg='last field number must be larger than the first one';
     2222end
     2223
     2224%------------------------------------------------------------------------
     2225% --- determine the list of filenames and indices needed for launch_job
    23172226function [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,file_ref_fix1,file_ref_fix2]=...
    2318     set_civ_filenames(handles,box_test)
     2227    set_civ_filenames(handles,ref_i,ref_j,box_test)
    23192228%------------------------------------------------------------------------
    23202229filecell=[];%default
     
    23512260if isempty(nom_type_nc),nom_type_nc='_i1-i2';end; %default
    23522261[num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
    2353     find_pair_indices(handles,mode);
     2262    find_pair_indices(handles,ref_i,ref_j,mode);
    23542263%determine the new filebase for 'displacement' mode (comparison of two series)
    23552264filebase_B=filebase;% root name of the second field series for stereo
     
    30342943
    30352944%------------------------------------------------------------------------
     2945% --- determine the list of index pairs of processing file
     2946function [num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
     2947    find_pair_indices(handles,ref_i,ref_j,mode)
     2948%------------------------------------------------------------------------
     2949
     2950list_civ1=get(handles.list_pair_civ1,'String');
     2951index_civ1=get(handles.list_pair_civ1,'Value');
     2952str_civ1=list_civ1{index_civ1};%string defining the image pairs for civ1
     2953if isempty(str_civ1)||isequal(str_civ1,'')
     2954    msgbox_uvmat('ERROR','no image pair selected for civ1')
     2955    return
     2956end
     2957list_civ2=get(handles.list_pair_civ2,'String');
     2958index_civ2=get(handles.list_pair_civ2,'Value');
     2959if index_civ2>length(list_civ2)
     2960    list_civ2=list_civ1;
     2961    index_civ2=index_civ1;
     2962end
     2963str_civ2=list_civ2{index_civ2};%string defining the image pairs for civ2
     2964
     2965if isequal (mode,'series(Di)')
     2966    lastfield=str2double(get(handles.nb_field,'String'));
     2967    num1_civ1=ref_i-floor(index_civ1/2)*ones(size(ref_i));% set of first image numbers
     2968    num2_civ1=ref_i+ceil(index_civ1/2)*ones(size(ref_i));
     2969    num_a_civ1=ref_j;
     2970    num_b_civ1=ref_j;
     2971    num1_civ2=ref_i-floor(index_civ2/2)*ones(size(ref_i));;
     2972    num2_civ2=ref_i+ceil(index_civ2/2)*ones(size(ref_i));
     2973    num_a_civ2=ref_j;
     2974    num_b_civ2=ref_j;   
     2975   
     2976    % adjust the first and last field number
     2977    lastfield=str2double(get(handles.nb_field,'String'));
     2978    if isnan(lastfield)
     2979        indsel=find((num1_civ1 >= 1)&(num1_civ2 >= 1));
     2980    else
     2981        indsel=find((num2_civ1 <= lastfield)&(num2_civ2 <= lastfield)&(num1_civ1 >= 1)&(num1_civ2 >= 1));
     2982    end
     2983    if length(indsel)>=1
     2984        firstind=indsel(1);
     2985        lastind=indsel(end);
     2986        set(handles.first_i,'String',num2str(ref_i(firstind)))%update the display of first and last fields
     2987        set(handles.last_i,'String',num2str(ref_i(lastind)))
     2988        ref_i=ref_i(indsel);
     2989        num1_civ1=num1_civ1(indsel);
     2990        num1_civ2=num1_civ2(indsel);
     2991        num2_civ1=num2_civ1(indsel);
     2992        num2_civ2=num2_civ2(indsel);
     2993    end
     2994elseif isequal (mode,'series(Dj)')
     2995    lastfield_j=str2double(get(handles.nb_field2,'String'));
     2996    num1_civ1=ref_i;% set of first image numbers
     2997    num2_civ1=ref_i;
     2998    num_a_civ1=ref_j-floor(index_civ1/2)*ones(size(ref_j));
     2999    num_b_civ1=ref_j+ceil(index_civ1/2)*ones(size(ref_j));
     3000    num1_civ2=ref_i;
     3001    num2_civ2=ref_i;
     3002    num_a_civ2=ref_j-floor(index_civ2/2)*ones(size(ref_j));
     3003    num_b_civ2=ref_j+ceil(index_civ2/2)*ones(size(ref_j));
     3004    % adjust the first and last field number
     3005    if isnan(lastfield_j)
     3006        indsel=find((num_a_civ1 >= 1)&(num_a_civ2 >= 1));
     3007    else
     3008        indsel=find((num_b_civ1 <= lastfield_j)&(num_b_civ2 <= lastfield_j)&(num_a_civ1 >= 1)&(num_a_civ2 >= 1));
     3009    end
     3010    if length(indsel)>=1
     3011        firstind=indsel(1);
     3012        lastind=indsel(end);
     3013        set(handles.first_j,'String',num2str(ref_j(firstind)))%update the display of first and last fields
     3014        set(handles.last_j,'String',num2str(ref_j(lastind)))
     3015        ref_j=ref_j(indsel);
     3016        num_a_civ1=num_a_civ1(indsel);
     3017        num_b_civ1=num_b_civ1(indsel);
     3018        num_a_civ2=num_a_civ2(indsel);
     3019        num_b_civ2=num_b_civ2(indsel);
     3020    end
     3021elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)
     3022    displ_num=get(handles.list_pair_civ1,'UserData');
     3023    num1_civ1=ref_i;
     3024    num2_civ1=ref_i;
     3025    num_a_civ1=displ_num(1,index_civ1);
     3026    num_b_civ1=displ_num(2,index_civ1);
     3027    num1_civ2=ref_i;
     3028    num2_civ2=ref_i;
     3029    num_a_civ2=displ_num(1,index_civ2);
     3030    num_b_civ2=displ_num(2,index_civ2);
     3031elseif isequal(mode,'displacement')
     3032    num1_civ1=ref_i;
     3033    num2_civ1=ref_i;
     3034    num_a_civ1=ref_j;
     3035    num_b_civ1=ref_j;
     3036    num1_civ2=ref_i;
     3037    num2_civ2=ref_i;
     3038    num_a_civ2=ref_j;
     3039    num_b_civ2=ref_j;
     3040end
     3041
     3042
     3043%------------------------------------------------------------------------
    30363044% --- PATCH
    30373045function cmd_PATCH=PATCH_CMD(filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,test_interp,PatchBin)
     
    45964604test_civ1=get(handles.TestCiv1,'Value');
    45974605if test_civ1
     4606    ref_i=str2double(get(handles.ref_i,'String'));
     4607    if strcmp(get(handles.ref_j,'Visible'),'on')
     4608        ref_j=str2double(get(handles.ref_j,'String'));
     4609    else
     4610        ref_j=1;%default
     4611    end
    45984612    [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,file_ref_fix1,file_ref_fix2]=...
    4599         set_civ_filenames(handles,[1 0 0 0 0 0]);
     4613        set_civ_filenames(handles,ref_i,ref_j,[1 0 0 0 0 0]);
    46004614    Data.ListVarName={'ny','nx','A'};
    46014615    Data.VarDimName={'ny','nx',{'ny','nx'}};
     
    46034617    Data.ny=[size(Data.A,1) 1];
    46044618    Data.nx=[1 size(Data.A,2)];
     4619    par_civ1=read_param_civ1(handles,filecell.ima1.civ1{1});
     4620   
     4621            stepx=str2num(par_civ1.dx);
     4622            stepy=str2num(par_civ1.dy);
     4623            ibx2=ceil(str2num(par_civ1.ibx)/2);
     4624            iby2=ceil(str2num(par_civ1.iby)/2);
     4625            isx2=ceil(str2num(par_civ1.isx)/2);
     4626            isy2=ceil(str2num(par_civ1.isy)/2);
     4627            shiftx=str2num(par_civ1.shiftx);
     4628            shifty=str2num(par_civ1.shifty);
     4629%             ibx=2*ibx2-1;%ibx and iby odd, reduced by 1 if even
     4630%             iby=2*iby2-1;
     4631            miniy=max(1+isy2-shifty,1+iby2);
     4632            minix=max(1+isx2-shiftx,1+ibx2);
     4633            maxiy=min(size(image1,1)-isy2-shifty,size(image1,1)-iby2);
     4634            maxix=min(size(image1,2)-isx2-shiftx,size(image1,2)-ibx2);
     4635%             maxix=stepx*(floor(size(image1_roi,2)/stepx))-(2*ibx2-2)+ibx2;
     4636            [GridX,GridY]=meshgrid(miniy:stepy:maxiy,minix:stepx:maxix);
     4637            PointCoord(:,1)=reshape(GridX,[],1);
     4638            PointCoord(:,2)=reshape(GridY,[],1);
    46054639    hh=view_field(Data);
     4640    set(0,'CurrentFigure',hh)
     4641    plot(PointCoord(:,2),PointCoord(:,1),'+')
    46064642    ViewData=get(hh,'UserData');
    46074643    ViewData.axes3.B=imread(filecell.ima2.civ1{1});%store the second image in the UserData of the GUI view_field
     
    46524688filecell=get(handles.civ,'UserData');
    46534689if ~isfield(filecell,'nc')
    4654     filecell=set_civ_filenames(handles,box_test);%determine the list of output files expected from the GUI status
     4690    [ref_i,ref_j,errormsg]=find_ref_indices(handles);
     4691    if ~isempty(errormsg)
     4692        msgbox_uvmat('ERROR',errormsg)
     4693        return
     4694    end
     4695    filecell=set_civ_filenames(handles,ref_i,ref_j,box_test);%determine the list of output files expected from the GUI status
    46554696end
    46564697
Note: See TracChangeset for help on using the changeset viewer.