source: trunk/src/series/extract_rdvision.m @ 1164

Last change on this file since 1164 was 1164, checked in by sommeria, 2 months ago

civ3D updated

File size: 26.9 KB
Line 
1%'extract_rdvision': relabel an image series with two indices, and correct errors from the RDvision transfer program
2%------------------------------------------------------------------------
3% function ParamOut=extract_rdvision(Param)
4%------------------------------------------------------------------------
5%
6%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %
7%%%%%%%%%%%%%%%%%%%%%%%%%%
8%
9%OUTPUT
10% ParamOut: sets options in the GUI series.fig needed for the function
11%
12%INPUT:
13% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
14% In batch mode, Param is the name of the corresponding xml file containing the same information
15% when Param.Action.RUN=0 (as activated when the current Action is selected
16% in series), the function ouput paramOut set the activation of the needed GUI elements
17%
18% Param contains the elements:(use the menu bar command 'export/GUI config' in series to
19% see the current structure Param)
20%    .InputTable: cell of input file names, (several lines for multiple input)
21%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
22%    .OutputSubDir: name of the subdirectory for data outputs
23%    .OutputDirExt: directory extension for data outputs
24%    .Action: .ActionName: name of the current activated function
25%             .ActionPath:   path of the current activated function
26%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
27%             .RUN =0 for GUI input, =1 for function activation
28%             .RunMode='local','background', 'cluster': type of function  extract_rdvision.muse
29%
30%    .IndexRange: set the file or frame indices on which the action must be performed
31%    .FieldTransform: .TransformName: name of the selected transform function
32%                     .TransformPath:   path  of the selected transform function
33%    .InputFields: sub structure describing the input fields withfields
34%              .FieldName: name(s) of the field
35%              .VelType: velocity type
36%              .FieldName_1: name of the second field in case of two input series
37%              .VelType_1: velocity type of the second field in case of two input series
38%              .Coord_y: name of y coordinate variable
39%              .Coord_x: name of x coordinate variable
40%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
41%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42
43%=======================================================================
44% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
45%   http://www.legi.grenoble-inp.fr
46%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
47%
48%     This file is part of the toolbox UVMAT.
49%
50%     UVMAT is free software; you can redistribute it and/or modify
51%     it under the terms of the GNU General Public License as published
52%     by the Free Software Foundation; either version 2 of the license,
53%     or (at your option) any later version.
54%
55%     UVMAT is distributed in the hope that it will be useful,
56%     but WITHOUT ANY WARRANTY; without even the implied warranty of
57%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
58%     GNU General Public License (see LICENSE.txt) for more details.extract_rdvision.m
59%=======================================================================
60
61function ParamOut=extract_rdvision(Param) %default output=relabel_i_j(Param)
62
63%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
64if isstruct(Param) && isequal(Param.Action.RUN,0)
65    ParamOut.AllowInputSort='off';...% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
66        ParamOut.WholeIndexRange='on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
67        ParamOut.NbSlice='off';%1; ...%nbre of slices, 1 prevents splitting in several processes, ('off' by default)
68    ParamOut.VelType='off';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
69        ParamOut.FieldName='off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
70        ParamOut.FieldTransform = 'off';...%can use a transform function
71        ParamOut.ProjObject='off';...%can use projection object(option 'off'/'on',
72        ParamOut.Mask='off';...%can use mask option   (option 'off'/'on', 'off' by default)
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)
75    ParamOut.OutputDirExt='.extract';%set the output dir extension
76    ParamOut.OutputSubDirMode='one'; %output folder given by the folder name of the first input line
77    % detect the set of image folder
78    RootPath=Param.InputTable{1,1};
79    ListStruct=dir(RootPath);
80    ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
81    check_bad=strcmp('.',ListCells(1,:))|strcmp('..',ListCells(1,:));%detect the dir '.' to exclude it
82    check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
83    ListDir=ListCells(1,find(check_dir & ~check_bad));
84    isel=0;
85    InputTable=Param.InputTable;
86    for ilist=1:numel(ListDir)
87        ListStructSub=dir(fullfile(RootPath,ListDir{ilist}));
88        ListCellSub=struct2cell(ListStructSub);% transform dir struct to a cell arrray
89        detect_seq=regexp(ListCellSub(1,:),'.seq$');
90        seq_index=find(~cellfun('isempty',detect_seq),1);
91        if ~isempty(seq_index)
92            isel=isel+1;
93            InputTable{isel,1}=RootPath;
94            InputTable{isel,2}=ListDir{ilist};
95            RootFile=regexprep(ListCellSub{1,seq_index},'.seq$','');
96            InputTable{isel,3}=RootFile;
97            InputTable{isel,4}='*';
98            InputTable{isel,5}='.seq';
99        end
100    end
101    hseries=findobj(allchild(0),'Tag','series');% find the parent GUI 'series'
102    hhseries=guidata(hseries); %handles of the elements in 'series'
103    set(hhseries.InputTable,'Data',InputTable)
104    ParamOut.ActionInput.LogPath=RootPath;% indicate the path for the output info: 0_LOG ....
105
106    % check the names of .seq and .sqb files
107    iview=1;
108    if ~ismember(Param.InputTable{iview,5},{'.seq','.sqb'})
109        msgbox_uvmat('ERROR','bad input file : select .seq or .sqb for image extraction');
110        return
111    end
112    filename_seq=fullfile(RootPath,Param.InputTable{iview,2},[Param.InputTable{iview,3} '.seq']);
113    filename_sqb=fullfile(RootPath,Param.InputTable{iview,2},[Param.InputTable{iview,3} '.sqb']);
114    if ~exist(filename_seq,'file')
115        msgbox_uvmat('ERROR',[filename_seq ' missing']);
116        return
117    end
118    if ~exist(filename_sqb,'file')
119        msgbox_uvmat('ERROR',[filename_sqb ' missing']);
120        return
121    end
122    filexml=[fullfile(RootPath,Param.InputTable{iview,2},Param.InputTable{iview,3}) '.xml'];%xml at the level of the image folder
123    if exist(filexml,'file')
124        [XmlData,errormsg]=imadoc2struct(filexml);
125        if isempty(errormsg)
126            msgbox_uvmat('CONFIRMATION',[filexml ' used' ]);
127        else
128            msgbox_uvmat('ERROR',errormsg);
129            return
130        end
131        ParamOut.ActionInput.Createxml=false;
132        %  filexml=uigetfile_uvmat('pick xml file for timing',fullfile(RootPath,Param.InputTable{iview,2}),'.xml');
133        % msgbox_uvmat('ERROR',[filexml ' missing: needed to get the image organisation and timing ']);
134    else
135        if isfield(Param,'ActionInput') && isfield(Param.ActionInput,'BurstLength')
136            BurstLength=num2str(Param.ActionInput.BurstLength);
137        else
138            BurstLength='1';%default for a simple image series
139        end
140         answer=msgbox_uvmat('INPUT_TXT',{['no xml file in ' Param.InputTable{iview,2}];' introduce the nbre of frames in a burst to create xml'},BurstLength);
141        ParamOut.ActionInput.BurstLength=str2double(answer);
142         % filexml=uigetfile_uvmat('pick xml file for timing',fullfile(RootPath,Param.InputTable{iview,2}),'.xml');
143        % [XmlData,errormsg]=imadoc2struct(filexml);
144        ParamOut.ActionInput.Createxml=true;
145    end
146
147% get data from .seq file
148    s=ini2struct(filename_seq);
149    SeqData=s.sequenceSettings;
150    SeqData.nb_frames=str2double(s.sequenceSettings.numberoffiles);
151% reading the .sqb file
152    m = memmapfile(filename_sqb,'Format', { 'uint32' [1 1] 'offset'; ...
153        'uint32' [1 1] 'garbage1';...
154        'double' [1 1] 'timestamp';...
155        'uint32' [1 1] 'file_idx';...
156        'uint32' [1 1] 'garbage2' },'Repeat',SeqData.nb_frames);
157    ParamOut.ActionInput.XmlData.SourceFolder=fileparts(m.Filename);
158        timestamp=zeros(1,numel(m.Data));
159        for ii=1: numel(m.Data)
160            timestamp(ii)=m.Data(ii).timestamp;
161        end
162
163        if ParamOut.ActionInput.Createxml
164            ParamOut.ActionInput.XmlData.Camera.BurstTiming=time2xmlburst(timestamp,ParamOut.ActionInput.BurstLength);
165            Time=xmlburst2time(ParamOut.ActionInput.XmlData.Camera.BurstTiming);
166        else
167           Time=XmlData.Time;
168        end
169        timexml=reshape(Time(2:end,2:end)',1,[]);
170        if numel(timestamp)<= numel(timexml)
171            timexml=timexml(1:numel(timestamp));
172        else
173            msgbox_uvmat('ERROR',['time sequence from the xml file = ' num2str(numel(timexml))  ' smaller than timestamp length ' num2str(numel(timestamp))])
174            return
175        end
176        difftime=timestamp-timexml;
177        %if max(difftime)>0.01
178
179        figure
180        plot(timestamp,difftime)
181        xlabel('timestamps(s)')
182        ylabel('time difference(s)')
183        title('discrepency timestamps-timexml')
184        %end
185    return
186end
187
188
189%%%%%%%%%%%% STANDARD PART  %%%%%%%%%%%%
190ParamOut=[];
191%% read input parameters from an xml file if input is a file name (batch mode)
192
193if ischar(Param)
194    Param=xml2struct(Param);% read Param as input file (batch case)
195end
196disp(Param)
197checkrun=strcmp(Param.RunMode,'local');
198hseries=findobj(allchild(0),'Tag','series');
199RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
200WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
201
202%% root input file(s) and type
203RootPath=Param.InputTable{1,1};
204if ~isempty(find(~strcmp(RootPath,Param.InputTable(:,1))))% if the Rootpath for each camera are not identical
205    disp_uvmat('ERROR','Rootpath for all cameras must be identical',checkrun)
206    return
207end
208
209% get the set of input file names (cell array filecell), and the lists of
210% input file or frame indices i1_series,i2_series,j1_series,j2_series
211[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
212 
213% numbers of slices and file indices
214nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
215nbfield_i=size(i1_series{1},2); %nb of fields for the i index
216nbfield=nbfield_j*nbfield_i; %total number of fields
217
218%determine the file type on each line from the first input file
219FileInfo=get_file_info(filecell{1,1});
220if strcmp(FileInfo.FileType,'rdvision')
221
222    %% interactive input of specific parameters (for RDvision system)
223    display('converting images from RDvision system...')
224else
225    disp_uvmat('ERROR','the input is not from rdvision: a .seq or .sqb file must be opened',checkrun)
226    return
227end
228t=xmltree;
229
230save(t,fullfile(RootPath,'Running.xml'))%create an xml file to indicate that processing takes place
231
232%% calibration data and timing: read the ImaDoc files
233mode=''; %default
234timecell={};
235itime=0;
236NbSlice_calib={};
237
238%SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
239
240%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
241%%%  loop on the cameras ( #iview)
242%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243
244for iview=1:size(Param.InputTable,1)
245    check_xml=0;
246    for iview_xml=1:size(Param.InputTable,1)% look for the xml files in the different data directories
247        filexml=[fullfile(RootPath,Param.InputTable{iview_xml,2},Param.InputTable{iview,3}) '.xml'];%new convention: xml at the level of the image folder
248        if exist(filexml,'file')
249            check_xml=1;
250            break
251        end
252    end
253    newxml=fullfile(RootPath,Param.InputTable{iview,3});
254    newxml=regexprep(newxml,'_Master_Dalsa_4M180$','');%suppress '_Master_Dalsa_4M180'extract_rdvision.m
255    newxml=[newxml '.xml'];
256   
257    %% get the names of .seq and .sqb files and save them to the log output folder .extract
258    if ismember( Param.InputTable{iview,5}, {'.seq','.sqb'})
259            filename_seq=fullfile(RootPath,Param.InputTable{iview,2},[Param.InputTable{iview,3} '.seq']);
260            filename_sqb=fullfile(RootPath,Param.InputTable{iview,2},[Param.InputTable{iview,3} '.sqb']);
261            errormsg='';
262            % backup of the seq, sqb and xml files for the first frame index
263            if isequal(Param.IndexRange.first_i,1)% backup of the seq, sqb and xml files for the first frame index
264                logdir=[Param.OutputSubDir Param.OutputDirExt];
265                [success,errormsg] = copyfile(filename_seq,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.seq']); %copy the seq file in the upper folder
266                if ~success
267                    disp(errormsg)
268                end
269                [success,errormsg] = copyfile(filename_sqb,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.sqb']); %copy the sqb file in the upper folder
270                if ~success
271                    disp(errormsg)
272                end
273                if check_xml
274                    [success,errormsg] = copyfile(filexml,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.xml']); %copy the original xml file in the upper folder
275                    if ~success
276                        disp(errormsg)
277                    end
278                end
279            end
280    else
281            errormsg='input file extension must be .seq or .sqb';
282    end
283    if ~exist(filename_seq,'file')
284        errormsg=[filename_seq ' does not exist'];
285    end
286    if ~isempty(errormsg)
287        disp_uvmat('ERRROR',errormsg,checkrun);
288        return
289    end
290   
291
292    %% get data from .seq file
293    s=ini2struct(filename_seq);
294    SeqData=s.sequenceSettings;
295    SeqData.width=str2double(SeqData.width);
296    SeqData.height=str2double(SeqData.height);
297    SeqData.bytesperpixel=str2double(SeqData.bytesperpixel);
298    SeqData.nb_frames=str2double(s.sequenceSettings.numberoffiles);
299    if isempty(SeqData.binrepertoire)%used when binrepertoire empty, strange feature of rdvision
300        SeqData.binrepertoire=regexprep(s.sequenceSettings.bindirectory,'\\$','');%tranform Windows notation to Linux
301        SeqData.binrepertoire=regexprep(SeqData.binrepertoire,'\','/');
302        [tild,SeqData.binrepertoire,DirExt]=fileparts(SeqData.binrepertoire);
303    end
304   
305    %% reading the .sqb file
306    m = memmapfile(filename_sqb,'Format', { 'uint32' [1 1] 'offset'; ...
307        'uint32' [1 1] 'garbage1';...
308        'double' [1 1] 'timestamp';...
309        'uint32' [1 1] 'file_idx';...
310        'uint32' [1 1] 'garbage2' },'Repeat',SeqData.nb_frames);
311   
312    %%%%%%%BRICOLAGE in case of unreadable .sqb file: remplace lecture du fichier
313%             ind=[8356 8356:8672];%indices of bin files
314%             w=2432;%w=width of images in pixels
315%             h=864;%h=height of images in pixels
316%             bpp=2;% nbre of bytes per pixel
317%             lengthimage=w*h*bpp;% lengthof an image record on the binary file
318%             nbimages=15; %nbre of images of each camera in a bin file
319%             for ii=1:15*numel(ind)
320%                 %data(ii).offset=mod(ii-1,32)*2*lengthimage+lengthimage;%Dalsa_2
321%                 %data(ii).offset=mod(ii-1,32)*2*lengthimage;%Dalsa_1
322%                 %data(ii).file_idx=ind(ceil(ii/32));
323%                 data(ii).file_idx=ind(ceil(ii/15));
324%                 data(ii).timestamp=0.005*(ii-1);
325%             end
326%             m.Data=data;
327%%%%%%%
328if Param.ActionInput.Createxml
329    nbfield2=Param.ActionInput.BurstLength;
330else
331    [XmlData,errormsg]=imadoc2struct(filexml);% check reading of the xml file
332    if isempty(errormsg)
333        nbfield2=size(XmlData.Time,2)-1;
334    else
335        disp(errormsg)
336        return
337    end
338end
339
340
341
342% timestamp=zeros(1,numel(m.Data));
343% for ii=1: numel(m.Data)
344%     timestamp(ii)=m.Data(ii).timestamp;
345% end
346if isequal(Param.IndexRange.first_i,1)
347    if Param.ActionInput.Createxml
348        t=struct2xml(Param.ActionInput.XmlData);
349        t=set(t,1,'name','ImaDoc');
350        save(t,newxml)
351    else
352        [success,errormsg]=copyfile(filexml,newxml);
353    end
354    % [nbfield1,nbfield2,msg]=copyfile_modif(filexml,timestamp,newxml); %copy the xml file in the upper folder
355    % if numel(timestamp)~=nbfield1*nbfield2
356    %     disp('WARNING: total image number defined by the xml file differs from  the number of frames ')
357    % else
358    %     timestamp=reshape(timestamp,nbfield2,nbfield1);
359    %     difftime=XmlData.Time(2:end,2:end)'-timestamp;
360    %     disp(['time from xml and timestamp differ by ' num2str(max(max(abs(difftime))))])
361    %     if max(abs(difftime))>0.01
362    %         checkpreserve=1;% will not erase the initial files, possibility of error
363    %     end
364    % end
365end
366if nbfield2>1
367    NomTypeNew='_1_1';
368else
369    NomTypeNew='_1';
370end
371
372[BinList,errormsg]=binread_rdv_series(RootPath,SeqData,m.Data,nbfield2,NomTypeNew,Param.IndexRange.first_i,Param.IndexRange.last_i,Param.CheckOverwrite);
373if ~isempty(errormsg)
374    disp_uvmat('ERROR',errormsg,checkrun)
375    return
376end
377end
378%% remove binary files if transfer OK
379%     if ~checkpreserve
380%         for iview=1:size(Param.InputTable,1)
381%          fullfile(RootPath,Param.InputTable{iview,2})
382%          source_dir=fullfile(RootPath,Param.InputTable{iview,2});
383%         [SUCCESS,MESSAGE]=rmdir(source_dir,'s')
384%         end
385%     end
386delete(fullfile(RootPath,'Running.xml'))%delete the  xml file to indicate that processing is finished
387
388%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
389%--------- reads a series of bin files
390
391%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
392function [BinList,errormsg]=binread_rdv_series(PathDir,SeqData,SqbData,nbfield2,NomTypeNew,first,last,checkoverwrite)
393% BINREAD_RDV Permet de lire les fichiers bin g???n???r???s par Hiris ??? partir du
394% fichier seq associ???.
395%   [IMGS,TIMESTAMPS,NB_FRAMES] = BINREAD_RDV(FILENAME,FRAME_IDX) lit
396%   l'image d'indice FRAME_IDX de la s???quence FILENAME.
397%
398%   Entr???es
399%   -------
400%   FILENAME  : Nom du fichier s???quence (.seq).
401%   FRAME_IDX : Indice de l'image ??? lire. Si FRAME_IDX vaut -1 alors la
402%   s???quence est enti???rement lue. Si FRAME_IDX est un tableau d'indices
403%   alors toutes les images d'incides correspondant sont lues. Si FRAME_IDX
404%   est un tableau vide alors aucune image n'est lue mais le nombre
405%   d'images et tous les timestamps sont renvoy???s. Les indices commencent ???
406%   1 et se termines ??? NB_FRAMES.
407%
408%   Sorties
409%   -------
410%   IMGS        : Images de sortie.
411%   TIMESTAMPS  : Timestaps des images lues.
412%   NB_FRAMES   : Nombres d'images dans la s???quence.
413NbBinFile=0;
414BinSize=0;
415fid=0;
416errormsg='';
417BinList={};
418
419classname=sprintf('uint%d',SeqData.bytesperpixel*8);
420
421classname=['*' classname];
422BitDepth=8*SeqData.bytesperpixel;%needed to write images (8 or 16 bits)
423%%%%
424% SeqData.binrepertoire='2017-01-26T11.59.57';
425%SeqData.binrepertoire='2017-01-26T16.57.27';
426%SeqData.binrepertoire='2017-01-26T19.28.05';
427%SeqData.binrepertoire='2017-01-27T09.51.34';
428%SeqData.binrepertoire='2017-01-27T14.21.47'
429%%%%
430binrepertoire=fullfile(PathDir,SeqData.binrepertoire);
431FileDir=SeqData.sequencename;
432FileDir=regexprep(FileDir,'_Master_Dalsa_4M180$','');%suppress '_Master_Dalsa_4M180'
433OutputDir=fullfile(PathDir,FileDir);
434if ~exist(OutputDir,'dir')
435    %     errormsg=[OutputDir ' already exist, delete it first'];
436    %     return
437    % end
438    [s,errormsg]=mkdir(OutputDir);
439   
440    if s==0
441        disp(errormsg)
442        return%not able to create new image dir
443    end
444end
445bin_file_counter=0;
446
447for ii=first:last
448    j1=[];
449    iinew=ii;
450
451    if ~isequal(nbfield2,1)
452        j1=mod(iinew-1,nbfield2)+1;
453    end
454    i1=floor((iinew-1)/nbfield2)+1;
455   
456    OutputFile=fullfile_uvmat(PathDir,FileDir,'img','.png',NomTypeNew,i1,[],j1);% TODO: set NomTypeNew from SeqData.mode
457    fname=fullfile(binrepertoire,sprintf('%s%.5d.bin',SeqData.binfile,SqbData(ii).file_idx));
458    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
459        fid=0;
460    else
461        if fid==0 || ~strcmp(fname,fname_prev) % open the bin file if not in use
462            if fid~=0
463                fclose(fid);%close the previous bin file if relevant
464            end
465            [fid,msg]=fopen(fname,'rb');
466            if isequal(fid,-1)
467                errormsg=['error in opening ' fname ': ' msg];
468                return
469            else
470                disp([fname ' opened for reading'])
471                bin_file_counter=bin_file_counter+1;
472                BinList{bin_file_counter}=fname;
473            end
474            fseek(fid,SqbData(ii).offset,-1);%look at the right starting place in the bin file
475            NbBinFile=NbBinFile+1;%counter of binary files (for checking purpose)
476            BinSize(NbBinFile)=0;% strat counter for new bin file
477        else
478            fseek(fid,SqbData(ii).offset,-1);%look at the right starting place in the bin file
479        end
480        fname_prev=fname;
481        A=reshape(fread(fid,SeqData.width*SeqData.height,classname),SeqData.width,SeqData.height);%read the current image
482        A=A';
483        BinSize(NbBinFile)=BinSize(NbBinFile)+SeqData.width*SeqData.height*SeqData.bytesperpixel*8; %record bits read
484        try
485            tic
486            imwrite(A,OutputFile,'BitDepth',BitDepth) % case of 16 bit images
487            disp([OutputFile ' written']);
488            toc
489            % [s,errormsg] = fileattrib(OutputFile,'-w','a'); %set images to read only '-w' for all users ('a')
490            %         if ~s
491            % %             disp_uvmat('ERROR',errormsg,checkrun);
492            %             return
493            %         end
494        catch ME
495            errormsg=ME.message;
496            return
497        end
498    end
499end
500if fid~=0
501fclose(fid)
502end
503disp('END EXTRACT')
504
505
506%OBSOLETE
507function [nbfield1,nbfield2,msg]=copyfile_modif(filexml,timestamp,newxml)%
508msg='';
509t=xmltree(filexml);
510
511%% read Dtk and NbDtk
512NbDtk=1; %default
513Dtk=[]; % default
514uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk');
515uid_content_Dtk=get(t,uid_Dtk,'contents');
516if ~isempty(uid_content_Dtk)
517    Dtk=str2num(get(t,uid_content_Dtk,'value'));
518    uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
519    uid_content_NbDtk=get(t,uid_NbDtk,'contents');
520    if ~isempty(uid_content_NbDtk)
521    NbDtk=str2num(get(t,uid_content_NbDtk,'value'));
522    end
523end
524
525%% read Dti and NbDti
526NbDti=1; %default
527Dti=[]; % default
528uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti');
529uid_content_Dti=get(t,uid_Dti,'contents');
530if ~isempty(uid_content_Dti)
531    Dti=str2num(get(t,uid_content_Dti,'value'));
532    uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
533    uid_content_NbDti=get(t,uid_NbDti,'contents');
534    if ~isempty(uid_content_NbDti)
535    NbDti=str2num(get(t,uid_content_NbDti,'value'));
536    end
537end
538
539%% read Dtj and NbDtj
540NbDtj=1; %default
541Dtj=[]; % default
542uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj');
543uid_content_Dtj=get(t,uid_Dtj,'contents');
544if ~isempty(uid_content_Dtj)
545    Dtj=str2num(get(t,uid_content_Dtj,'value'));
546    uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
547    uid_content_NbDtj=get(t,uid_NbDtj,'contents');
548    if ~isempty(uid_content_NbDtj)
549    NbDtj=str2num(get(t,uid_content_NbDtj,'value'));
550    end
551end
552
553%% correct NbDtj and NbDti (error from RDvision)
554% if NbDtj==numel(Dtj)% case of bursts
555%     NbDtj=1;
556%     uid_motor_nbslice=find(t,'ImaDoc/TranslationMotor/Nbslice');
557%     if ~isempty(uid_motor_nbslice)&& ~isempty(uid_Dtk)% case of multilevel
558%         NbSlice=str2num(get(t,get(t,uid_motor_nbslice,'contents'),'value'));
559%         NbDti=NbSlice-1;
560%     end
561% end
562
563if isempty(Dtj)% case of simple series
564    timestamp=timestamp';
565    t=set(t,uid_content_NbDti,'value',num2str(numel(timestamp)-1));% correct NbDti in the xml file
566    nbfield1=numel(timestamp);
567    nbfield2=1;
568else
569    nbfieldi=(NbDti*numel(Dti)+1);
570    nbfieldk=(NbDtk*numel(Dtk)+1);
571    nbfield1=nbfieldi*nbfieldk;
572    nbfield2=NbDtj*numel(Dtj)+1;
573    NbFrames_xml=nbfield1*nbfield2;
574%    if NbFrames_xml<numel(timestamp)
575%        disp(['ERROR: size from xml ' num2str(NbFrame_xml) ' smaller than timestamp size ' num2str(numel(timestamp))])
576%        return
577%    end
578%    if NbFrames_xml>numel(timestamp)
579%        nbfield1=floor(numel(timestamp)/nbfield2);
580%        nbfieldk=floor(nbfield1/nbfieldi);
581%        nbfield1=nbfieldi*nbfieldk;
582%        NbDtk=nbfieldk-1;
583%        t=set(t,uid_content_NbDtk,'value',num2str(NbDtk));% correct NbDtk in the xml file (in practice numel(Dtk)=1;
584%        timestamp=timestamp(1:nbfield1*nbfield2);
585%        disp(['image record stopped before end: max index i= ' num2str(nbfield1)]);
586%        timestamp=reshape(timestamp,nbfield2,nbfield1);
587%    end
588%    % check Dtj with respect to timestamp
589%     timestamp=(reshape(timestamp,nbfield2,[]))';
590%     diff_Dtj=diff(timestamp(1,:))-Dtj;
591%     if max(abs(diff_Dtj))>min(Dtj)/1000
592%         disp(['Dtj from xml file differs from time stamp by ' num2str(max(abs(diff_Dtj))) ', '])%'
593%     else
594%         disp('Dtj OK');
595%     end
596end
597
598%% adjust Dti
599% if NbDti+1>size(timestamp,1)
600%     NbDti=size(timestamp,1)-1;
601% end
602% Dti_stamp=(timestamp(1+NbDti,1)-timestamp(1,1))/NbDti;
603% Dti_stamp=(timestamp(1+NbDti,1)-timestamp(2,1))/(NbDti-1);
604% t=set(t,uid_content_Dti,'value',num2str(Dti_stamp));%corret Dti
605% if abs(Dti_stamp-Dti)>Dti/1000
606%     disp([msg 'Dti from xml file corrected by ' num2str(Dti_stamp-Dti) ', ']);%'
607% else
608%     disp('Dti OK')
609% end
610
611%% adjust Dtk
612if ~isempty(uid_Dtk)
613    Dtk_stamp=(timestamp((NbDti+1)*NbDtk+1,1)-timestamp(1,1))/NbDtk;
614    t=set(t,uid_content_Dtk,'value',num2str(Dtk_stamp));
615    if abs(Dtk_stamp-Dtk)>Dtk/1000
616        disp(['Dtk from xml file corrected by ' num2str(Dtk_stamp-Dtk)]);
617    else
618        disp('Dtk OK')
619    end
620    t=set(t,uid_content_Dtk,'value',num2str(Dtk_stamp));
621end
622
623%% save the new xml file
624if ~isempty(newxml)
625    save(t,newxml)
626    [success,errormsg] = fileattrib(newxml,'+w','g');% allow writing access for the group of users
627    if success==0
628        disp({['warning: unable to set group write access to ' newxml ':']; errormsg});%error message for directory creation
629        msg=errormsg;
630    end
631end
632
633
Note: See TracBrowser for help on using the repository browser.