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