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

relabel_i_j , sub_field_series improved

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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)
Note: See TracChangeset for help on using the changeset viewer.