source: trunk/src/series/extract_rdvision.m

Last change on this file was 1163, checked in by sommeria, 32 hours ago

SearchBoxSize? changed to SearchRange? in civ, possibility of a grid set by a netcdf file

File size: 27.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%         
164%         %%%%%BRICOLAGE EXP40
165%         ind1=5*59-10;
166%         ind2=12*59-10;
167%         ind3=119*59-10;
168%         ind4=483*59-10;
169%         timestamp=[timestamp(1:ind4) timestamp(ind4) timestamp(ind4+1:end)];
170%          timestamp=[timestamp(1:ind3) timestamp(ind3) timestamp(ind3+1:end)];
171%           timestamp=[timestamp(1:ind2) timestamp(ind2) timestamp(ind2+1:end)];
172%            timestamp=[timestamp(1:ind1) timestamp(ind1) timestamp(ind1+1:end)];
173%            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174           
175           
176        if ParamOut.ActionInput.Createxml
177            ParamOut.ActionInput.XmlData.Camera.BurstTiming=time2xmlburst(timestamp,ParamOut.ActionInput.BurstLength);
178            Time=xmlburst2time(ParamOut.ActionInput.XmlData.Camera.BurstTiming);
179        else
180           Time=XmlData.Time;
181        end
182        timexml=reshape(Time(2:end,2:end)',1,[]);
183        if numel(timestamp)<= numel(timexml)
184            timexml=timexml(1:numel(timestamp));
185        else
186            msgbox_uvmat('ERROR',['time sequence from the xml file = ' num2str(numel(timexml))  ' smaller than timestamp length ' num2str(numel(timestamp))])
187            return
188        end
189        difftime=timestamp-timexml;
190        %if max(difftime)>0.01
191
192        figure
193        plot(timestamp,difftime)
194        xlabel('timestamps(s)')
195        ylabel('time difference(s)')
196        title('discrepency timestamps-timexml')
197        %end
198    return
199end
200
201
202%%%%%%%%%%%% STANDARD PART  %%%%%%%%%%%%
203ParamOut=[];
204%% read input parameters from an xml file if input is a file name (batch mode)
205
206if ischar(Param)
207    Param=xml2struct(Param);% read Param as input file (batch case)
208end
209disp(Param)
210checkrun=strcmp(Param.RunMode,'local');
211hseries=findobj(allchild(0),'Tag','series');
212RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
213WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
214
215%% root input file(s) and type
216RootPath=Param.InputTable{1,1};
217if ~isempty(find(~strcmp(RootPath,Param.InputTable(:,1))))% if the Rootpath for each camera are not identical
218    disp_uvmat('ERROR','Rootpath for all cameras must be identical',checkrun)
219    return
220end
221
222% get the set of input file names (cell array filecell), and the lists of
223% input file or frame indices i1_series,i2_series,j1_series,j2_series
224[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
225 
226% numbers of slices and file indices
227nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
228nbfield_i=size(i1_series{1},2); %nb of fields for the i index
229nbfield=nbfield_j*nbfield_i; %total number of fields
230
231%determine the file type on each line from the first input file
232FileInfo=get_file_info(filecell{1,1});
233if strcmp(FileInfo.FileType,'rdvision')
234
235    %% interactive input of specific parameters (for RDvision system)
236    display('converting images from RDvision system...')
237else
238    disp_uvmat('ERROR','the input is not from rdvision: a .seq or .sqb file must be opened',checkrun)
239    return
240end
241t=xmltree;
242
243save(t,fullfile(RootPath,'Running.xml'))%create an xml file to indicate that processing takes place
244
245%% calibration data and timing: read the ImaDoc files
246mode=''; %default
247timecell={};
248itime=0;
249NbSlice_calib={};
250
251%SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
252
253%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
254%%%  loop on the cameras ( #iview)
255%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
256
257for iview=1:size(Param.InputTable,1)
258    check_xml=0;
259    for iview_xml=1:size(Param.InputTable,1)% look for the xml files in the different data directories
260        filexml=[fullfile(RootPath,Param.InputTable{iview_xml,2},Param.InputTable{iview,3}) '.xml'];%new convention: xml at the level of the image folder
261        if exist(filexml,'file')
262            check_xml=1;
263            break
264        end
265    end
266    newxml=fullfile(RootPath,Param.InputTable{iview,3});
267    newxml=regexprep(newxml,'_Master_Dalsa_4M180$','');%suppress '_Master_Dalsa_4M180'extract_rdvision.m
268    newxml=[newxml '.xml'];
269   
270    %% get the names of .seq and .sqb files and save them to the log output folder .extract
271    if ismember( Param.InputTable{iview,5}, {'.seq','.sqb'})
272            filename_seq=fullfile(RootPath,Param.InputTable{iview,2},[Param.InputTable{iview,3} '.seq']);
273            filename_sqb=fullfile(RootPath,Param.InputTable{iview,2},[Param.InputTable{iview,3} '.sqb']);
274            errormsg='';
275            % backup of the seq, sqb and xml files for the first frame index
276            if isequal(Param.IndexRange.first_i,1)% backup of the seq, sqb and xml files for the first frame index
277                logdir=[Param.OutputSubDir Param.OutputDirExt];
278                [success,errormsg] = copyfile(filename_seq,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.seq']); %copy the seq file in the upper folder
279                if ~success
280                    disp(errormsg)
281                end
282                [success,errormsg] = copyfile(filename_sqb,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.sqb']); %copy the sqb file in the upper folder
283                if ~success
284                    disp(errormsg)
285                end
286                if check_xml
287                    [success,errormsg] = copyfile(filexml,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.xml']); %copy the original xml file in the upper folder
288                    if ~success
289                        disp(errormsg)
290                    end
291                end
292            end
293    else
294            errormsg='input file extension must be .seq or .sqb';
295    end
296    if ~exist(filename_seq,'file')
297        errormsg=[filename_seq ' does not exist'];
298    end
299    if ~isempty(errormsg)
300        disp_uvmat('ERRROR',errormsg,checkrun);
301        return
302    end
303   
304
305    %% get data from .seq file
306    s=ini2struct(filename_seq);
307    SeqData=s.sequenceSettings;
308    SeqData.width=str2double(SeqData.width);
309    SeqData.height=str2double(SeqData.height);
310    SeqData.bytesperpixel=str2double(SeqData.bytesperpixel);
311    SeqData.nb_frames=str2double(s.sequenceSettings.numberoffiles);
312    if isempty(SeqData.binrepertoire)%used when binrepertoire empty, strange feature of rdvision
313        SeqData.binrepertoire=regexprep(s.sequenceSettings.bindirectory,'\\$','');%tranform Windows notation to Linux
314        SeqData.binrepertoire=regexprep(SeqData.binrepertoire,'\','/');
315        [tild,SeqData.binrepertoire,DirExt]=fileparts(SeqData.binrepertoire);
316    end
317   
318    %% reading the .sqb file
319    m = memmapfile(filename_sqb,'Format', { 'uint32' [1 1] 'offset'; ...
320        'uint32' [1 1] 'garbage1';...
321        'double' [1 1] 'timestamp';...
322        'uint32' [1 1] 'file_idx';...
323        'uint32' [1 1] 'garbage2' },'Repeat',SeqData.nb_frames);
324   
325    %%%%%%%BRICOLAGE in case of unreadable .sqb file: remplace lecture du fichier
326%             ind=[8356 8356:8672];%indices of bin files
327%             w=2432;%w=width of images in pixels
328%             h=864;%h=height of images in pixels
329%             bpp=2;% nbre of bytes per pixel
330%             lengthimage=w*h*bpp;% lengthof an image record on the binary file
331%             nbimages=15; %nbre of images of each camera in a bin file
332%             for ii=1:15*numel(ind)
333%                 %data(ii).offset=mod(ii-1,32)*2*lengthimage+lengthimage;%Dalsa_2
334%                 %data(ii).offset=mod(ii-1,32)*2*lengthimage;%Dalsa_1
335%                 %data(ii).file_idx=ind(ceil(ii/32));
336%                 data(ii).file_idx=ind(ceil(ii/15));
337%                 data(ii).timestamp=0.005*(ii-1);
338%             end
339%             m.Data=data;
340%%%%%%%
341if Param.ActionInput.Createxml
342    nbfield2=Param.ActionInput.BurstLength;
343else
344    [XmlData,errormsg]=imadoc2struct(filexml);% check reading of the xml file
345    if isempty(errormsg)
346        nbfield2=size(XmlData.Time,2)-1;
347    else
348        disp(errormsg)
349        return
350    end
351end
352
353
354
355% timestamp=zeros(1,numel(m.Data));
356% for ii=1: numel(m.Data)
357%     timestamp(ii)=m.Data(ii).timestamp;
358% end
359if isequal(Param.IndexRange.first_i,1)
360    if Param.ActionInput.Createxml
361        t=struct2xml(Param.ActionInput.XmlData);
362        t=set(t,1,'name','ImaDoc');
363        save(t,newxml)
364    else
365        [success,errormsg]=copyfile(filexml,newxml);
366    end
367    % [nbfield1,nbfield2,msg]=copyfile_modif(filexml,timestamp,newxml); %copy the xml file in the upper folder
368    % if numel(timestamp)~=nbfield1*nbfield2
369    %     disp('WARNING: total image number defined by the xml file differs from  the number of frames ')
370    % else
371    %     timestamp=reshape(timestamp,nbfield2,nbfield1);
372    %     difftime=XmlData.Time(2:end,2:end)'-timestamp;
373    %     disp(['time from xml and timestamp differ by ' num2str(max(max(abs(difftime))))])
374    %     if max(abs(difftime))>0.01
375    %         checkpreserve=1;% will not erase the initial files, possibility of error
376    %     end
377    % end
378end
379if nbfield2>1
380    NomTypeNew='_1_1';
381else
382    NomTypeNew='_1';
383end
384
385[BinList,errormsg]=binread_rdv_series(RootPath,SeqData,m.Data,nbfield2,NomTypeNew,Param.IndexRange.first_i,Param.IndexRange.last_i,Param.CheckOverwrite);
386if ~isempty(errormsg)
387    disp_uvmat('ERROR',errormsg,checkrun)
388    return
389end
390end
391%% remove binary files if transfer OK
392%     if ~checkpreserve
393%         for iview=1:size(Param.InputTable,1)
394%          fullfile(RootPath,Param.InputTable{iview,2})
395%          source_dir=fullfile(RootPath,Param.InputTable{iview,2});
396%         [SUCCESS,MESSAGE]=rmdir(source_dir,'s')
397%         end
398%     end
399delete(fullfile(RootPath,'Running.xml'))%delete the  xml file to indicate that processing is finished
400
401%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402%--------- reads a series of bin files
403
404%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
405function [BinList,errormsg]=binread_rdv_series(PathDir,SeqData,SqbData,nbfield2,NomTypeNew,first,last,checkoverwrite)
406% BINREAD_RDV Permet de lire les fichiers bin g???n???r???s par Hiris ??? partir du
407% fichier seq associ???.
408%   [IMGS,TIMESTAMPS,NB_FRAMES] = BINREAD_RDV(FILENAME,FRAME_IDX) lit
409%   l'image d'indice FRAME_IDX de la s???quence FILENAME.
410%
411%   Entr???es
412%   -------
413%   FILENAME  : Nom du fichier s???quence (.seq).
414%   FRAME_IDX : Indice de l'image ??? lire. Si FRAME_IDX vaut -1 alors la
415%   s???quence est enti???rement lue. Si FRAME_IDX est un tableau d'indices
416%   alors toutes les images d'incides correspondant sont lues. Si FRAME_IDX
417%   est un tableau vide alors aucune image n'est lue mais le nombre
418%   d'images et tous les timestamps sont renvoy???s. Les indices commencent ???
419%   1 et se termines ??? NB_FRAMES.
420%
421%   Sorties
422%   -------
423%   IMGS        : Images de sortie.
424%   TIMESTAMPS  : Timestaps des images lues.
425%   NB_FRAMES   : Nombres d'images dans la s???quence.
426NbBinFile=0;
427BinSize=0;
428fid=0;
429errormsg='';
430BinList={};
431
432classname=sprintf('uint%d',SeqData.bytesperpixel*8);
433
434classname=['*' classname];
435BitDepth=8*SeqData.bytesperpixel;%needed to write images (8 or 16 bits)
436%%%%
437% SeqData.binrepertoire='2017-01-26T11.59.57';
438%SeqData.binrepertoire='2017-01-26T16.57.27';
439%SeqData.binrepertoire='2017-01-26T19.28.05';
440%SeqData.binrepertoire='2017-01-27T09.51.34';
441%SeqData.binrepertoire='2017-01-27T14.21.47'
442%%%%
443binrepertoire=fullfile(PathDir,SeqData.binrepertoire);
444FileDir=SeqData.sequencename;
445FileDir=regexprep(FileDir,'_Master_Dalsa_4M180$','');%suppress '_Master_Dalsa_4M180'
446OutputDir=fullfile(PathDir,FileDir);
447if ~exist(OutputDir,'dir')
448    %     errormsg=[OutputDir ' already exist, delete it first'];
449    %     return
450    % end
451    [s,errormsg]=mkdir(OutputDir);
452   
453    if s==0
454        disp(errormsg)
455        return%not able to create new image dir
456    end
457end
458bin_file_counter=0;
459%for ii=1:SeqData.nb_frames
460 %%%%%BRICOLAGE EXP40
461        ind1=5*59-10;
462        ind2=12*59-10;
463        ind3=119*59-10;
464        ind4=483*59-10;
465
466for ii=first:last
467    j1=[];
468    iinew=ii;
469%     %%%%%BRICOLAGE EXP40
470%     switch ii
471%         case  ii>=ind1 && ii<ind2
472%       iinew=ii+1;
473%         case ii>=ind2 && ii<ind3
474%         iinew=ii+2;
475%         case  ii>=ind3 && ii<ind4
476%       iinew=ii+3;
477%         case       ii>=ind4 && ii<ind3
478%         iinew=ii+4;   
479%     end
480%      %%%%%%%%%
481    if ~isequal(nbfield2,1)
482        j1=mod(iinew-1,nbfield2)+1;
483    end
484    i1=floor((iinew-1)/nbfield2)+1;
485   
486    OutputFile=fullfile_uvmat(PathDir,FileDir,'img','.png',NomTypeNew,i1,[],j1);% TODO: set NomTypeNew from SeqData.mode
487    fname=fullfile(binrepertoire,sprintf('%s%.5d.bin',SeqData.binfile,SqbData(ii).file_idx));
488    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
489        fid=0;
490    else
491        if fid==0 || ~strcmp(fname,fname_prev) % open the bin file if not in use
492            if fid~=0
493                fclose(fid);%close the previous bin file if relevant
494            end
495            [fid,msg]=fopen(fname,'rb');
496            if isequal(fid,-1)
497                errormsg=['error in opening ' fname ': ' msg];
498                return
499            else
500                disp([fname ' opened for reading'])
501                bin_file_counter=bin_file_counter+1;
502                BinList{bin_file_counter}=fname;
503            end
504            fseek(fid,SqbData(ii).offset,-1);%look at the right starting place in the bin file
505            NbBinFile=NbBinFile+1;%counter of binary files (for checking purpose)
506            BinSize(NbBinFile)=0;% strat counter for new bin file
507        else
508            fseek(fid,SqbData(ii).offset,-1);%look at the right starting place in the bin file
509        end
510        fname_prev=fname;
511        A=reshape(fread(fid,SeqData.width*SeqData.height,classname),SeqData.width,SeqData.height);%read the current image
512        A=A';
513        BinSize(NbBinFile)=BinSize(NbBinFile)+SeqData.width*SeqData.height*SeqData.bytesperpixel*8; %record bits read
514        try
515            tic
516            imwrite(A,OutputFile,'BitDepth',BitDepth) % case of 16 bit images
517            disp([OutputFile ' written']);
518            toc
519            % [s,errormsg] = fileattrib(OutputFile,'-w','a'); %set images to read only '-w' for all users ('a')
520            %         if ~s
521            % %             disp_uvmat('ERROR',errormsg,checkrun);
522            %             return
523            %         end
524        catch ME
525            errormsg=ME.message;
526            return
527        end
528    end
529end
530if fid~=0
531fclose(fid)
532end
533disp('END EXTRACT')
534
535
536%OBSOLETE
537function [nbfield1,nbfield2,msg]=copyfile_modif(filexml,timestamp,newxml)%
538msg='';
539t=xmltree(filexml);
540
541%% read Dtk and NbDtk
542NbDtk=1; %default
543Dtk=[]; % default
544uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk');
545uid_content_Dtk=get(t,uid_Dtk,'contents');
546if ~isempty(uid_content_Dtk)
547    Dtk=str2num(get(t,uid_content_Dtk,'value'));
548    uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
549    uid_content_NbDtk=get(t,uid_NbDtk,'contents');
550    if ~isempty(uid_content_NbDtk)
551    NbDtk=str2num(get(t,uid_content_NbDtk,'value'));
552    end
553end
554
555%% read Dti and NbDti
556NbDti=1; %default
557Dti=[]; % default
558uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti');
559uid_content_Dti=get(t,uid_Dti,'contents');
560if ~isempty(uid_content_Dti)
561    Dti=str2num(get(t,uid_content_Dti,'value'));
562    uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
563    uid_content_NbDti=get(t,uid_NbDti,'contents');
564    if ~isempty(uid_content_NbDti)
565    NbDti=str2num(get(t,uid_content_NbDti,'value'));
566    end
567end
568
569%% read Dtj and NbDtj
570NbDtj=1; %default
571Dtj=[]; % default
572uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj');
573uid_content_Dtj=get(t,uid_Dtj,'contents');
574if ~isempty(uid_content_Dtj)
575    Dtj=str2num(get(t,uid_content_Dtj,'value'));
576    uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
577    uid_content_NbDtj=get(t,uid_NbDtj,'contents');
578    if ~isempty(uid_content_NbDtj)
579    NbDtj=str2num(get(t,uid_content_NbDtj,'value'));
580    end
581end
582
583%% correct NbDtj and NbDti (error from RDvision)
584% if NbDtj==numel(Dtj)% case of bursts
585%     NbDtj=1;
586%     uid_motor_nbslice=find(t,'ImaDoc/TranslationMotor/Nbslice');
587%     if ~isempty(uid_motor_nbslice)&& ~isempty(uid_Dtk)% case of multilevel
588%         NbSlice=str2num(get(t,get(t,uid_motor_nbslice,'contents'),'value'));
589%         NbDti=NbSlice-1;
590%     end
591% end
592
593if isempty(Dtj)% case of simple series
594    timestamp=timestamp';
595    t=set(t,uid_content_NbDti,'value',num2str(numel(timestamp)-1));% correct NbDti in the xml file
596    nbfield1=numel(timestamp);
597    nbfield2=1;
598else
599    nbfieldi=(NbDti*numel(Dti)+1);
600    nbfieldk=(NbDtk*numel(Dtk)+1);
601    nbfield1=nbfieldi*nbfieldk;
602    nbfield2=NbDtj*numel(Dtj)+1;
603    NbFrames_xml=nbfield1*nbfield2;
604%    if NbFrames_xml<numel(timestamp)
605%        disp(['ERROR: size from xml ' num2str(NbFrame_xml) ' smaller than timestamp size ' num2str(numel(timestamp))])
606%        return
607%    end
608%    if NbFrames_xml>numel(timestamp)
609%        nbfield1=floor(numel(timestamp)/nbfield2);
610%        nbfieldk=floor(nbfield1/nbfieldi);
611%        nbfield1=nbfieldi*nbfieldk;
612%        NbDtk=nbfieldk-1;
613%        t=set(t,uid_content_NbDtk,'value',num2str(NbDtk));% correct NbDtk in the xml file (in practice numel(Dtk)=1;
614%        timestamp=timestamp(1:nbfield1*nbfield2);
615%        disp(['image record stopped before end: max index i= ' num2str(nbfield1)]);
616%        timestamp=reshape(timestamp,nbfield2,nbfield1);
617%    end
618%    % check Dtj with respect to timestamp
619%     timestamp=(reshape(timestamp,nbfield2,[]))';
620%     diff_Dtj=diff(timestamp(1,:))-Dtj;
621%     if max(abs(diff_Dtj))>min(Dtj)/1000
622%         disp(['Dtj from xml file differs from time stamp by ' num2str(max(abs(diff_Dtj))) ', '])%'
623%     else
624%         disp('Dtj OK');
625%     end
626end
627
628%% adjust Dti
629% if NbDti+1>size(timestamp,1)
630%     NbDti=size(timestamp,1)-1;
631% end
632% Dti_stamp=(timestamp(1+NbDti,1)-timestamp(1,1))/NbDti;
633% Dti_stamp=(timestamp(1+NbDti,1)-timestamp(2,1))/(NbDti-1);
634% t=set(t,uid_content_Dti,'value',num2str(Dti_stamp));%corret Dti
635% if abs(Dti_stamp-Dti)>Dti/1000
636%     disp([msg 'Dti from xml file corrected by ' num2str(Dti_stamp-Dti) ', ']);%'
637% else
638%     disp('Dti OK')
639% end
640
641%% adjust Dtk
642if ~isempty(uid_Dtk)
643    Dtk_stamp=(timestamp((NbDti+1)*NbDtk+1,1)-timestamp(1,1))/NbDtk;
644    t=set(t,uid_content_Dtk,'value',num2str(Dtk_stamp));
645    if abs(Dtk_stamp-Dtk)>Dtk/1000
646        disp(['Dtk from xml file corrected by ' num2str(Dtk_stamp-Dtk)]);
647    else
648        disp('Dtk OK')
649    end
650    t=set(t,uid_content_Dtk,'value',num2str(Dtk_stamp));
651end
652
653%% save the new xml file
654if ~isempty(newxml)
655    save(t,newxml)
656    [success,errormsg] = fileattrib(newxml,'+w','g');% allow writing access for the group of users
657    if success==0
658        disp({['warning: unable to set group write access to ' newxml ':']; errormsg});%error message for directory creation
659        msg=errormsg;
660    end
661end
662
663
Note: See TracBrowser for help on using the repository browser.