Changeset 245 for trunk/src/series


Ignore:
Timestamp:
Apr 20, 2011, 12:52:35 PM (14 years ago)
Author:
sommeria
Message:

relabel_i_j , sub_field_series improved

Location:
trunk/src/series
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/series/calc_background.m

    r239 r245  
    182182%         ifile=indselect(ifield);
    183183        filename=name_generator(filebase,num_i1(ifile),num_j1(ifile),Series.FileExt,Series.NomType)
    184         Aread=read_image(filename,FileType,num_i1(ifile),MovieObject);
     184        try
     185            Aread=read_image(filename,FileType,num_i1(ifile),MovieObject);
     186        catch ME
     187            msgbox_uvmat('ERROR',ME.message)
     188            return
     189        end
    185190        Ak(:,:,ifile)=Aread;
    186191            %finish the waitbar
  • trunk/src/series/relabel_i_j.m

    r223 r245  
    1 
    2 % relabel_i_j: relabel an image series with two indices, and correct errors from the RDvision transfer program
     1%'relabel_i_j': relabel an image series with two indices, and correct errors from the RDvision transfer program
    32%----------------------------------------------------------------------
    43function GUI_input=relabel_i_j(num_i1,num_i2,num_j1,num_j2,Series)
     
    2625end
    2726basename=fullfile(RootPath{1},RootFile{1});
    28 [XmlData,warntext]=imadoc2struct([basename '.xml']);% read the xml file appended to the present function (containing bug corrections)
     27[XmlData,warntext]=imadoc2struct([basename '.xml'])% read the xml file appended to the present function (containing bug corrections)
    2928if ~isempty(warntext)
    3029    msgbox_uvmat('ERROR',warntext)%error message for xml file reading
     
    3231nbfield1=size(XmlData.Time,1);
    3332nbfield2=size(XmlData.Time,2);
    34 
    3533set(hseries.first_i,'String',num2str(first_label))% display the first image in the process
    3634set(hseries.last_i,'String',num2str(nbfield1*nbfield2-1+first_label))% display the last image in the process
     
    3836SeriesData=get(hGUI,'UserData');
    3937if ~strcmp(SeriesData.NomType,'_000001')
    40     msgbox_uvmat('WARNING','the input is not a file from RDvision: this function relabel_i_j has no action')%error message for directory creation
     38    msgbox_uvmat('WARNING','the input is not a file from RDvision: this function relabel_i_j has no action');%error message for directory creation
    4139    return
    4240else
    43     msgbox_uvmat('CONFIRMATION','this function will relabel the file series from RDvision and correct the xml file')%error message for directory creation
     41    answer=msgbox_uvmat('','this function will relabel the file series from RDvision and correct the xml file');%error message for directory creation
     42    if ~strcmp(answer,'Yes')
     43        return
     44    end
    4445end
    4546
     
    4849    return
    4950end
    50 answer=msgbox_uvmat('CONFIRMATION',[num2str(nbfield1) ' bursts containing ' num2str(nbfield2) ' images each']);%error message for directory creation
     51if nbfield2>=2
     52answer=msgbox_uvmat('',[num2str(nbfield1) ' bursts containing ' num2str(nbfield2) ' images each']);%error message for directory creation
     53nomtype='_i_j';
     54else
     55    answer=msgbox_uvmat('',['image series with ' num2str(nbfield1) ' images']);%error message for directory creation
     56    nomtype='_i';
     57end
     58if ~strcmp(answer,'Yes')
     59    return
     60end
    5161
    5262%% copy and adapt the xml file
     
    5464    try
    5565    copyfile([basename '.xml'],[basename '.xml~']);% backup the xml file
    56     catch
    57     errormsg=lasterr
    58             msgbox_uvmat('ERROR',errormsg);
     66    catch ME
     67            msgbox_uvmat('ERROR',ME.message);
    5968            return
    6069    end
     
    8190   
    8291    %%%% correction RDvision %%%%
     92    if isfield(XmlData,'NbDtj')
    8393    uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
    8494    uid_value=children(t,uid_NbDtj);
     
    8696        t=set(t,uid_value(1),'value',num2str(XmlData.NbDtj));
    8797    end
     98    end
     99    if isfield(XmlData,'NbDtk')
    88100    uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
    89101    uid_value=children(t,uid_NbDtk);
     
    91103        t=set(t,uid_value(1),'value',num2str(XmlData.NbDtk));
    92104    end
     105    end
     106    if strcmp(nomtype,'_i') && isfield(XmlData,'NbDti')
     107        uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
     108        uid_value=children(t,uid_NbDti);
     109        if ~isempty(uid_value)
     110            t=set(t,uid_value(1),'value',num2str(XmlData.NbDti));
     111        end
     112        uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
     113        uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
     114        t=delete(t,uid_NbDtj);
     115        t=delete(t,uid_NbDtk);
     116        uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj');
     117        uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk');
     118        t=delete(t,uid_Dtj);
     119        t=delete(t,uid_Dtk);   
     120    end
    93121    %%%
    94122   
     
    97125
    98126%% main loop
     127
    99128for ifile=1:nbfield1*nbfield2
    100129    update_waitbar(hseries.waitbar,WaitbarPos,ifile/(nbfield1*nbfield2))
     
    102131    num_j=mod(ifile-1+first_label,nbfield2)+1;
    103132    num_i=floor((ifile-1+first_label)/nbfield2)+1;
    104     filename_new=name_generator(basename,num_i,num_j,'.png','_i_j');
     133    filename_new=name_generator(basename,num_i,num_j,'.png',nomtype);
    105134    try
    106135        movefile(filename,filename_new);
     
    115144        return
    116145    end
    117     %     if test_level
    118     %         A=imread(filename);
    119     %         C=levels(A);
    120     %         imwrite(C,filename_new)
    121     %     else
    122     %         try
    123     %             copyfile(filename,filename_new);
    124     %         catch
    125     %             errormsg=lasterr
    126     %             msgbox_uvmat('ERROR',errormsg);
    127     %             return
    128     %         end
    129     %     end
    130 end
    131 
    132 
    133 function C=levels(A)
    134 %whos A;
    135 B=double(A(:,:,1));
    136 windowsize=round(min(size(B,1),size(B,2))/20);
    137 windowsize=floor(windowsize/2)*2+1;
    138 ix=[1/2-windowsize/2:-1/2+windowsize/2];%
    139 %del=np/3;
    140 %fct=exp(-(ix/del).^2);
    141 fct2=cos(ix/(windowsize-1)/2*pi/2);
    142 %Mfiltre=(ones(5,5)/5^2);
    143 %Mfiltre=fct2';
    144 Mfiltre=fct2'*fct2;
    145 Mfiltre=Mfiltre/(sum(sum(Mfiltre)));
    146 
    147 C=filter2(Mfiltre,B);
    148 C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize);
    149 C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize);
    150 C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:);
    151 C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:);
    152 C=tanh(B./(2*C));
    153 [n,c]=hist(reshape(C,1,[]),100);
    154 % figure;plot(c,n);
    155 
    156 [m,i]=max(n);
    157 c_max=c(i);
    158 [dummy,index]=sort(abs(c-c(i)));
    159 n=n(index);
    160 c=c(index);
    161 i_select = find(cumsum(n)<0.95*sum(n));
    162 if isempty(i_select)
    163     i_select = 1:length(c);
    164 end
    165 c_select=c(i_select);
    166 n_select=n(i_select);
    167 cmin=min(c_select);
    168 cmax=max(c_select);
    169 C=(C-cmin)/(cmax-cmin)*256;
    170 C=uint8(C);
     146end
     147
    171148
    172149%'imadoc2struct': reads the xml file for image documentation
     
    256233                NbDtj=get_value(subt,'/BurstTiming/NbDtj',1);
    257234                %%%% correction RDvision %%%%
    258                 NbDtj=NbDtj/numel(Dtj);
    259                 s.NbDtj=NbDtj;
    260                 %%%%
    261                 Dti=get_value(subt,'/BurstTiming/Dti',[]);
     235%                 NbDtj=NbDtj/numel(Dtj);
     236%                 s.NbDtj=NbDtj;
     237%                 %%%%
     238                Dti=get_value(subt,'/BurstTiming/Dti',[])
     239                NbDti=get_value(subt,'/BurstTiming/NbDti',1)
     240                 %%%% correction RDvision %%%%
     241                if isempty(Dti)% series
     242                     Dti=Dtj
     243                      NbDti=NbDtj
     244                     Dtj=[];
     245                     s.Dti=Dti;
     246                     'TESTrxml'
     247                     s.NbDti=NbDti
     248                else
     249                     NbDtj=NbDtj/numel(Dtj);%bursts
     250                    s.NbDtj=NbDtj;
     251                end
     252                %%%% %%%%
    262253                Dti=Dti/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
    263                 NbDti=get_value(subt,'/BurstTiming/NbDti',1);
     254
    264255                Time_val=get_value(subt,'/BurstTiming/Time',0);%time in TimeUnit
    265256                if ~isempty(Dti)
  • trunk/src/series/sub_field_series.m

    r240 r245  
    6868itime=0;
    6969NbSlice_calib={}; %test for z index
    70 for iview=1:nbview%Loop on views
     70for iview=1:nbview%Loop on views (nbview=2)
    7171    XmlData{iview}=[];%default
    7272    filebase{iview}=fullfile(Series.RootPath{iview},Series.RootFile{iview});
     73    testxml(iview)=0;% test for xml file
    7374    if exist([filebase{iview} '.xml'],'file')
     75        testxml(iview)=1;
    7476        [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']);
    7577        if isfield(XmlData{iview},'Time')
     
    146148FieldName='';
    147149if strcmp(get(hseries.FieldMenu,'Visible'),'on')
    148 Field_str=get(hseries.FieldMenu,'String');
    149 val=get(hseries.FieldMenu,'Value');
    150 FieldName=Field_str(val);%the same set of fields for all views
    151 VelType_str=get(hseries.VelTypeMenu,'String');
    152 VelType_val=get(hseries.VelTypeMenu,'Value');
    153 VelType=VelType_str{VelType_val}; %the same for all views
    154 if strcmp(FieldName,'')
    155     msgbox_uvmat('ERROR','no input field defined in FieldMenu')
    156 elseif strcmp(FieldName,'get_field...')
    157     hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI
    158     SubField=get_field('read_get_field',hObject,eventdata,hget_field); %read the names of the variables to plot in the get_field GUI
    159 end
     150    Field_str=get(hseries.FieldMenu,'String');
     151    val=get(hseries.FieldMenu,'Value');
     152    FieldName=Field_str(val);%the same set of fields for all views
     153    VelType_str=get(hseries.VelTypeMenu,'String');
     154    VelType_val=get(hseries.VelTypeMenu,'Value');
     155    VelType=VelType_str{VelType_val}; %the same for all views
     156    if strcmp(FieldName,'')
     157        msgbox_uvmat('ERROR','no input field defined in FieldMenu')
     158    elseif strcmp(FieldName,'get_field...')
     159        hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI
     160        SubField=get_field('read_get_field',hObject,eventdata,hget_field); %read the names of the variables to plot in the get_field GUI
     161    end
    160162end
    161163%detect whether all the files are 'images' or 'netcdf'
     
    187189    testcivx=testnc;
    188190end
     191if nbview~=2
     192    msgbox_uvmat('ERROR','this function needs two input series as input')
     193    return
     194elseif testima
     195    answer=msgbox_uvmat('CONFIRMATION','this function will substract each of the second image series from the first one');
     196    if ~isequal(answer,'Yes')
     197        return
     198    end
     199else
     200    answer=msgbox_uvmat('CONFIRMATION','this function will substract each the second field series from the first one');
     201    if ~isequal(answer,'Yes')
     202        return
     203    end
     204end
     205
    189206
    190207%% name of output files and directory:
     
    193210RootPath=get(hseries.RootPath,'String');
    194211SubDir=get(hseries.SubDir,'String');
    195 if isequal(length(RootPath),1)
    196     fulldir=RootPath{1};
    197     subdir='merge_proj';
    198     res_subdir=fullfile(fulldir,subdir);
    199 else
    200     def={fullfile(ProjectDir,'0_RESULTS')};
    201     dlgTitle='result directory';
    202     lineNo=1;
    203     answer=msgbox_uvmat('INPUT_TXT',dlgTitle,def);
    204     fulldir=answer{1};
    205     subdir=[];
    206     dirlist=sort(Series.RootFile);
    207     for iview=1:nbview
    208         if ~isempty(subdir)
    209             subdir=[subdir '-'];
    210         end
    211         subdir=[subdir dirlist{iview}];
    212     end 
    213     res_subdir=fullfile(fulldir,subdir);
    214 end
     212def={fullfile(ProjectDir,'0_RESULTS')};
     213dlgTitle='result directory';
     214lineNo=1;
     215answer=msgbox_uvmat('INPUT_TXT',dlgTitle,def);
     216fulldir=answer{1};
     217subdir=[];
     218dirlist=sort(Series.RootFile);
     219for iview=1:nbview
     220    if ~isempty(subdir)
     221        subdir=[subdir '-'];
     222    end
     223    subdir=[subdir dirlist{iview}];
     224end 
     225res_subdir=fullfile(fulldir,subdir);
     226
    215227ext=FileExt{1};
    216228if ~exist(fulldir,'dir')
     
    236248end
    237249filebasesub=fullfile(res_subdir,Series.RootFile{1});
    238 filebase_merge=fullfile(res_subdir,'merged');%root name for the merged files
     250filebase_merge=fullfile(res_subdir,'sub');%root name for the merged files
     251 if testxml(1) && ( isempty(transform_fct)|| isequal(transform_fct,'px'))
     252        copyfile([filebase{1} '.xml'],[filebase_merge '.xml'])% reproduce the xml file
     253        display([filebase_merge '.xml copied from ' filebase{1} '.xml'])
     254    end
    239255
    240256%% MAIN LOOP
     
    321337            mergename=name_generator(filebase_merge,num_i1{1}(ifile),num_j1{1}(ifile),'.png',Series.NomType{1},1,num_i2{1}(ifile),num_j2{1}(ifile));
    322338             if isa(Field{1}.A,'uint8')
    323                 imwrite(uint8(MergeData.A),mergename,'BitDepth',8);
     339                imwrite(uint8(MergeData.A),mergename,'BitDepth',8); % transform in integers (and put to 0 the negative values)
    324340             elseif isa(Field{1}.A,'uint16')
    325341                 imwrite(uint16(MergeData.A),mergename,'BitDepth',16);
    326342             end
    327 %             imwrite(MergeData.A,mergename,'BitDepth',bitdepth);
    328             %write xml calibration file
    329             siz=size(MergeData.A);
    330             npy=siz(1);
    331             npx=siz(2);
    332             if isfield(MergeData,'VarAttribute')&&isfield(MergeData.VarAttribute{1},'Coord_2')&&isfield(MergeData.VarAttribute{1},'Coord_1')
    333                 Rangx=MergeData.VarAttribute{1}.Coord_2;
    334                 Rangy=MergeData.VarAttribute{1}.Coord_1;
    335             elseif isfield(MergeData,'AX')&& isfield(MergeData,'AY')
    336                 Rangx=[MergeData.AX(1) MergeData.AX(end)];
    337                 Rangy=[MergeData.AY(1) MergeData.AY(end)];
    338             else
    339                 Rangx=[0.5 npx-0.5];
    340                 Rangy=[npy-0.5 0.5];%default
    341             end
    342             pxcmx=(npx-1)/(Rangx(2)-Rangx(1));
    343             pxcmy=(npy-1)/(Rangy(1)-Rangy(2));
    344             T_x=-pxcmx*Rangx(1)+0.5;
    345             T_y=-pxcmy*Rangy(2)+0.5;
    346             GeometryCal.focal=1;
    347             GeometryCal.R=[pxcmx,0,0;0,pxcmy,0;0,0,1];
    348             GeometryCal.Tx_Ty_Tz=[T_x T_y 1];
    349             ImaDoc.GeometryCalib=GeometryCal;
    350             t=struct2xml(ImaDoc);
    351             t=set(t,1,'name','ImaDoc');
    352             save(t,[filebase_merge '.xml'])     
    353             display([filebase_merge '.xml saved'])
     343             display(['output image ' mergename ' written'])
    354344        else
    355345            mergename=name_generator(filebase_merge,num_i1{1}(ifile),num_j1{1}(ifile),'.nc',Series.NomType{1},1,num_i2{1}(ifile),num_j2{1}(ifile));
     
    381371    end
    382372end
    383 
    384 %'merge_field': concatene fields
    385 %------------------------------------------------------------------------
    386 function MergeData=merge_field(Data)
    387 %% default output
    388 if isempty(Data)||~iscell(Data)
    389     MergeData=[];
    390     return
    391 end
    392 MergeData=Data{1};%default
    393 error=0;
    394 nbview=length(Data);
    395 if nbview==1
    396     return
    397 end
    398 
    399 %% group the variables (fields of 'FieldData') in cells of variables with the same dimensions
    400 [CellVarIndex,NbDim,VarTypeCell]=find_field_indices(Data{1});
    401 %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
    402 % CellVarIndex=cells of variable index arrays
    403 ivar_new=0; % index of the current variable in the projected field
    404 for icell=1:length(CellVarIndex)
    405     if NbDim(icell)==1
    406         continue
    407     end
    408     VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
    409     VarType=VarTypeCell{icell};
    410     ivar_X=VarType.coord_x;
    411     ivar_Y=VarType.coord_y;
    412     ivar_FF=VarType.errorflag;
    413     if isempty(ivar_X)
    414         test_grid=1;%test for input data on regular grid (e.g. image)coordinates
     373%write xml calibration file
     374if testima && ~isempty(transform_fct) && ~isequal(transform_fct,'px')
     375    siz=size(MergeData.A);
     376    npy=siz(1);
     377    npx=siz(2);
     378    if isfield(MergeData,'VarAttribute')&&isfield(MergeData.VarAttribute{1},'Coord_2')&&isfield(MergeData.VarAttribute{1},'Coord_1')
     379        Rangx=MergeData.VarAttribute{1}.Coord_2;
     380        Rangy=MergeData.VarAttribute{1}.Coord_1;
     381    elseif isfield(MergeData,'AX')&& isfield(MergeData,'AY')
     382        Rangx=[MergeData.AX(1) MergeData.AX(end)];
     383        Rangy=[MergeData.AY(1) MergeData.AY(end)];
    415384    else
    416         if length(ivar_Y)~=1
    417                 msgbox_uvmat('ERROR','y coordinate missing in proj_field.m')
    418                 return
    419         end
    420         test_grid=0;
    421     end
    422     %case of input fields with unstructured coordinates
    423     if ~test_grid
    424         for ivar=VarIndex
    425             VarName=MergeData.ListVarName{ivar};
    426             for iview=1:nbview
    427                 eval(['MergeData.' VarName '=[MergeData.' VarName '; Data{iview}.' VarName '];'])
    428             end
    429         end
    430     %case of fields defined on a structured  grid
    431     else 
    432         testFF=0;
    433         for iview=2:nbview
    434             for ivar=VarIndex
    435                 VarName=MergeData.ListVarName{ivar};
    436                 if isfield(MergeData,'VarAttribute')
    437                     if length(MergeData.VarAttribute)>=ivar && isfield(MergeData.VarAttribute{ivar},'Role') && isequal(MergeData.VarAttribute{ivar}.Role,'errorflag')
    438                         testFF=1;
    439                     end
    440                 end
    441                 eval(['MergeData.' VarName '=MergeData.' VarName '+ Data{iview}.' VarName ';'])
    442             end
    443         end
    444         if testFF
    445             nbaver=nbview-MergeData.FF;
    446             indgood=find(nbaver>0);
    447             for ivar=VarIndex
    448                 VarName=MergeData.ListVarName{ivar};
    449                 eval(['MergeData.' VarName '(indgood)=double(MergeData.' VarName '(indgood))./nbaver(indgood);'])
    450             end
    451         else
    452             for ivar=VarIndex
    453                 VarName=MergeData.ListVarName{ivar};
    454                 eval(['MergeData.' VarName '=double(MergeData.' VarName ')./nbview;'])
    455             end   
    456         end
    457     end
    458 end
     385        Rangx=[0.5 npx-0.5];
     386        Rangy=[npy-0.5 0.5];%default
     387    end
     388    pxcmx=(npx-1)/(Rangx(2)-Rangx(1));
     389    pxcmy=(npy-1)/(Rangy(1)-Rangy(2));
     390    T_x=-pxcmx*Rangx(1)+0.5;
     391    T_y=-pxcmy*Rangy(2)+0.5;
     392    GeometryCal.focal=1;
     393    GeometryCal.R=[pxcmx,0,0;0,pxcmy,0;0,0,1];
     394    GeometryCal.Tx_Ty_Tz=[T_x T_y 1];
     395    ImaDoc.GeometryCalib=GeometryCal;
     396    t=struct2xml(ImaDoc);
     397    t=set(t,1,'name','ImaDoc');
     398    save(t,[filebase_merge '.xml'])
     399    display([filebase_merge '.xml saved'])
     400end
Note: See TracChangeset for help on using the changeset viewer.