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