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 | %OUTPUT
|
---|
9 | % ParamOut: sets options in the GUI series.fig needed for the function
|
---|
10 | %
|
---|
11 | %INPUT:
|
---|
12 | % In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
|
---|
13 | % In batch mode, Param is the name of the corresponding xml file containing the same information
|
---|
14 | % when Param.Action.RUN=0 (as activated when the current Action is selected
|
---|
15 | % in series), the function ouput paramOut set the activation of the needed GUI elements
|
---|
16 | %
|
---|
17 | % Param contains the elements:(use the menu bar command 'export/GUI config' in series to
|
---|
18 | % see the current structure Param)
|
---|
19 | % .InputTable: cell of input file names, (several lines for multiple input)
|
---|
20 | % each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
|
---|
21 | % .OutputSubDir: name of the subdirectory for data outputs
|
---|
22 | % .OutputDirExt: directory extension for data outputs
|
---|
23 | % .Action: .ActionName: name of the current activated function
|
---|
24 | % .ActionPath: path of the current activated function
|
---|
25 | % .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled Matlab fct
|
---|
26 | % .RUN =0 for GUI input, =1 for function activation
|
---|
27 | % .RunMode='local','background', 'cluster': type of function use
|
---|
28 | %
|
---|
29 | % .IndexRange: set the file or frame indices on which the action must be performed
|
---|
30 | % .FieldTransform: .TransformName: name of the selected transform function
|
---|
31 | % .TransformPath: path of the selected transform function
|
---|
32 | % .InputFields: sub structure describing the input fields withfields
|
---|
33 | % .FieldName: name(s) of the field
|
---|
34 | % .VelType: velocity type
|
---|
35 | % .FieldName_1: name of the second field in case of two input series
|
---|
36 | % .VelType_1: velocity type of the second field in case of two input series
|
---|
37 | % .Coord_y: name of y coordinate variable
|
---|
38 | % .Coord_x: name of x coordinate variable
|
---|
39 | % .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
|
---|
40 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
41 |
|
---|
42 | %=======================================================================
|
---|
43 | % Copyright 2008-2015, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
|
---|
44 | % http://www.legi.grenoble-inp.fr
|
---|
45 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
|
---|
46 | %
|
---|
47 | % This file is part of the toolbox UVMAT.
|
---|
48 | %
|
---|
49 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
50 | % it under the terms of the GNU General Public License as published
|
---|
51 | % by the Free Software Foundation; either version 2 of the license,
|
---|
52 | % or (at your option) any later version.
|
---|
53 | %
|
---|
54 | % UVMAT is distributed in the hope that it will be useful,
|
---|
55 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
56 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
57 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
58 | %=======================================================================
|
---|
59 |
|
---|
60 | function ParamOut=extract_rdvision(Param) %default output=relabel_i_j(Param)
|
---|
61 |
|
---|
62 | %% set the input elements needed on the GUI series when the action is selected in the menu ActionName
|
---|
63 | if isstruct(Param) && isequal(Param.Action.RUN,0)
|
---|
64 | ParamOut.AllowInputSort='off';...% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
|
---|
65 | ParamOut.WholeIndexRange='on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
|
---|
66 | ParamOut.NbSlice='one'; ...%nbre of slices, 'one' prevents splitting in several processes, ('off' by default)
|
---|
67 | ParamOut.VelType='off';...% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default)
|
---|
68 | ParamOut.FieldName='off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
|
---|
69 | ParamOut.FieldTransform = 'off';...%can use a transform function
|
---|
70 | ParamOut.ProjObject='off';...%can use projection object(option 'off'/'on',
|
---|
71 | ParamOut.Mask='off';...%can use mask option (option 'off'/'on', 'off' by default)
|
---|
72 | ParamOut.OutputDirExt='.extract';%set the output dir extension
|
---|
73 | ParamOut.OutputSubDirMode='one'; %output folder given by the program, not by the GUI series
|
---|
74 | % detect the set of image folder
|
---|
75 | RootPath=Param.InputTable{1,1};
|
---|
76 | ListStruct=dir(RootPath);
|
---|
77 | ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
|
---|
78 | check_bad=strcmp('.',ListCells(1,:))|strcmp('..',ListCells(1,:));%detect the dir '.' to exclude it
|
---|
79 | check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
|
---|
80 | ListDir=ListCells(1,find(check_dir & ~check_bad));
|
---|
81 | % InputTable=cell(numel(ListDir),5);
|
---|
82 | % InputTable(:,2)=ListDir';
|
---|
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 | % msgbox_uvmat('ERROR',['not seq file in ' ListDir{ilist} ': please check the input folders'])
|
---|
92 | % else
|
---|
93 | isel=isel+1;
|
---|
94 | InputTable{isel,1}=RootPath;
|
---|
95 | InputTable{isel,2}=ListDir{ilist};
|
---|
96 | RootFile=regexprep(ListCellSub{1,seq_index},'.seq$','');
|
---|
97 | InputTable{isel,3}=RootFile;
|
---|
98 | InputTable{isel,4}='*';
|
---|
99 | InputTable{isel,5}='.seq';
|
---|
100 | end
|
---|
101 | end
|
---|
102 | hseries=findobj(allchild(0),'Tag','series');% find the parent GUI 'series'
|
---|
103 | hhseries=guidata(hseries); %handles of the elements in 'series'
|
---|
104 | set(hhseries.InputTable,'Data',InputTable)
|
---|
105 | ParamOut.ActionInput.LogPath=RootPath;% indicate the path for the output info: 0_LOG ....
|
---|
106 | return
|
---|
107 | end
|
---|
108 |
|
---|
109 | ParamOut=[];
|
---|
110 | %%%%%%%%%%%% STANDARD PART %%%%%%%%%%%%
|
---|
111 | %% read input parameters from an xml file if input is a file name (batch mode)
|
---|
112 | checkrun=1;
|
---|
113 | if ischar(Param)
|
---|
114 | Param=xml2struct(Param);% read Param as input file (batch case)
|
---|
115 | checkrun=0;
|
---|
116 | end
|
---|
117 | hseries=findobj(allchild(0),'Tag','series');
|
---|
118 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
|
---|
119 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
|
---|
120 |
|
---|
121 | %% root input file(s) and type
|
---|
122 | RootPath=Param.InputTable{1,1};
|
---|
123 | if ~isempty(find(~strcmp(RootPath,Param.InputTable(:,1))))% if the Rootpath for each camera are not identical
|
---|
124 | disp_uvmat('ERROR','Rootpath for all cameras must be identical',checkrun)
|
---|
125 | return
|
---|
126 | end
|
---|
127 |
|
---|
128 | % get the set of input file names (cell array filecell), and the lists of
|
---|
129 | % input file or frame indices i1_series,i2_series,j1_series,j2_series
|
---|
130 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
|
---|
131 |
|
---|
132 | %OutputDir=[Param.OutputSubDir Param.OutputDirExt];
|
---|
133 |
|
---|
134 | % numbers of slices and file indices
|
---|
135 | nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
|
---|
136 | nbfield_i=size(i1_series{1},2); %nb of fields for the i index
|
---|
137 | nbfield=nbfield_j*nbfield_i; %total number of fields
|
---|
138 |
|
---|
139 | %determine the file type on each line from the first input file
|
---|
140 |
|
---|
141 | FileInfo=get_file_info(filecell{1,1});
|
---|
142 | if strcmp(FileInfo.FileType,'rdvision')
|
---|
143 | if ~isequal(FileInfo.NumberOfFrames,nbfield)
|
---|
144 | msgbox_uvmat('ERROR',['the whole series of ' num2str(FileInfo.NumberOfFrames) ' images must be extracted at once'])
|
---|
145 | %rmfield(OutputDir)
|
---|
146 | % return
|
---|
147 | end
|
---|
148 | %% interactive input of specific parameters (for RDvision system)
|
---|
149 | display('converting images from RDvision system...')
|
---|
150 | else
|
---|
151 | msgbox_uvmat('ERROR','the input is not from rdvision: a .seq or .sqb file must be opened')
|
---|
152 | return
|
---|
153 | end
|
---|
154 | t=xmltree;
|
---|
155 | %%% A REMETTREE %%%%%%%%%%%%%%%%%%%%%
|
---|
156 | save(t,fullfile(RootPath,'Running.xml'))%create an xml file to indicate that processing takes place
|
---|
157 |
|
---|
158 | %% calibration data and timing: read the ImaDoc files
|
---|
159 | mode=''; %default
|
---|
160 | timecell={};
|
---|
161 | itime=0;
|
---|
162 | NbSlice_calib={};
|
---|
163 |
|
---|
164 | %SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
|
---|
165 |
|
---|
166 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
167 | %%% loop on the cameras ( #iview)
|
---|
168 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
169 | % RootPath=Param.InputTable(:,1);
|
---|
170 | % RootFile=Param.InputTable(:,3);
|
---|
171 | % SubDir=Param.InputTable(:,2);
|
---|
172 | % NomType=Param.InputTable(:,4);
|
---|
173 | % FileExt=Param.InputTable(:,5);
|
---|
174 |
|
---|
175 | % [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
|
---|
176 | % if size(time,1)>1
|
---|
177 | % diff_time=max(max(diff(time)));
|
---|
178 | % if diff_time>0
|
---|
179 | % disp_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)],checkrun)
|
---|
180 | % end
|
---|
181 | % end
|
---|
182 | %
|
---|
183 | % nbfield2=size(time,1);
|
---|
184 | checkpreserve=0;% if =1, will npreserve the original images, else it erases them at the end
|
---|
185 | for iview=1:size(Param.InputTable,1)
|
---|
186 | for iview_xml=1:size(Param.InputTable,1)% loojk for the xml files in the different data directories
|
---|
187 | filexml=[fullfile(RootPath,Param.InputTable{iview_xml,2},Param.InputTable{iview,3}) '.xml'];%new convention: xml at the level of the image folder
|
---|
188 | if exist(filexml,'file')
|
---|
189 | break
|
---|
190 | end
|
---|
191 | end
|
---|
192 | if ~exist(filexml,'file')
|
---|
193 | disp_uvmat('ERROR',[filexml ' missing'],checkrun)
|
---|
194 | return
|
---|
195 | end
|
---|
196 | [XmlData,errormsg]=imadoc2struct(filexml);
|
---|
197 |
|
---|
198 | newxml=[fullfile(RootPath,Param.InputTable{iview,3}) '.xml']
|
---|
199 |
|
---|
200 | [success,errormsg] = copyfile(filexml,newxml); %copy the xml file in the upper folder
|
---|
201 |
|
---|
202 | nbfield2=size(XmlData.Time,2)-1;
|
---|
203 | if nbfield2>1
|
---|
204 | NomTypeNew='_1_1';
|
---|
205 | else
|
---|
206 | NomTypeNew='_1';
|
---|
207 | end
|
---|
208 | %% get the names of .seq and .sqb files
|
---|
209 | switch Param.InputTable{iview,5}
|
---|
210 | case {'.seq','.sqb'}
|
---|
211 | filename_seq=fullfile(RootPath,Param.InputTable{iview,2},[Param.InputTable{iview,3} '.seq']);
|
---|
212 | filename_sqb=fullfile(RootPath,Param.InputTable{iview,2},[Param.InputTable{iview,3} '.sqb']);
|
---|
213 | [success,errormsg] = copyfile(filename_seq,[fullfile(RootPath,Param.InputTable{iview,3}) '.seq']); %copy the seq file in the upper folder
|
---|
214 | [success,errormsg] = copyfile(filename_sqb,[fullfile(RootPath,Param.InputTable{iview,3}) '.sqb']); %copy the sqb file in the upper folder
|
---|
215 | otherwise
|
---|
216 | errormsg='input file extension must be .seq or .sqb';
|
---|
217 | end
|
---|
218 | if ~exist(filename_seq,'file')
|
---|
219 | errormsg=[filename_seq ' does not exist'];
|
---|
220 | end
|
---|
221 | if ~isempty(errormsg)
|
---|
222 | disp_uvmat('ERRROR',errormsg,checkrun);
|
---|
223 | return
|
---|
224 | end
|
---|
225 |
|
---|
226 |
|
---|
227 | %% get data from .seq file
|
---|
228 | s=ini2struct(filename_seq);
|
---|
229 | SeqData=s.sequenceSettings;
|
---|
230 | SeqData.width=str2double(SeqData.width);
|
---|
231 | SeqData.height=str2double(SeqData.height);
|
---|
232 | SeqData.bytesperpixel=str2double(SeqData.bytesperpixel);
|
---|
233 | SeqData.nb_frames=str2double(s.sequenceSettings.numberoffiles);
|
---|
234 | if isempty(SeqData.binrepertoire)%used when binrepertoire empty, strange feature of rdvision
|
---|
235 | SeqData.binrepertoire=regexprep(s.sequenceSettings.bindirectory,'\\$','');%tranform Windows notation to Linux
|
---|
236 | SeqData.binrepertoire=regexprep(SeqData.binrepertoire,'\','/');
|
---|
237 | [tild,binrepertoire,DirExt]=fileparts(SeqData.binrepertoire);
|
---|
238 | SeqData.binrepertoire=[SeqData.binrepertoire DirExt];
|
---|
239 | end
|
---|
240 |
|
---|
241 | %% checking consistency with the xml file
|
---|
242 | [npi,npj]=size(XmlData.Time);
|
---|
243 | if ~isequal(SeqData.nb_frames,(npi-1)*(npj-1))
|
---|
244 | disp_uvmat('ERRROR',['inconsistent number of images ' num2str(SeqData.nb_frames) ' with respect to the xml file: ' num2str((npi-1)*(npj-1))] ,checkrun);
|
---|
245 | return
|
---|
246 | end
|
---|
247 |
|
---|
248 | %% reading the .sqb file
|
---|
249 | m = memmapfile(filename_sqb,'Format', { 'uint32' [1 1] 'offset'; ...
|
---|
250 | 'uint32' [1 1] 'garbage1';...
|
---|
251 | 'double' [1 1] 'timestamp';...
|
---|
252 | 'uint32' [1 1] 'file_idx';...
|
---|
253 | 'uint32' [1 1] 'garbage2' },'Repeat',SeqData.nb_frames);
|
---|
254 |
|
---|
255 | %%%%%%%BRICOLAGE in case of unreadable .sqb file: remplace lecture du fichier
|
---|
256 | % ind=[111 114:211];%indices of bin files
|
---|
257 | % w=1024;%w=width of images in pixels
|
---|
258 | % h=1024;%h=height of images in pixels
|
---|
259 | % bpp=2;% nbre of bytes per pixel
|
---|
260 | % lengthimage=w*h*bpp;% lengthof an image record on the binary file
|
---|
261 | % nbimages=32; %nbre of images of each camera in a bin file
|
---|
262 | % for ii=1:32*numel(ind)
|
---|
263 | % data(ii).offset=mod(ii-1,32)*2*lengthimage+lengthimage;%Dalsa_2
|
---|
264 | % %data(ii).offset=mod(ii-1,32)*2*lengthimage;%Dalsa_1
|
---|
265 | % data(ii).file_idx=ind(ceil(ii/32));
|
---|
266 | % data(ii).timestamp=0.2*(ii-1);
|
---|
267 | % end
|
---|
268 | % m.Data=data;
|
---|
269 | %%%%%%%
|
---|
270 | timestamp=zeros(1,numel(m.Data));
|
---|
271 | for ii=1: numel(m.Data)
|
---|
272 | timestamp(ii)=m.Data(ii).timestamp;
|
---|
273 | j1=1;
|
---|
274 | if ~isequal(nbfield2,1)
|
---|
275 | j1=mod(ii-1,nbfield2)+1;
|
---|
276 | end
|
---|
277 | i1=floor((ii-1)/nbfield2)+1;
|
---|
278 | diff_time(i1,j1)= timestamp(ii)-XmlData.Time(i1+1,j1+1);
|
---|
279 | end
|
---|
280 | time_diff_max=max(diff_time');
|
---|
281 | time_diff_min=min(diff_time');
|
---|
282 | if max(time_diff_max)>0.005
|
---|
283 | disp(['WARNING:timestamps exceeds xml time by' num2str(max(time_diff_max))])
|
---|
284 | checkpreserve=1;
|
---|
285 | elseif min(time_diff_min)<-0.005
|
---|
286 | disp(['timestamps is lower than xml time by' num2str(min(time_diff_min))])
|
---|
287 | checkpreserve=1;
|
---|
288 | else
|
---|
289 | disp('CONFIRMATION:time from xml file correct within better than 5 ms')
|
---|
290 | end
|
---|
291 | if checkpreserve
|
---|
292 | disp( 'max and min of timestamp-xml time for each index i:')
|
---|
293 | disp(time_diff_max)
|
---|
294 | disp(time_diff_min)
|
---|
295 | end
|
---|
296 | [BinList,errormsg]=binread_rdv_series(RootPath,SeqData,m.Data,nbfield2,NomTypeNew);
|
---|
297 | if ~isempty(errormsg)
|
---|
298 | disp_uvmat('ERROR',errormsg,checkrun)
|
---|
299 | return
|
---|
300 | end
|
---|
301 | % check the existence of the expected output image files (from the xml)
|
---|
302 | for i1=1:npi-1
|
---|
303 | for j1=1:npj-1
|
---|
304 | OutputFile=fullfile_uvmat(RootPath,SeqData.sequencename,'img','.png',NomTypeNew,i1,[],j1);% TODO: set NomTypeNew from SeqData.mode
|
---|
305 | A=imread(OutputFile);% check image reading (stop if error)
|
---|
306 | end
|
---|
307 | end
|
---|
308 |
|
---|
309 | % check images
|
---|
310 |
|
---|
311 | % delete(fullfile(RootPath,'Running.xml'))%delete the xml file to indicate that processing is finished
|
---|
312 | % if ~checkpreserve
|
---|
313 | % for ibin=1:numel(BinList)
|
---|
314 | % delete(BinList{ibin})
|
---|
315 | % end
|
---|
316 | % rmdir(fullfile(RootPath,Param.InputTable{iview,2}))
|
---|
317 | % end
|
---|
318 | end
|
---|
319 | delete(fullfile(RootPath,'Running.xml'))%delete the xml file to indicate that processing is finished
|
---|
320 |
|
---|
321 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
322 | %--------- reads a series of bin files
|
---|
323 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
324 | function [BinList,errormsg]=binread_rdv_series(PathDir,SeqData,SqbData,nbfield2,NomTypeNew)
|
---|
325 | % BINREAD_RDV Permet de lire les fichiers bin gᅵnᅵrᅵs par Hiris ᅵ partir du
|
---|
326 | % fichier seq associᅵ.
|
---|
327 | % [IMGS,TIMESTAMPS,NB_FRAMES] = BINREAD_RDV(FILENAME,FRAME_IDX) lit
|
---|
328 | % l'image d'indice FRAME_IDX de la sï¿œquence FILENAME.
|
---|
329 | %
|
---|
330 | % Entrï¿œes
|
---|
331 | % -------
|
---|
332 | % FILENAME : Nom du fichier sï¿œquence (.seq).
|
---|
333 | % FRAME_IDX : Indice de l'image ᅵ lire. Si FRAME_IDX vaut -1 alors la
|
---|
334 | % sï¿œquence est entiï¿œrement lue. Si FRAME_IDX est un tableau d'indices
|
---|
335 | % alors toutes les images d'incides correspondant sont lues. Si FRAME_IDX
|
---|
336 | % est un tableau vide alors aucune image n'est lue mais le nombre
|
---|
337 | % d'images et tous les timestamps sont renvoyᅵs. Les indices commencent ᅵ
|
---|
338 | % 1 et se termines ᅵ NB_FRAMES.
|
---|
339 | %
|
---|
340 | % Sorties
|
---|
341 | % -------
|
---|
342 | % IMGS : Images de sortie.
|
---|
343 | % TIMESTAMPS : Timestaps des images lues.
|
---|
344 | % NB_FRAMES : Nombres d'images dans la sï¿œquence.
|
---|
345 | NbBinFile=0;
|
---|
346 | BinSize=0;
|
---|
347 | fid=0;
|
---|
348 | errormsg='';
|
---|
349 | classname=sprintf('uint%d',SeqData.bytesperpixel*8);
|
---|
350 |
|
---|
351 | classname=['*' classname];
|
---|
352 | BitDepth=8*SeqData.bytesperpixel;%needed to write images (8 or 16 bits)
|
---|
353 | binrepertoire=fullfile(PathDir,SeqData.binrepertoire);
|
---|
354 | OutputDir=fullfile(PathDir,SeqData.sequencename);
|
---|
355 | if ~exist(OutputDir,'dir')
|
---|
356 | % errormsg=[OutputDir ' already exist, delete it first'];
|
---|
357 | % return
|
---|
358 | % end
|
---|
359 | [s,errormsg]=mkdir(OutputDir);
|
---|
360 |
|
---|
361 | if s==0
|
---|
362 | disp(errormsg)
|
---|
363 | return%not able to create new image dir
|
---|
364 | end
|
---|
365 | end
|
---|
366 | bin_file_counter=0;
|
---|
367 | for ii=1:SeqData.nb_frames
|
---|
368 | j1=[];
|
---|
369 | if ~isequal(nbfield2,1)
|
---|
370 | j1=mod(ii-1,nbfield2)+1;
|
---|
371 | end
|
---|
372 | i1=floor((ii-1)/nbfield2)+1;
|
---|
373 | OutputFile=fullfile_uvmat(PathDir,SeqData.sequencename,'img','.png',NomTypeNew,i1,[],j1);% TODO: set NomTypeNew from SeqData.mode
|
---|
374 | fname=fullfile(binrepertoire,sprintf('%s%.5d.bin',SeqData.binfile,SqbData(ii).file_idx));
|
---|
375 | if exist(OutputFile,'file')
|
---|
376 | fid=0;
|
---|
377 | else
|
---|
378 | if fid==0 || ~strcmp(fname,fname_prev) % open the bin file if not in use
|
---|
379 | if fid~=0
|
---|
380 | fclose(fid);%close the previous bin file if relevant
|
---|
381 | end
|
---|
382 | [fid,msg]=fopen(fname,'rb');
|
---|
383 | if isequal(fid,-1)
|
---|
384 | errormsg=['error in opening ' fname ': ' msg];
|
---|
385 | return
|
---|
386 | else
|
---|
387 | disp([fname ' opened for reading'])
|
---|
388 | bin_file_counter=bin_file_counter+1;
|
---|
389 | BinList{bin_file_counter}=fname;
|
---|
390 | end
|
---|
391 | fseek(fid,SqbData(ii).offset,-1);%look at the right starting place in the bin file
|
---|
392 | NbBinFile=NbBinFile+1;%counter of binary files (for checking purpose)
|
---|
393 | BinSize(NbBinFile)=0;% strat counter for new bin file
|
---|
394 | else
|
---|
395 | fseek(fid,SqbData(ii).offset,-1);%look at the right starting place in the bin file
|
---|
396 | end
|
---|
397 | fname_prev=fname;
|
---|
398 | A=reshape(fread(fid,SeqData.width*SeqData.height,classname),SeqData.width,SeqData.height);%read the current image
|
---|
399 | A=A';
|
---|
400 | BinSize(NbBinFile)=BinSize(NbBinFile)+SeqData.width*SeqData.height*SeqData.bytesperpixel*8; %record bits read
|
---|
401 | try
|
---|
402 | imwrite(A,OutputFile,'BitDepth',BitDepth) % case of 16 bit images
|
---|
403 | disp([OutputFile ' written']);
|
---|
404 | % [s,errormsg] = fileattrib(OutputFile,'-w','a'); %set images to read only '-w' for all users ('a')
|
---|
405 | % if ~s
|
---|
406 | % % disp_uvmat('ERROR',errormsg,checkrun);
|
---|
407 | % return
|
---|
408 | % end
|
---|
409 | catch ME
|
---|
410 | errormsg=ME.message;
|
---|
411 | return
|
---|
412 | end
|
---|
413 | end
|
---|
414 | end
|
---|
415 | if fid~=0
|
---|
416 | fclose(fid)
|
---|
417 | end
|
---|
418 |
|
---|
419 |
|
---|
420 |
|
---|
421 |
|
---|
422 | % for ifile=1:nbfield
|
---|
423 | % update_waitbar(WaitbarHandle,ifile/nbfield)
|
---|
424 | % if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
|
---|
425 | % disp('program stopped by user')
|
---|
426 | % break
|
---|
427 | % end
|
---|
428 | % [A,FileInfo,timestamps]=read_rdvision(filename,ifile);
|
---|
429 | % if ifile==1
|
---|
430 | % classA=class(A);
|
---|
431 | % if strcmp(classA,'uint8')
|
---|
432 | % BitDepth=8;
|
---|
433 | % else
|
---|
434 | % BitDepth=16;
|
---|
435 | % end
|
---|
436 | % end
|
---|
437 | % j1=[];
|
---|
438 | % if ~isequal(nbfield2,1)
|
---|
439 | % j1=mod(ifile-1+first_label,nbfield2)+1;
|
---|
440 | % end
|
---|
441 | % i1=floor((ifile-1+first_label)/nbfield2)+1;
|
---|
442 | % OutputFile=fullfile_uvmat(RootPath{1},OutputDir,'img','.png',NomTypeNew,i1,[],j1);
|
---|
443 | % try
|
---|
444 | % imwrite(A,OutputFile,'BitDepth',BitDepth) % case of 16 bit images
|
---|
445 | % disp([OutputFile ' written']);
|
---|
446 | % [s,errormsg] = fileattrib(OutputFile,'-w','a'); %set images to read only '-w' for all users ('a')
|
---|
447 | % if ~s
|
---|
448 | % disp_uvmat('ERROR',errormsg,checkrun);
|
---|
449 | % return
|
---|
450 | % end
|
---|
451 | % catch ME
|
---|
452 | % disp_uvmat('ERROR',ME.message,checkrun);
|
---|
453 | % return
|
---|
454 | % end
|
---|
455 | %
|
---|
456 | % end
|
---|
457 |
|
---|
458 | %'imadoc2struct_special': reads the xml file for image documentation
|
---|
459 | %------------------------------------------------------------------------
|
---|
460 | % function [s,errormsg]=imadoc2struct_special(ImaDoc,option)
|
---|
461 | %
|
---|
462 | % OUTPUT:
|
---|
463 | % s: structure representing ImaDoc
|
---|
464 | % s.Heading: information about the data hierarchical structure
|
---|
465 | % s.Time: matrix of times
|
---|
466 | % s.TimeUnit
|
---|
467 | % s.GeometryCalib: substructure containing the parameters for geometric calibration
|
---|
468 | % errormsg: error message
|
---|
469 | %
|
---|
470 | % INPUT:
|
---|
471 | % ImaDoc: full name of the xml input file with head key ImaDoc
|
---|
472 | % option: ='GeometryCalib': read the data of GeometryCalib, including source point coordinates
|
---|
473 |
|
---|
474 | function [s,errormsg]=imadoc2struct_special(ImaDoc,option)
|
---|
475 |
|
---|
476 | %% default input and output
|
---|
477 | if ~exist('option','var')
|
---|
478 | option='*';
|
---|
479 | end
|
---|
480 | errormsg=[];%default
|
---|
481 | s.Heading=[];%default
|
---|
482 | s.Time=[]; %default
|
---|
483 | s.TimeUnit=[]; %default
|
---|
484 | s.GeometryCalib=[];
|
---|
485 | tsai=[];%default
|
---|
486 |
|
---|
487 | %% opening the xml file
|
---|
488 | if exist(ImaDoc,'file')~=2, errormsg=[ ImaDoc ' does not exist']; return;end;%input file does not exist
|
---|
489 | try
|
---|
490 | t=xmltree(ImaDoc);
|
---|
491 | catch
|
---|
492 | errormsg={[ImaDoc ' is not a valid xml file']; lasterr};
|
---|
493 | display(errormsg);
|
---|
494 | return
|
---|
495 | end
|
---|
496 | uid_root=find(t,'/ImaDoc');
|
---|
497 | if isempty(uid_root), errormsg=[ImaDoc ' is not an image documentation file ImaDoc']; return; end;%not an ImaDoc .xml file
|
---|
498 |
|
---|
499 |
|
---|
500 | %% Heading
|
---|
501 | uid_Heading=find(t,'/ImaDoc/Heading');
|
---|
502 | if ~isempty(uid_Heading),
|
---|
503 | uid_Campaign=find(t,'/ImaDoc/Heading/Campaign');
|
---|
504 | uid_Exp=find(t,'/ImaDoc/Heading/Experiment');
|
---|
505 | uid_Device=find(t,'/ImaDoc/Heading/Device');
|
---|
506 | uid_Record=find(t,'/ImaDoc/Heading/Record');
|
---|
507 | uid_FirstImage=find(t,'/ImaDoc/Heading/ImageName');
|
---|
508 | s.Heading.Campaign=get(t,children(t,uid_Campaign),'value');
|
---|
509 | s.Heading.Experiment=get(t,children(t,uid_Exp),'value');
|
---|
510 | s.Heading.Device=get(t,children(t,uid_Device),'value');
|
---|
511 | if ~isempty(uid_Record)
|
---|
512 | s.Heading.Record=get(t,children(t,uid_Record),'value');
|
---|
513 | end
|
---|
514 | s.Heading.ImageName=get(t,children(t,uid_FirstImage),'value');
|
---|
515 | end
|
---|
516 |
|
---|
517 | %% Camera and timing
|
---|
518 | if strcmp(option,'*') || strcmp(option,'Camera')
|
---|
519 | uid_Camera=find(t,'/ImaDoc/Camera');
|
---|
520 | if ~isempty(uid_Camera)
|
---|
521 | uid_ImageSize=find(t,'/ImaDoc/Camera/ImageSize');
|
---|
522 | if ~isempty(uid_ImageSize);
|
---|
523 | ImageSize=get(t,children(t,uid_ImageSize),'value');
|
---|
524 | xindex=findstr(ImageSize,'x');
|
---|
525 | if length(xindex)>=2
|
---|
526 | s.Npx=str2double(ImageSize(1:xindex(1)-1));
|
---|
527 | s.Npy=str2double(ImageSize(xindex(1)+1:xindex(2)-1));
|
---|
528 | end
|
---|
529 | end
|
---|
530 | uid_TimeUnit=find(t,'/ImaDoc/Camera/TimeUnit');
|
---|
531 | if ~isempty(uid_TimeUnit)
|
---|
532 | s.TimeUnit=get(t,children(t,uid_TimeUnit),'value');
|
---|
533 | end
|
---|
534 | uid_BurstTiming=find(t,'/ImaDoc/Camera/BurstTiming');
|
---|
535 | if ~isempty(uid_BurstTiming)
|
---|
536 | for k=1:length(uid_BurstTiming)
|
---|
537 | subt=branch(t,uid_BurstTiming(k));%subtree under BurstTiming
|
---|
538 | % reading Dtk
|
---|
539 | Frequency=get_value(subt,'/BurstTiming/FrameFrequency',1);
|
---|
540 | Dtj=get_value(subt,'/BurstTiming/Dtj',[]);
|
---|
541 | Dtj=Dtj/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
|
---|
542 | NbDtj=get_value(subt,'/BurstTiming/NbDtj',[]);
|
---|
543 | %%%% correction RDvision %%%%
|
---|
544 | % NbDtj=NbDtj/numel(Dtj);
|
---|
545 | % s.NbDtj=NbDtj;
|
---|
546 | % %%%%
|
---|
547 | Dti=get_value(subt,'/BurstTiming/Dti',[]);
|
---|
548 | NbDti=get_value(subt,'/BurstTiming/NbDti',1);
|
---|
549 | %%%% correction RDvision %%%%
|
---|
550 | if isempty(Dti)% series
|
---|
551 | Dti=Dtj;
|
---|
552 | NbDti=NbDtj;
|
---|
553 | Dtj=[];
|
---|
554 | s.Dti=Dti;
|
---|
555 | s.NbDti=NbDti;
|
---|
556 | else
|
---|
557 | % NbDtj=NbDtj/numel(Dtj);%bursts
|
---|
558 | if ~isempty(NbDtj)
|
---|
559 | s.NbDtj=NbDtj/numel(Dtj);%bursts;
|
---|
560 | else
|
---|
561 | s.NbDtj=1;
|
---|
562 | end
|
---|
563 | end
|
---|
564 | %%%% %%%%
|
---|
565 | Dti=Dti/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
|
---|
566 |
|
---|
567 | Time_val=get_value(subt,'/BurstTiming/Time',0);%time in TimeUnit
|
---|
568 | if ~isempty(Dti)
|
---|
569 | Dti=reshape(Dti'*ones(1,NbDti),NbDti*numel(Dti),1); %concatene Dti vector NbDti times
|
---|
570 | Time_val=[Time_val;Time_val(end)+cumsum(Dti)];%append the times defined by the intervals Dti
|
---|
571 | end
|
---|
572 | if ~isempty(Dtj)
|
---|
573 | Dtj=reshape(Dtj'*ones(1,s.NbDtj),1,s.NbDtj*numel(Dtj)); %concatene Dtj vector NbDtj times
|
---|
574 | Dtj=[0 Dtj];
|
---|
575 | Time_val=Time_val*ones(1,numel(Dtj))+ones(numel(Time_val),1)*cumsum(Dtj);% produce a time matrix with Dtj
|
---|
576 | end
|
---|
577 | % reading Dtk
|
---|
578 | Dtk=get_value(subt,'/BurstTiming/Dtk',[]);
|
---|
579 | NbDtk=get_value(subt,'/BurstTiming/NbDtk',1);
|
---|
580 | %%%% correction RDvision %%%%
|
---|
581 | if ~isequal(NbDtk,1)
|
---|
582 | NbDtk=-1+(NbDtk+1)/(NbDti+1);
|
---|
583 | end
|
---|
584 | s.NbDtk=NbDtk;
|
---|
585 | %%%%%
|
---|
586 | if isempty(Dtk)
|
---|
587 | s.Time=[s.Time;Time_val];
|
---|
588 | else
|
---|
589 | for kblock=1:NbDtk+1
|
---|
590 | Time_val_k=Time_val+(kblock-1)*Dtk;
|
---|
591 | s.Time=[s.Time;Time_val_k];
|
---|
592 | end
|
---|
593 | end
|
---|
594 | end
|
---|
595 | end
|
---|
596 | end
|
---|
597 | end
|
---|
598 |
|
---|
599 | %% motor
|
---|
600 | if strcmp(option,'*') || strcmp(option,'GeometryCalib')
|
---|
601 | uid_subtree=find(t,'/ImaDoc/TranslationMotor');
|
---|
602 | if length(uid_subtree)==1
|
---|
603 | subt=branch(t,uid_subtree);%subtree under GeometryCalib
|
---|
604 | [s.TranslationMotor,errormsg]=read_subtree(subt,{'Nbslice','ZStart','ZEnd'},[1 1 1],[1 1 1]);
|
---|
605 | end
|
---|
606 | end
|
---|
607 | %% geometric calibration
|
---|
608 | if strcmp(option,'*') || strcmp(option,'GeometryCalib')
|
---|
609 | uid_GeometryCalib=find(t,'/ImaDoc/GeometryCalib');
|
---|
610 | if ~isempty(uid_GeometryCalib)
|
---|
611 | if length(uid_GeometryCalib)>1
|
---|
612 | errormsg=['More than one GeometryCalib in ' filecivxml];
|
---|
613 | return
|
---|
614 | end
|
---|
615 | subt=branch(t,uid_GeometryCalib);%subtree under GeometryCalib
|
---|
616 | cont=get(subt,1,'contents');
|
---|
617 | if ~isempty(cont)
|
---|
618 | uid_CalibrationType=find(subt,'/GeometryCalib/CalibrationType');
|
---|
619 | if isequal(length(uid_CalibrationType),1)
|
---|
620 | tsai.CalibrationType=get(subt,children(subt,uid_CalibrationType),'value');
|
---|
621 | end
|
---|
622 | uid_CoordUnit=find(subt,'/GeometryCalib/CoordUnit');
|
---|
623 | if isequal(length(uid_CoordUnit),1)
|
---|
624 | tsai.CoordUnit=get(subt,children(subt,uid_CoordUnit),'value');
|
---|
625 | end
|
---|
626 | uid_fx_fy=find(subt,'/GeometryCalib/fx_fy');
|
---|
627 | focal=[];%default fro old convention (Reg Wilson)
|
---|
628 | if isequal(length(uid_fx_fy),1)
|
---|
629 | tsai.fx_fy=str2num(get(subt,children(subt,uid_fx_fy),'value'));
|
---|
630 | else %old convention (Reg Wilson)
|
---|
631 | uid_focal=find(subt,'/GeometryCalib/focal');
|
---|
632 | uid_dpx_dpy=find(subt,'/GeometryCalib/dpx_dpy');
|
---|
633 | uid_sx=find(subt,'/GeometryCalib/sx');
|
---|
634 | if ~isempty(uid_focal) && ~isempty(uid_dpx_dpy) && ~isempty(uid_sx)
|
---|
635 | dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value'));
|
---|
636 | sx=str2num(get(subt,children(subt,uid_sx),'value'));
|
---|
637 | focal=str2num(get(subt,children(subt,uid_focal),'value'));
|
---|
638 | tsai.fx_fy(1)=sx*focal/dpx_dpy(1);
|
---|
639 | tsai.fx_fy(2)=focal/dpx_dpy(2);
|
---|
640 | end
|
---|
641 | end
|
---|
642 | uid_Cx_Cy=find(subt,'/GeometryCalib/Cx_Cy');
|
---|
643 | if ~isempty(uid_Cx_Cy)
|
---|
644 | tsai.Cx_Cy=str2num(get(subt,children(subt,uid_Cx_Cy),'value'));
|
---|
645 | end
|
---|
646 | uid_kc=find(subt,'/GeometryCalib/kc');
|
---|
647 | if ~isempty(uid_kc)
|
---|
648 | tsai.kc=str2double(get(subt,children(subt,uid_kc),'value'));
|
---|
649 | else %old convention (Reg Wilson)
|
---|
650 | uid_kappa1=find(subt,'/GeometryCalib/kappa1');
|
---|
651 | if ~isempty(uid_kappa1)&& ~isempty(focal)
|
---|
652 | kappa1=str2double(get(subt,children(subt,uid_kappa1),'value'));
|
---|
653 | tsai.kc=-kappa1*focal*focal;
|
---|
654 | end
|
---|
655 | end
|
---|
656 | uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz');
|
---|
657 | if ~isempty(uid_Tx_Ty_Tz)
|
---|
658 | tsai.Tx_Ty_Tz=str2num(get(subt,children(subt,uid_Tx_Ty_Tz),'value'));
|
---|
659 | end
|
---|
660 | uid_R=find(subt,'/GeometryCalib/R');
|
---|
661 | if ~isempty(uid_R)
|
---|
662 | RR=get(subt,children(subt,uid_R),'value');
|
---|
663 | if length(RR)==3
|
---|
664 | tsai.R=[str2num(RR{1});str2num(RR{2});str2num(RR{3})];
|
---|
665 | end
|
---|
666 | end
|
---|
667 |
|
---|
668 | %look for laser plane definitions
|
---|
669 | uid_Angle=find(subt,'/GeometryCalib/PlaneAngle');
|
---|
670 | uid_Pos=find(subt,'/GeometryCalib/SliceCoord');
|
---|
671 | if isempty(uid_Pos)
|
---|
672 | uid_Pos=find(subt,'/GeometryCalib/PlanePos');%old convention
|
---|
673 | end
|
---|
674 | if ~isempty(uid_Angle)
|
---|
675 | tsai.PlaneAngle=str2num(get(subt,children(subt,uid_Angle),'value'));
|
---|
676 | end
|
---|
677 | if ~isempty(uid_Pos)
|
---|
678 | for j=1:length(uid_Pos)
|
---|
679 | tsai.SliceCoord(j,:)=str2num(get(subt,children(subt,uid_Pos(j)),'value'));
|
---|
680 | end
|
---|
681 | uid_DZ=find(subt,'/GeometryCalib/SliceDZ');
|
---|
682 | uid_NbSlice=find(subt,'/GeometryCalib/NbSlice');
|
---|
683 | if ~isempty(uid_DZ) && ~isempty(uid_NbSlice)
|
---|
684 | DZ=str2double(get(subt,children(subt,uid_DZ),'value'));
|
---|
685 | NbSlice=get(subt,children(subt,uid_NbSlice),'value');
|
---|
686 | if isequal(NbSlice,'volume')
|
---|
687 | tsai.NbSlice='volume';
|
---|
688 | NbSlice=NbDtj+1;
|
---|
689 | else
|
---|
690 | tsai.NbSlice=str2double(NbSlice);
|
---|
691 | end
|
---|
692 | tsai.SliceCoord=ones(NbSlice,1)*tsai.SliceCoord+DZ*(0:NbSlice-1)'*[0 0 1];
|
---|
693 | end
|
---|
694 | end
|
---|
695 | tsai.SliceAngle=get_value(subt,'/GeometryCalib/SliceAngle',[0 0 0]);
|
---|
696 | tsai.VolumeScan=get_value(subt,'/GeometryCalib/VolumeScan','n');
|
---|
697 | tsai.InterfaceCoord=get_value(subt,'/GeometryCalib/InterfaceCoord',[0 0 0]);
|
---|
698 | tsai.RefractionIndex=get_value(subt,'/GeometryCalib/RefractionIndex',1);
|
---|
699 |
|
---|
700 | if strcmp(option,'GeometryCalib')
|
---|
701 | tsai.PointCoord=get_value(subt,'/GeometryCalib/SourceCalib/PointCoord',[0 0 0 0 0]);
|
---|
702 | end
|
---|
703 | s.GeometryCalib=tsai;
|
---|
704 | end
|
---|
705 | end
|
---|
706 | end
|
---|
707 |
|
---|
708 | %--------------------------------------------------
|
---|
709 | % read a subtree
|
---|
710 | % INPUT:
|
---|
711 | % t: xltree
|
---|
712 | % head_element: head elelemnt of the subtree
|
---|
713 | % Data, structure containing
|
---|
714 | % .Key: element name
|
---|
715 | % .Type: type of element ('charg', 'float'....)
|
---|
716 | % .NbOccur: nbre of occurrence, NaN for un specified number
|
---|
717 | function [s,errormsg]=read_subtree(subt,Data,NbOccur,NumTest)
|
---|
718 | %--------------------------------------------------
|
---|
719 | s=[];%default
|
---|
720 | errormsg='';
|
---|
721 | head_element=get(subt,1,'name');
|
---|
722 | cont=get(subt,1,'contents');
|
---|
723 | if ~isempty(cont)
|
---|
724 | for ilist=1:length(Data)
|
---|
725 | uid_key=find(subt,[head_element '/' Data{ilist}]);
|
---|
726 | if ~isequal(length(uid_key),NbOccur(ilist))
|
---|
727 | errormsg=['wrong number of occurence for ' Data{ilist}];
|
---|
728 | return
|
---|
729 | end
|
---|
730 | for ival=1:length(uid_key)
|
---|
731 | val=get(subt,children(subt,uid_key(ival)),'value');
|
---|
732 | if ~NumTest(ilist)
|
---|
733 | eval(['s.' Data{ilist} '=val;']);
|
---|
734 | else
|
---|
735 | eval(['s.' Data{ilist} '=str2double(val);'])
|
---|
736 | end
|
---|
737 | end
|
---|
738 | end
|
---|
739 | end
|
---|
740 |
|
---|
741 |
|
---|
742 | %--------------------------------------------------
|
---|
743 | % read an xml element
|
---|
744 | function val=get_value(t,label,default)
|
---|
745 | %--------------------------------------------------
|
---|
746 | val=default;
|
---|
747 | uid=find(t,label);%find the element iud(s)
|
---|
748 | if ~isempty(uid) %if the element named label exists
|
---|
749 | uid_child=children(t,uid);%find the children
|
---|
750 | if ~isempty(uid_child)
|
---|
751 | data=get(t,uid_child,'type');%get the type of child
|
---|
752 | if iscell(data)% case of multiple element
|
---|
753 | for icell=1:numel(data)
|
---|
754 | val_read=str2num(get(t,uid_child(icell),'value'));
|
---|
755 | if ~isempty(val_read)
|
---|
756 | val(icell,:)=val_read;
|
---|
757 | end
|
---|
758 | end
|
---|
759 | % val=val';
|
---|
760 | else % case of unique element value
|
---|
761 | val_read=str2num(get(t,uid_child,'value'));
|
---|
762 | if ~isempty(val_read)
|
---|
763 | val=val_read;
|
---|
764 | else
|
---|
765 | val=get(t,uid_child,'value');%char string data
|
---|
766 | end
|
---|
767 | end
|
---|
768 | end
|
---|
769 | end
|
---|
770 |
|
---|
771 |
|
---|
772 |
|
---|
773 |
|
---|