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