Changeset 826


Ignore:
Timestamp:
Nov 23, 2014, 10:52:03 AM (6 years ago)
Author:
sommeria
Message:

extract_rdvision updated to treat all cameras at once

Location:
trunk/src/series
Files:
2 edited

Legend:

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

    r810 r826  
    6262    ParamOut.ProjObject='off';%can use projection object(option 'off'/'on',
    6363    ParamOut.Mask='off';%can use mask option   (option 'off'/'on', 'off' by default)
    64     ParamOut.OutputDirExt='';%set the output dir extension (blank=no output dir)
     64    ParamOut.OutputSubDirMode='none'; %(options 'none'/'custom'/'auto'/'first'/'last','auto' by default)
     65    %                      'none' =no output files
    6566    return
    6667end
  • trunk/src/series/extract_rdvision.m

    r824 r826  
    7070    ParamOut.ProjObject='off';...%can use projection object(option 'off'/'on',
    7171    ParamOut.Mask='off';...%can use mask option   (option 'off'/'on', 'off' by default)
    72     ParamOut.OutputSubDir=Param.InputTable{1,3};
    73     ParamOut.OutputDirExt='';%set the output dir extension
    74     if size(Param.InputTable,1)>1
    75         msgbox_uvmat('WARNING', 'this function acts only on the first input file line')
    76     end
     72    ParamOut.OutputSubDirMode='custom'; %output folder given by the program, not by the GUI series
     73     % detect the set of image folder
     74    RootPath=Param.InputTable{1,1};
     75    ListStruct=dir(RootPath);   
     76    ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
     77    check_bad=strcmp('.',ListCells(1,:))|strcmp('..',ListCells(1,:));%detect the dir '.' to exclude it
     78    check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
     79    ListDir=ListCells(1,find(check_dir & ~check_bad));
     80    InputTable=cell(numel(ListDir),5);
     81    InputTable(:,2)=ListDir';
     82    for ilist=1:numel(ListDir)
     83        InputTable{ilist,1}=RootPath;
     84        ListStructSub=dir(fullfile(RootPath,ListDir{ilist}));
     85        ListCellSub=struct2cell(ListStructSub);% transform dir struct to a cell arrray
     86        detect_seq=regexp(ListCellSub(1,:),'.seq$');
     87        seq_index=find(~cellfun('isempty',detect_seq),1);
     88        if isempty(seq_index)
     89            msgbox_uvmat('ERROR',['not seq file in ' ListDir{ilist} ': please check the input folders'])
     90        else
     91            RootFile=regexprep(ListCellSub{1,seq_index},'.seq$','');
     92            InputTable{ilist,3}=RootFile;
     93        end
     94        InputTable{ilist,4}='*';
     95        InputTable{ilist,5}='.seq';
     96    end
     97    hseries=findobj(allchild(0),'Tag','series');% find the parent GUI 'series'
     98    hhseries=guidata(hseries); %handles of the elements in 'series'
     99    set(hhseries.InputTable,'Data',InputTable)
     100    ParamOut.ActionInput.LogPath=RootPath;% indicate the path for the output info: 0_LOG ....
    77101return
    78102end
     
    91115
    92116%% root input file(s) and type
    93 RootPath=Param.InputTable(:,1);
    94 RootFile=Param.InputTable(:,3);
    95 SubDir=Param.InputTable(:,2);
    96 FileExt=Param.InputTable(:,5);
     117RootPath=Param.InputTable{1,1};
     118if ~isempty(find(~strcmp(RootPath,Param.InputTable(:,1))))% if the Rootpath for each camera are not identical
     119    disp_uvmat('ERROR','Rootpath for all cameras must be identical',checkrun)
     120    return
     121end
    97122
    98123% get the set of input file names (cell array filecell), and the lists of
    99124% input file or frame indices i1_series,i2_series,j1_series,j2_series
    100125[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
    101 filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},'*',1);
    102 OutputDir=[Param.OutputSubDir Param.OutputDirExt];
     126
     127%OutputDir=[Param.OutputSubDir Param.OutputDirExt];
    103128 
    104129% numbers of slices and file indices
     
    108133
    109134%determine the file type on each line from the first input file
    110 % if ~exist(filecell{1,1}','file')
    111 %     msgbox_uvmat('ERROR',['the first input file ' filecell{1,1} ' does not exist'])
    112 %     return
    113 % end
     135
    114136FileInfo=get_file_info(filecell{1,1});
    115 if ~strcmp(FileInfo.FileType,'rdvision')
     137if strcmp(FileInfo.FileType,'rdvision')
     138    if ~isequal(FileInfo.NumberOfFrames,nbfield)
     139        msgbox_uvmat('ERROR',['the whole series of ' num2str(FileInfo.NumberOfFrames) ' images must be extracted at once'])
     140        %rmfield(OutputDir)
     141        return
     142    end
     143    %% interactive input of specific parameters (for RDvision system)
     144    display('converting images from RDvision system...')
     145else
    116146    msgbox_uvmat('ERROR','the input is not from rdvision: a .seq or .sqb file must be opened')
    117147    return
    118148end
    119 if exist(fullfile(RootPath{1},OutputDir),'dir')
    120      msgbox_uvmat('ERROR',['output folder ' OutputDir ' already exists, put data in a new folder Experiment']);
    121      return
    122 end
     149t=xmltree;
     150save(t,fullfile(RootPath,'Running.xml'))%create an xml file to indicate that processing takes place
    123151
    124152%% calibration data and timing: read the ImaDoc files
     
    128156NbSlice_calib={};
    129157
    130 SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
    131 filexml=[fullfile(RootPath{1},RootFile{1}) '.xml'];%new convention: xml at the level of the image folder
    132 if ~exist(filexml,'file')
    133     disp_uvmat('ERROR',[filexml ' missing'],checkrun)
     158%SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
     159
     160%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     161%%%  loop on the cameras ( #iview)
     162%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     163for iview=1:size(Param.InputTable,1)
     164    filexml=[fullfile(RootPath,Param.InputTable{iview,3}) '.xml'];%new convention: xml at the level of the image folder
     165    if ~exist(filexml,'file')
     166        disp_uvmat('ERROR',[filexml ' missing'],checkrun)
     167        return
     168    end
     169    [XmlData,error]=imadoc2struct_special(filexml);
     170    if isfield(XmlData,'Time')
     171        itime=itime+1;
     172        timecell{itime}=XmlData.Time;
     173    end
     174    if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
     175        NbSlice_calib{1}=size(XmlData.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
     176        if ~isequal(NbSlice_calib{1},NbSlice_calib{1})
     177            msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
     178        end
     179    end
     180   
     181   
     182    % correction to RDvision xml file
     183    t=xmltree(filexml);
     184   
     185    % correct Dtj and Dtk
     186    NomTypeNew='_1_1';% new file nomencalture by default
     187    ImageName='img_1_1.png';% first image name
     188    if isfield(XmlData,'NbDtj')
     189        uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
     190        uid_value=children(t,uid_NbDtj);
     191        if ~isempty(uid_value)
     192            t=set(t,uid_value(1),'value',num2str(XmlData.NbDtj));
     193        end
     194    end
     195    if isfield(XmlData,'NbDtk')
     196        uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
     197        uid_value=children(t,uid_NbDtk);
     198        if ~isempty(uid_value)
     199            t=set(t,uid_value(1),'value',num2str(XmlData.NbDtk));
     200        end
     201    end
     202    if isempty(j1_series{1}) && isfield(XmlData,'NbDti')
     203        uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti');
     204        t=add(t,uid_Dti,'chardata',num2str(XmlData.Dti));
     205        uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
     206        t=add(t,uid_NbDti,'chardata',num2str(XmlData.NbDti));
     207        uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
     208        uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
     209        t=delete(t,uid_NbDtj);
     210        t=delete(t,uid_NbDtk);
     211        uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj');
     212        uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk');
     213        t=delete(t,uid_Dtj);
     214        t=delete(t,uid_Dtk);
     215        NomTypeNew='_1';
     216        ImageName='img_1.png';
     217    end
     218   
     219    %update information of 'Heading'
     220    uid_Heading=find(t,'ImaDoc/Heading');
     221    if isempty(uid_Heading)
     222        [t,uid_Heading]=add(t,1,'element','Heading');
     223    end
     224    uid_SubCampaign=find(t,'ImaDoc/Heading/SubCampaign');
     225    if ~isempty(uid_SubCampaign), t=delete(t,uid_SubCampaign); end
     226    uid_Experiment=find(t,'ImaDoc/Heading/Experiment');
     227    if ~isempty(uid_Experiment), t=delete(t,uid_Experiment); end
     228    uid_Device=find(t,'ImaDoc/Heading/Device');
     229    if ~isempty(uid_Device), t=delete(t,uid_Device); end
     230    uid_Record=find(t,'ImaDoc/Heading/Record');
     231    if ~isempty(uid_Record), t=delete(t,uid_Record); end
     232    uid_DateExp=find(t,'ImaDoc/Heading/DateExp');
     233    if ~isempty(uid_DateExp), t=delete(t,uid_DateExp); end
     234   
     235    %indicate the name of the first image (as a check that the xml file is not moved)
     236    uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
     237    if isempty(uid_ImageName)
     238        [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
     239    end
     240    uid_value=children(t,uid_ImageName);
     241    if isempty(uid_value)
     242        t=add(t,uid_ImageName,'chardata',ImageName);%indicate  name of the first image, with ;png extension
     243    else
     244        t=set(t,uid_value(1),'value',ImageName);%indicate  name of the first image, with ;png extension
     245    end
     246   
     247    %indicate the date and time of the image acquisition start
     248    % if isfield(FileInfo,'binrepertoire') && isfield(FileInfo,'starttime')
     249    %     sep_pos=regexp(FileInfo.binrepertoire,'T');
     250    %     DateTime=FileInfo.starttime;
     251    %     if ~isempty(sep_pos)
     252    %         DateTime=[FileInfo.binrepertoire(1:sep_pos-1) ' ' DateTime];
     253    %     end
     254    %     uid_DateTime=find(t,'ImaDoc/Heading/DateTime');
     255    %     if isempty(uid_DateTime)
     256    %         [t,uid_DateTime]=add(t,uid_Heading,'element','DateTime');
     257    %     end
     258    %     uid_value=children(t,uid_DateTime);
     259    %     if isempty(uid_value)
     260    %         t=add(t,uid_DateTime,'chardata',DateTime);%indicate  name of the first image, with ;png extension
     261    %     else
     262    %         t=set(t,uid_value(1),'value',DateTime);%indicate  name of the first image, with ;png extension
     263    %     end
     264    % end
     265   
     266    %% backup the previous xml file and save the corrected one
     267    [success,message]=copyfile(filexml,[filexml '~']);%make backup
     268    if success~=1
     269        dips(['errror in xml file backup: ' message]);
     270        return
     271    end
     272    save(t,filexml)
     273    nbfield2=1;
     274    if isfield(XmlData,'Time')
     275        nbfield2=size(XmlData.Time,2);
     276    end
     277   
     278    %% get the names of .seq and .sqb files
     279    switch Param.InputTable{iview,5}
     280        case {'.seq','.sqb'}
     281            filename_seq=fullfile(RootPath,Param.InputTable{iview,2},[Param.InputTable{iview,3} '.seq']);
     282            filename_sqb=fullfile(RootPath,Param.InputTable{iview,2},[Param.InputTable{iview,3} '.sqb']);
     283        otherwise
     284            errormsg='input file extension must be .seq or .sqb';
     285    end
     286    if ~exist(filename_seq,'file')
     287        errormsg=[filename_seq ' does not exist'];
     288        return
     289    end
     290   
     291    %% get data from .seq file
     292    s=ini2struct(filename_seq);
     293    SeqData=s.sequenceSettings;
     294    SeqData.width=str2double(SeqData.width);
     295    SeqData.height=str2double(SeqData.height);
     296    SeqData.bytesperpixel=str2double(SeqData.bytesperpixel);
     297    SeqData.nb_frames=str2double(s.sequenceSettings.numberoffiles);
     298    if isempty(SeqData.binrepertoire)%used when binrepertoire empty, strange feature of rdvision
     299        SeqData.binrepertoire=regexprep(s.sequenceSettings.bindirectory,'\\$','');%tranform Windows notation to Linux
     300        SeqData.binrepertoire=regexprep(SeqData.binrepertoire,'\','/');
     301        [tild,binrepertoire,DirExt]=fileparts(SeqData.binrepertoire);
     302        SeqData.binrepertoire=[SeqData.binrepertoire DirExt];
     303    end
     304%     PathDir=fileparts(PathDir);
     305   
     306    %% reading the .sqb file
     307    m = memmapfile(filename_sqb,'Format', { 'uint32' [1 1] 'offset'; ...
     308        'uint32' [1 1] 'garbage1';...
     309        'double' [1 1] 'timestamp';...
     310        'uint32' [1 1] 'file_idx';...
     311        'uint32' [1 1] 'garbage2' },'Repeat',SeqData.nb_frames);
     312    %%%%%%%BRICOLAGE in case of unreadable .sqb file
     313    %     ind=[60 63:152];%indices of bin files
     314    %     lengthimage=w*h*bpp;% lengthof an image record on the binary file
     315    %     for ii=1:32*numel(ind)
     316    %         data(ii).offset=mod(ii-1,32)*2*lengthimage+lengthimage;%Dalsa_2
     317    %         %data(ii).offset=mod(ii-1,32)*2*lengthimage;%Dalsa_1
     318    %         data(ii).file_idx=ind(ceil(ii/32));
     319    %         data(ii).timestamp=0.2*(ii-1);
     320    %     end
     321    %%%%%%%
     322    for ii=1: numel(m.Data)
     323        timestamp(ii)=m.Data(ii).timestamp;
     324    end
     325    timestamp %todo: check withDt from the xml file
     326    [BinSize,errormsg]=binread_rdv_series(RootPath,SeqData,m.Data,nbfield2,NomTypeNew)
     327    if ~isempty(errormsg)
     328        disp_uvmat('ERROR',errormsg,checkrun)
     329        return
     330    end
     331end
     332delete(fullfile(RootPath,'Running.xml'))%delete the  xml file to indicate that processing is finished
     333
     334%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     335%--------- reads a series of bin files
     336%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     337function [BinSize,errormsg]=binread_rdv_series(PathDir,SeqData,SqbData,nbfield2,NomTypeNew)
     338% BINREAD_RDV Permet de lire les fichiers bin générés par Hiris à partir du
     339% fichier seq associé.
     340%   [IMGS,TIMESTAMPS,NB_FRAMES] = BINREAD_RDV(FILENAME,FRAME_IDX) lit
     341%   l'image d'indice FRAME_IDX de la séquence FILENAME.
     342%
     343%   Entrées
     344%   -------
     345%   FILENAME  : Nom du fichier séquence (.seq).
     346%   FRAME_IDX : Indice de l'image à lire. Si FRAME_IDX vaut -1 alors la
     347%   séquence est entièrement lue. Si FRAME_IDX est un tableau d'indices
     348%   alors toutes les images d'incides correspondant sont lues. Si FRAME_IDX
     349%   est un tableau vide alors aucune image n'est lue mais le nombre
     350%   d'images et tous les timestamps sont renvoyés. Les indices commencent à
     351%   1 et se termines à NB_FRAMES.
     352%
     353%   Sorties
     354%   -------
     355%   IMGS        : Images de sortie.
     356%   TIMESTAMPS  : Timestaps des images lues.
     357%   NB_FRAMES   : Nombres d'images dans la séquence.
     358NbBinFile=0;
     359BinSize=0;
     360errormsg='';
     361classname=sprintf('uint%d',SeqData.bytesperpixel*8);
     362
     363classname=['*' classname];
     364BitDepth=8*SeqData.bytesperpixel;%needed to write images (8 or 16 bits)
     365binrepertoire=fullfile(PathDir,SeqData.binrepertoire);
     366tic
     367OutputDir=fullfile(PathDir,SeqData.sequencename)
     368if exist(OutputDir,'dir')
     369    errormsg=[OutpuDir ' already exist, delete it first'];
    134370    return
    135371end
    136 [XmlData,error]=imadoc2struct_special(filexml);
    137 if isfield(XmlData,'Time')
    138     itime=itime+1;
    139     timecell{itime}=XmlData.Time;
    140 end
    141 if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
    142     NbSlice_calib{1}=size(XmlData.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
    143     if ~isequal(NbSlice_calib{1},NbSlice_calib{1})
    144         msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
    145     end
    146 end
    147 
    148 
    149 %% check coincidence in time for several input file series
    150 % not relevant
    151 
    152 %% coordinate transform or other user defined transform
    153 %not relevant
    154 %%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
    155  % EDIT FROM HERE
    156 
    157 
    158 %% Set field names and velocity types
    159 % not relevant here
    160 
    161 %% Initiate output fields
    162 % not relevant here
    163 
    164 %% interactive input of specific parameters (for RDvision system)
    165 display('RDvision system')
    166 first_label=0; %image numbers start from 0
    167 
    168 %% correction to RDvision xml file
    169 t=xmltree(filexml);
    170 
    171 % correct Dtj and Dtk
    172 NomTypeNew='_1_1';% new file nomencalture by default
    173 ImageName='img_1_1.png';% first image name
    174 if isfield(XmlData,'NbDtj')
    175     uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
    176     uid_value=children(t,uid_NbDtj);
    177     if ~isempty(uid_value)
    178         t=set(t,uid_value(1),'value',num2str(XmlData.NbDtj));
    179     end
    180 end
    181 if isfield(XmlData,'NbDtk')
    182     uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
    183     uid_value=children(t,uid_NbDtk);
    184     if ~isempty(uid_value)
    185         t=set(t,uid_value(1),'value',num2str(XmlData.NbDtk));
    186     end
    187 end
    188 if isempty(j1_series{1}) && isfield(XmlData,'NbDti')
    189     uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti');
    190     t=add(t,uid_Dti,'chardata',num2str(XmlData.Dti));
    191     uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
    192     t=add(t,uid_NbDti,'chardata',num2str(XmlData.NbDti));
    193     uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
    194     uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
    195     t=delete(t,uid_NbDtj);
    196     t=delete(t,uid_NbDtk);
    197     uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj');
    198     uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk');
    199     t=delete(t,uid_Dtj);
    200     t=delete(t,uid_Dtk);
    201     NomTypeNew='_1';
    202     ImageName='img_1.png';
    203 end
    204  
    205 %update information of 'Heading'
    206 uid_Heading=find(t,'ImaDoc/Heading');
    207 if isempty(uid_Heading)
    208     [t,uid_Heading]=add(t,1,'element','Heading');
    209 end
    210 uid_SubCampaign=find(t,'ImaDoc/Heading/SubCampaign');
    211 if ~isempty(uid_SubCampaign), t=delete(t,uid_SubCampaign); end
    212 uid_Experiment=find(t,'ImaDoc/Heading/Experiment');
    213 if ~isempty(uid_Experiment), t=delete(t,uid_Experiment); end
    214 uid_Device=find(t,'ImaDoc/Heading/Device');
    215 if ~isempty(uid_Device), t=delete(t,uid_Device); end
    216 uid_Record=find(t,'ImaDoc/Heading/Record');
    217 if ~isempty(uid_Record), t=delete(t,uid_Record); end
    218 uid_DateExp=find(t,'ImaDoc/Heading/DateExp');
    219 if ~isempty(uid_DateExp), t=delete(t,uid_DateExp); end
    220 
    221 %indicate the name of the first image (as a check that the xml file is not moved)
    222 uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
    223 if isempty(uid_ImageName)
    224     [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
    225 end
    226 uid_value=children(t,uid_ImageName);
    227 if isempty(uid_value)
    228     t=add(t,uid_ImageName,'chardata',ImageName);%indicate  name of the first image, with ;png extension
    229 else
    230     t=set(t,uid_value(1),'value',ImageName);%indicate  name of the first image, with ;png extension
    231 end
    232 
    233 %indicate the date and time of the image acquisition start
    234 if isfield(FileInfo,'binrepertoire') && isfield(FileInfo,'starttime')
    235     sep_pos=regexp(FileInfo.binrepertoire,'T');
    236     DateTime=FileInfo.starttime;
    237     if ~isempty(sep_pos)
    238         DateTime=[FileInfo.binrepertoire(1:sep_pos-1) ' ' DateTime];
    239     end
    240     uid_DateTime=find(t,'ImaDoc/Heading/DateTime');
    241     if isempty(uid_DateTime)
    242         [t,uid_DateTime]=add(t,uid_Heading,'element','DateTime');
    243     end
    244     uid_value=children(t,uid_DateTime);
    245     if isempty(uid_value)
    246         t=add(t,uid_DateTime,'chardata',DateTime);%indicate  name of the first image, with ;png extension
     372[s,errormsg]=mkdir(OutputDir);
     373if s==0
     374    return%not able to create new image dir
     375end
     376for ii=1:SeqData.nb_frames
     377    fname=fullfile(binrepertoire,sprintf('%s%.5d.bin',SeqData.binfile,SqbData(ii).file_idx));
     378    if ii==1 || ~strcmp(fname,fname_prev) % open the bin file if not in use
     379        fid=fopen(fname,'rb');
     380        fseek(fid,SqbData(ii).offset,-1);%look at the right starting place in the bin file
     381        NbBinFile=NbBinFile+1;%counter of binary files (for checking purpose)
     382        BinSize(NbBinFile)=0;% strat counter for new bin file
    247383    else
    248         t=set(t,uid_value(1),'value',DateTime);%indicate  name of the first image, with ;png extension
    249     end
    250 end
    251  
    252 %% backup the previous xml file and save the corrected one
    253 [success,message]=copyfile(filexml,[filexml '~']);%make backup
    254 if success~=1
    255     dips(['errror in xml file backup: ' message]);
    256     return
    257 end
    258 save(t,filexml)
    259 
    260 %% main loop on images
    261 nbfield2=1;
    262 if isfield(XmlData,'Time')
    263 nbfield2=size(XmlData.Time,2);
    264 end
    265 for ifile=1:nbfield
    266             update_waitbar(WaitbarHandle,ifile/nbfield)
    267     if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
    268         disp('program stopped by user')
    269         break
    270     end
    271     [A,FileInfo,timestamps]=read_rdvision(filename,ifile);
    272     if ifile==1
    273         classA=class(A);
    274         if strcmp(classA,'uint8')
    275             BitDepth=8;
    276         else
    277         BitDepth=16;
    278         end
    279     end
     384        fclose(fid);%close the previous bin file
     385        fid=fopen(fname,'rb');% open the new bin file
     386        fseek(fid,SqbData(ii).offset,-1);%look at the right starting place in the bin file
     387    end
     388    fname_prev=fname;
     389    A=reshape(fread(fid,SeqData.width*SeqData.height,classname),SeqData.width,SeqData.height);%read the current image
     390    A=A';
     391    BinSize(NbBinFile)=BinSize(NbBinFile)+SeqData.width*SeqData.height*SeqData.bytesperpixel*8; %record bits read
    280392    j1=[];
    281393    if ~isequal(nbfield2,1)
    282     j1=mod(ifile-1+first_label,nbfield2)+1;
    283     end
    284     i1=floor((ifile-1+first_label)/nbfield2)+1;
    285     OutputFile=fullfile_uvmat(RootPath{1},OutputDir,'img','.png',NomTypeNew,i1,[],j1);
     394        j1=mod(ii-1,nbfield2)+1;
     395    end
     396    i1=floor((ii-1)/nbfield2)+1;
     397    OutputFile=fullfile_uvmat(PathDir,SeqData.sequencename,'img','.png',NomTypeNew,i1,[],j1);% TODO: set NomTypeNew from SeqData.mode
    286398    try
    287399        imwrite(A,OutputFile,'BitDepth',BitDepth) % case of 16 bit images
    288     disp([OutputFile ' written']);
     400        disp([OutputFile ' written']);
    289401        [s,errormsg] = fileattrib(OutputFile,'-w','a'); %set images to read only '-w' for all users ('a')
    290402        if ~s
    291             disp_uvmat('ERROR',errormsg,checkrun);
     403%             disp_uvmat('ERROR',errormsg,checkrun);
    292404            return
    293405        end
    294406    catch ME
    295         disp_uvmat('ERROR',ME.message,checkrun);
     407        errormsg=ME.message;
    296408        return
    297409    end
    298    
    299 end
     410end
     411fclose(fid)
     412toc
     413
     414
     415
     416% for ifile=1:nbfield
     417%             update_waitbar(WaitbarHandle,ifile/nbfield)
     418%     if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
     419%         disp('program stopped by user')
     420%         break
     421%     end
     422%     [A,FileInfo,timestamps]=read_rdvision(filename,ifile);
     423%     if ifile==1
     424%         classA=class(A);
     425%         if strcmp(classA,'uint8')
     426%             BitDepth=8;
     427%         else
     428%         BitDepth=16;
     429%         end
     430%     end
     431%     j1=[];
     432%     if ~isequal(nbfield2,1)
     433%     j1=mod(ifile-1+first_label,nbfield2)+1;
     434%     end
     435%     i1=floor((ifile-1+first_label)/nbfield2)+1;
     436%     OutputFile=fullfile_uvmat(RootPath{1},OutputDir,'img','.png',NomTypeNew,i1,[],j1);
     437%     try
     438%         imwrite(A,OutputFile,'BitDepth',BitDepth) % case of 16 bit images
     439%     disp([OutputFile ' written']);
     440%         [s,errormsg] = fileattrib(OutputFile,'-w','a'); %set images to read only '-w' for all users ('a')
     441%         if ~s
     442%             disp_uvmat('ERROR',errormsg,checkrun);
     443%             return
     444%         end
     445%     catch ME
     446%         disp_uvmat('ERROR',ME.message,checkrun);
     447%         return
     448%     end
     449%     
     450% end
    300451
    301452%'imadoc2struct_special': reads the xml file for image documentation
     
    611762   end
    612763end
     764
     765
     766
     767
Note: See TracChangeset for help on using the changeset viewer.