[907] | 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 | %
|
---|
[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
|
---|
| 28 | % .RunMode='local','background', 'cluster': type of function use
|
---|
| 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 | %=======================================================================
|
---|
[977] | 44 | % Copyright 2008-2017, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
[907] | 45 | % http://www.legi.grenoble-inp.fr
|
---|
| 46 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
|
---|
| 47 | %
|
---|
| 48 | % This file is part of the toolbox UVMAT.
|
---|
| 49 | %
|
---|
| 50 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
| 51 | % it under the terms of the GNU General Public License as published
|
---|
| 52 | % by the Free Software Foundation; either version 2 of the license,
|
---|
| 53 | % or (at your option) any later version.
|
---|
| 54 | %
|
---|
| 55 | % UVMAT is distributed in the hope that it will be useful,
|
---|
| 56 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 57 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 58 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
| 59 | %=======================================================================
|
---|
| 60 |
|
---|
| 61 | function ParamOut=extract_rdvision(Param) %default output=relabel_i_j(Param)
|
---|
| 62 |
|
---|
| 63 | %% set the input elements needed on the GUI series when the action is selected in the menu ActionName
|
---|
| 64 | if isstruct(Param) && isequal(Param.Action.RUN,0)
|
---|
| 65 | ParamOut.AllowInputSort='off';...% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
|
---|
| 66 | ParamOut.WholeIndexRange='on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
|
---|
[928] | 67 | ParamOut.NbSlice=1; ...%nbre of slices, 1 prevents splitting in several processes, ('off' by default)
|
---|
[907] | 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)
|
---|
[922] | 73 | ParamOut.OutputDirExt='.extract';%set the output dir extension
|
---|
[929] | 74 | ParamOut.OutputSubDirMode='one'; %output folder given by the folder name of the first input line
|
---|
[907] | 75 | % detect the set of image folder
|
---|
| 76 | RootPath=Param.InputTable{1,1};
|
---|
| 77 | ListStruct=dir(RootPath);
|
---|
| 78 | ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
|
---|
| 79 | check_bad=strcmp('.',ListCells(1,:))|strcmp('..',ListCells(1,:));%detect the dir '.' to exclude it
|
---|
| 80 | check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
|
---|
| 81 | ListDir=ListCells(1,find(check_dir & ~check_bad));
|
---|
| 82 | % InputTable=cell(numel(ListDir),5);
|
---|
| 83 | % InputTable(:,2)=ListDir';
|
---|
| 84 | isel=0;
|
---|
| 85 | InputTable=Param.InputTable;
|
---|
| 86 | for ilist=1:numel(ListDir)
|
---|
| 87 | ListStructSub=dir(fullfile(RootPath,ListDir{ilist}));
|
---|
| 88 | ListCellSub=struct2cell(ListStructSub);% transform dir struct to a cell arrray
|
---|
| 89 | detect_seq=regexp(ListCellSub(1,:),'.seq$');
|
---|
| 90 | seq_index=find(~cellfun('isempty',detect_seq),1);
|
---|
| 91 | if ~isempty(seq_index)
|
---|
| 92 | % msgbox_uvmat('ERROR',['not seq file in ' ListDir{ilist} ': please check the input folders'])
|
---|
| 93 | % else
|
---|
| 94 | isel=isel+1;
|
---|
| 95 | InputTable{isel,1}=RootPath;
|
---|
| 96 | InputTable{isel,2}=ListDir{ilist};
|
---|
| 97 | RootFile=regexprep(ListCellSub{1,seq_index},'.seq$','');
|
---|
| 98 | InputTable{isel,3}=RootFile;
|
---|
| 99 | InputTable{isel,4}='*';
|
---|
| 100 | InputTable{isel,5}='.seq';
|
---|
| 101 | end
|
---|
| 102 | end
|
---|
| 103 | hseries=findobj(allchild(0),'Tag','series');% find the parent GUI 'series'
|
---|
| 104 | hhseries=guidata(hseries); %handles of the elements in 'series'
|
---|
| 105 | set(hhseries.InputTable,'Data',InputTable)
|
---|
| 106 | ParamOut.ActionInput.LogPath=RootPath;% indicate the path for the output info: 0_LOG ....
|
---|
| 107 | return
|
---|
| 108 | end
|
---|
| 109 |
|
---|
| 110 | ParamOut=[];
|
---|
| 111 | %%%%%%%%%%%% STANDARD PART %%%%%%%%%%%%
|
---|
| 112 | %% read input parameters from an xml file if input is a file name (batch mode)
|
---|
| 113 | checkrun=1;
|
---|
| 114 | if ischar(Param)
|
---|
| 115 | Param=xml2struct(Param);% read Param as input file (batch case)
|
---|
| 116 | checkrun=0;
|
---|
| 117 | end
|
---|
| 118 | hseries=findobj(allchild(0),'Tag','series');
|
---|
| 119 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
|
---|
| 120 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
|
---|
| 121 |
|
---|
| 122 | %% root input file(s) and type
|
---|
| 123 | RootPath=Param.InputTable{1,1};
|
---|
| 124 | if ~isempty(find(~strcmp(RootPath,Param.InputTable(:,1))))% if the Rootpath for each camera are not identical
|
---|
| 125 | disp_uvmat('ERROR','Rootpath for all cameras must be identical',checkrun)
|
---|
| 126 | return
|
---|
| 127 | end
|
---|
| 128 |
|
---|
| 129 | % get the set of input file names (cell array filecell), and the lists of
|
---|
| 130 | % input file or frame indices i1_series,i2_series,j1_series,j2_series
|
---|
| 131 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
|
---|
| 132 |
|
---|
| 133 | %OutputDir=[Param.OutputSubDir Param.OutputDirExt];
|
---|
| 134 |
|
---|
| 135 | % numbers of slices and file indices
|
---|
| 136 | nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
|
---|
| 137 | nbfield_i=size(i1_series{1},2); %nb of fields for the i index
|
---|
| 138 | nbfield=nbfield_j*nbfield_i; %total number of fields
|
---|
| 139 |
|
---|
| 140 | %determine the file type on each line from the first input file
|
---|
| 141 |
|
---|
| 142 | FileInfo=get_file_info(filecell{1,1});
|
---|
| 143 | if strcmp(FileInfo.FileType,'rdvision')
|
---|
| 144 | if ~isequal(FileInfo.NumberOfFrames,nbfield)
|
---|
[969] | 145 | disp_uvmat('WARNING',['the whole series of ' num2str(FileInfo.NumberOfFrames) ' images must be extracted at once'],checkrun)
|
---|
[907] | 146 | %rmfield(OutputDir)
|
---|
[922] | 147 | % return
|
---|
[907] | 148 | end
|
---|
| 149 | %% interactive input of specific parameters (for RDvision system)
|
---|
| 150 | display('converting images from RDvision system...')
|
---|
| 151 | else
|
---|
[969] | 152 | disp_uvmat('ERROR','the input is not from rdvision: a .seq or .sqb file must be opened',checkrun)
|
---|
[907] | 153 | return
|
---|
| 154 | end
|
---|
| 155 | t=xmltree;
|
---|
[930] | 156 |
|
---|
[907] | 157 | save(t,fullfile(RootPath,'Running.xml'))%create an xml file to indicate that processing takes place
|
---|
| 158 |
|
---|
| 159 | %% calibration data and timing: read the ImaDoc files
|
---|
| 160 | mode=''; %default
|
---|
| 161 | timecell={};
|
---|
| 162 | itime=0;
|
---|
| 163 | NbSlice_calib={};
|
---|
| 164 |
|
---|
| 165 | %SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
|
---|
| 166 |
|
---|
| 167 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 168 | %%% loop on the cameras ( #iview)
|
---|
| 169 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 170 | % RootPath=Param.InputTable(:,1);
|
---|
| 171 | % RootFile=Param.InputTable(:,3);
|
---|
| 172 | % SubDir=Param.InputTable(:,2);
|
---|
| 173 | % NomType=Param.InputTable(:,4);
|
---|
| 174 | % FileExt=Param.InputTable(:,5);
|
---|
| 175 |
|
---|
| 176 | % [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
|
---|
| 177 | % if size(time,1)>1
|
---|
| 178 | % diff_time=max(max(diff(time)));
|
---|
| 179 | % if diff_time>0
|
---|
| 180 | % disp_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)],checkrun)
|
---|
| 181 | % end
|
---|
| 182 | % end
|
---|
| 183 | %
|
---|
| 184 | % nbfield2=size(time,1);
|
---|
| 185 | checkpreserve=0;% if =1, will npreserve the original images, else it erases them at the end
|
---|
| 186 | for iview=1:size(Param.InputTable,1)
|
---|
[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')
|
---|
| 190 | break
|
---|
| 191 | end
|
---|
[922] | 192 | end
|
---|
[907] | 193 | if ~exist(filexml,'file')
|
---|
| 194 | disp_uvmat('ERROR',[filexml ' missing'],checkrun)
|
---|
| 195 | return
|
---|
| 196 | end
|
---|
[930] | 197 |
|
---|
[928] | 198 | newxml=fullfile(RootPath,Param.InputTable{iview,3});
|
---|
| 199 | newxml=regexprep(newxml,'_Master_Dalsa_4M180$','');%suppress '_Master_Dalsa_4M180'
|
---|
| 200 | newxml=[newxml '.xml'];
|
---|
[907] | 201 |
|
---|
[930] | 202 | %copyfile_modif(filexml,newxml); %copy the xml file in the upper folder
|
---|
| 203 |
|
---|
| 204 | %[XmlData,errormsg]=imadoc2struct(newxml);
|
---|
| 205 | % nbfield2=size(XmlData.Time,2)-1;
|
---|
| 206 | % if nbfield2>1
|
---|
| 207 | % NomTypeNew='_1_1';
|
---|
| 208 | % else
|
---|
| 209 | % NomTypeNew='_1';
|
---|
| 210 | % end
|
---|
[907] | 211 | %% get the names of .seq and .sqb files
|
---|
| 212 | switch Param.InputTable{iview,5}
|
---|
| 213 | case {'.seq','.sqb'}
|
---|
| 214 | filename_seq=fullfile(RootPath,Param.InputTable{iview,2},[Param.InputTable{iview,3} '.seq']);
|
---|
| 215 | filename_sqb=fullfile(RootPath,Param.InputTable{iview,2},[Param.InputTable{iview,3} '.sqb']);
|
---|
[930] | 216 | logdir=[Param.OutputSubDir Param.OutputDirExt];
|
---|
[929] | 217 | [success,errormsg] = copyfile(filename_seq,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.seq']); %copy the seq file in the upper folder
|
---|
| 218 | [success,errormsg] = copyfile(filename_sqb,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.sqb']); %copy the sqb file in the upper folder
|
---|
[907] | 219 | otherwise
|
---|
| 220 | errormsg='input file extension must be .seq or .sqb';
|
---|
| 221 | end
|
---|
| 222 | if ~exist(filename_seq,'file')
|
---|
| 223 | errormsg=[filename_seq ' does not exist'];
|
---|
| 224 | end
|
---|
| 225 | if ~isempty(errormsg)
|
---|
| 226 | disp_uvmat('ERRROR',errormsg,checkrun);
|
---|
| 227 | return
|
---|
| 228 | end
|
---|
| 229 |
|
---|
| 230 |
|
---|
| 231 | %% get data from .seq file
|
---|
| 232 | s=ini2struct(filename_seq);
|
---|
| 233 | SeqData=s.sequenceSettings;
|
---|
| 234 | SeqData.width=str2double(SeqData.width);
|
---|
| 235 | SeqData.height=str2double(SeqData.height);
|
---|
| 236 | SeqData.bytesperpixel=str2double(SeqData.bytesperpixel);
|
---|
| 237 | SeqData.nb_frames=str2double(s.sequenceSettings.numberoffiles);
|
---|
| 238 | if isempty(SeqData.binrepertoire)%used when binrepertoire empty, strange feature of rdvision
|
---|
| 239 | SeqData.binrepertoire=regexprep(s.sequenceSettings.bindirectory,'\\$','');%tranform Windows notation to Linux
|
---|
| 240 | SeqData.binrepertoire=regexprep(SeqData.binrepertoire,'\','/');
|
---|
| 241 | [tild,binrepertoire,DirExt]=fileparts(SeqData.binrepertoire);
|
---|
| 242 | SeqData.binrepertoire=[SeqData.binrepertoire DirExt];
|
---|
| 243 | end
|
---|
[930] | 244 |
|
---|
[907] | 245 |
|
---|
[931] | 246 |
|
---|
[907] | 247 | %% reading the .sqb file
|
---|
| 248 | m = memmapfile(filename_sqb,'Format', { 'uint32' [1 1] 'offset'; ...
|
---|
| 249 | 'uint32' [1 1] 'garbage1';...
|
---|
| 250 | 'double' [1 1] 'timestamp';...
|
---|
| 251 | 'uint32' [1 1] 'file_idx';...
|
---|
| 252 | 'uint32' [1 1] 'garbage2' },'Repeat',SeqData.nb_frames);
|
---|
| 253 |
|
---|
| 254 | %%%%%%%BRICOLAGE in case of unreadable .sqb file: remplace lecture du fichier
|
---|
| 255 | % ind=[111 114:211];%indices of bin files
|
---|
| 256 | % w=1024;%w=width of images in pixels
|
---|
| 257 | % h=1024;%h=height of images in pixels
|
---|
| 258 | % bpp=2;% nbre of bytes per pixel
|
---|
| 259 | % lengthimage=w*h*bpp;% lengthof an image record on the binary file
|
---|
| 260 | % nbimages=32; %nbre of images of each camera in a bin file
|
---|
| 261 | % for ii=1:32*numel(ind)
|
---|
| 262 | % data(ii).offset=mod(ii-1,32)*2*lengthimage+lengthimage;%Dalsa_2
|
---|
| 263 | % %data(ii).offset=mod(ii-1,32)*2*lengthimage;%Dalsa_1
|
---|
| 264 | % data(ii).file_idx=ind(ceil(ii/32));
|
---|
| 265 | % data(ii).timestamp=0.2*(ii-1);
|
---|
| 266 | % end
|
---|
| 267 | % m.Data=data;
|
---|
| 268 | %%%%%%%
|
---|
| 269 | timestamp=zeros(1,numel(m.Data));
|
---|
| 270 | for ii=1: numel(m.Data)
|
---|
| 271 | timestamp(ii)=m.Data(ii).timestamp;
|
---|
[930] | 272 | % j1=1;
|
---|
| 273 | % if ~isequal(nbfield2,1)
|
---|
| 274 | % j1=mod(ii-1,nbfield2)+1;
|
---|
| 275 | % end
|
---|
| 276 | % i1=floor((ii-1)/nbfield2)+1;
|
---|
| 277 | %diff_time(i1,j1)= timestamp(ii)-XmlData.Time(i1+1,j1+1);
|
---|
[907] | 278 | end
|
---|
[930] | 279 | [nbfield2,msg]=copyfile_modif(filexml,timestamp,newxml); %copy the xml file in the upper folder
|
---|
| 280 | [XmlData,errormsg]=imadoc2struct(newxml);% check reading of the new xml file
|
---|
| 281 | if ~isempty(errormsg)
|
---|
| 282 | disp(errormsg)
|
---|
| 283 | return
|
---|
| 284 | end
|
---|
[982] | 285 | difftime=XmlData.Time(2:end,2:end)-(reshape(timestamp(1:end),nbfield2,[]))';
|
---|
[930] | 286 | disp(['time from xml and timestamp differ by ' num2str(max(max(abs(difftime))))])
|
---|
| 287 | if max(abs(difftime))>0.01
|
---|
| 288 | checkpreserve=1;% will not erase the initial files, possibility of error
|
---|
| 289 | end
|
---|
[931] | 290 |
|
---|
| 291 | %% checking consistency with the xml file
|
---|
| 292 | if ~isequal(SeqData.nb_frames,numel(timestamp))
|
---|
| 293 | disp_uvmat('ERRROR',['inconsistent number of images ' num2str(SeqData.nb_frames) ' with respect to the xml file: ' num2str(numel(timestamp))] ,checkrun);
|
---|
| 294 | return
|
---|
| 295 | end
|
---|
| 296 |
|
---|
[930] | 297 | if nbfield2>1
|
---|
| 298 | NomTypeNew='_1_1';
|
---|
[909] | 299 | else
|
---|
[930] | 300 | NomTypeNew='_1';
|
---|
[907] | 301 | end
|
---|
[930] | 302 |
|
---|
[907] | 303 | [BinList,errormsg]=binread_rdv_series(RootPath,SeqData,m.Data,nbfield2,NomTypeNew);
|
---|
| 304 | if ~isempty(errormsg)
|
---|
| 305 | disp_uvmat('ERROR',errormsg,checkrun)
|
---|
| 306 | return
|
---|
| 307 | end
|
---|
[930] | 308 |
|
---|
[907] | 309 | % check the existence of the expected output image files (from the xml)
|
---|
[929] | 310 | FileDir=SeqData.sequencename;
|
---|
| 311 | FileDir=regexprep(FileDir,'_Master_Dalsa_4M180$','');%suppress '_Master_Dalsa_4M180'
|
---|
[931] | 312 | for i1=1:numel(timestamp)/nbfield2
|
---|
| 313 | for j1=1:nbfield2
|
---|
[929] | 314 | OutputFile=fullfile_uvmat(RootPath,FileDir,'img','.png',NomTypeNew,i1,[],j1);% TODO: set NomTypeNew from SeqData.mode
|
---|
[931] | 315 | try
|
---|
[907] | 316 | A=imread(OutputFile);% check image reading (stop if error)
|
---|
[931] | 317 | catch ME
|
---|
| 318 | disp(['checking ' OutputFile])
|
---|
| 319 | disp(ME.message)
|
---|
| 320 | end
|
---|
[907] | 321 | end
|
---|
| 322 | end
|
---|
| 323 | end
|
---|
[928] | 324 |
|
---|
| 325 | %% remove binary files if transfer OK
|
---|
| 326 | if ~checkpreserve
|
---|
[930] | 327 | for iview=1:size(Param.InputTable,1)
|
---|
| 328 | fullfile(RootPath,Param.InputTable{iview,2})
|
---|
| 329 |
|
---|
| 330 | [SUCCESS,MESSAGE]=rmdir(fullfile(RootPath,Param.InputTable{iview,2}),'s')
|
---|
[928] | 331 | end
|
---|
| 332 | end
|
---|
[922] | 333 | delete(fullfile(RootPath,'Running.xml'))%delete the xml file to indicate that processing is finished
|
---|
[907] | 334 |
|
---|
| 335 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 336 | %--------- reads a series of bin files
|
---|
[930] | 337 |
|
---|
[907] | 338 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 339 | function [BinList,errormsg]=binread_rdv_series(PathDir,SeqData,SqbData,nbfield2,NomTypeNew)
|
---|
[939] | 340 | % BINREAD_RDV Permet de lire les fichiers bin g???n???r???s par Hiris ??? partir du
|
---|
| 341 | % fichier seq associ???.
|
---|
[907] | 342 | % [IMGS,TIMESTAMPS,NB_FRAMES] = BINREAD_RDV(FILENAME,FRAME_IDX) lit
|
---|
[939] | 343 | % l'image d'indice FRAME_IDX de la s???quence FILENAME.
|
---|
[907] | 344 | %
|
---|
[939] | 345 | % Entr???es
|
---|
[907] | 346 | % -------
|
---|
[939] | 347 | % FILENAME : Nom du fichier s???quence (.seq).
|
---|
| 348 | % FRAME_IDX : Indice de l'image ??? lire. Si FRAME_IDX vaut -1 alors la
|
---|
| 349 | % s???quence est enti???rement lue. Si FRAME_IDX est un tableau d'indices
|
---|
[907] | 350 | % alors toutes les images d'incides correspondant sont lues. Si FRAME_IDX
|
---|
| 351 | % est un tableau vide alors aucune image n'est lue mais le nombre
|
---|
[939] | 352 | % d'images et tous les timestamps sont renvoy???s. Les indices commencent ???
|
---|
| 353 | % 1 et se termines ??? NB_FRAMES.
|
---|
[907] | 354 | %
|
---|
| 355 | % Sorties
|
---|
| 356 | % -------
|
---|
| 357 | % IMGS : Images de sortie.
|
---|
| 358 | % TIMESTAMPS : Timestaps des images lues.
|
---|
[939] | 359 | % NB_FRAMES : Nombres d'images dans la s???quence.
|
---|
[907] | 360 | NbBinFile=0;
|
---|
| 361 | BinSize=0;
|
---|
| 362 | fid=0;
|
---|
| 363 | errormsg='';
|
---|
[930] | 364 | BinList={};
|
---|
| 365 |
|
---|
[907] | 366 | classname=sprintf('uint%d',SeqData.bytesperpixel*8);
|
---|
| 367 |
|
---|
| 368 | classname=['*' classname];
|
---|
| 369 | BitDepth=8*SeqData.bytesperpixel;%needed to write images (8 or 16 bits)
|
---|
| 370 | binrepertoire=fullfile(PathDir,SeqData.binrepertoire);
|
---|
[928] | 371 | FileDir=SeqData.sequencename;
|
---|
| 372 | FileDir=regexprep(FileDir,'_Master_Dalsa_4M180$','');%suppress '_Master_Dalsa_4M180'
|
---|
| 373 | OutputDir=fullfile(PathDir,FileDir);
|
---|
[907] | 374 | if ~exist(OutputDir,'dir')
|
---|
| 375 | % errormsg=[OutputDir ' already exist, delete it first'];
|
---|
| 376 | % return
|
---|
| 377 | % end
|
---|
| 378 | [s,errormsg]=mkdir(OutputDir);
|
---|
| 379 |
|
---|
| 380 | if s==0
|
---|
| 381 | disp(errormsg)
|
---|
| 382 | return%not able to create new image dir
|
---|
| 383 | end
|
---|
| 384 | end
|
---|
| 385 | bin_file_counter=0;
|
---|
| 386 | for ii=1:SeqData.nb_frames
|
---|
| 387 | j1=[];
|
---|
| 388 | if ~isequal(nbfield2,1)
|
---|
| 389 | j1=mod(ii-1,nbfield2)+1;
|
---|
| 390 | end
|
---|
| 391 | i1=floor((ii-1)/nbfield2)+1;
|
---|
[928] | 392 | OutputFile=fullfile_uvmat(PathDir,FileDir,'img','.png',NomTypeNew,i1,[],j1);% TODO: set NomTypeNew from SeqData.mode
|
---|
[907] | 393 | fname=fullfile(binrepertoire,sprintf('%s%.5d.bin',SeqData.binfile,SqbData(ii).file_idx));
|
---|
[931] | 394 | if exist(OutputFile,'file')% do not recreate existing image file
|
---|
[907] | 395 | fid=0;
|
---|
| 396 | else
|
---|
| 397 | if fid==0 || ~strcmp(fname,fname_prev) % open the bin file if not in use
|
---|
| 398 | if fid~=0
|
---|
| 399 | fclose(fid);%close the previous bin file if relevant
|
---|
| 400 | end
|
---|
| 401 | [fid,msg]=fopen(fname,'rb');
|
---|
| 402 | if isequal(fid,-1)
|
---|
| 403 | errormsg=['error in opening ' fname ': ' msg];
|
---|
| 404 | return
|
---|
| 405 | else
|
---|
| 406 | disp([fname ' opened for reading'])
|
---|
| 407 | bin_file_counter=bin_file_counter+1;
|
---|
| 408 | BinList{bin_file_counter}=fname;
|
---|
| 409 | end
|
---|
| 410 | fseek(fid,SqbData(ii).offset,-1);%look at the right starting place in the bin file
|
---|
| 411 | NbBinFile=NbBinFile+1;%counter of binary files (for checking purpose)
|
---|
| 412 | BinSize(NbBinFile)=0;% strat counter for new bin file
|
---|
| 413 | else
|
---|
| 414 | fseek(fid,SqbData(ii).offset,-1);%look at the right starting place in the bin file
|
---|
| 415 | end
|
---|
| 416 | fname_prev=fname;
|
---|
| 417 | A=reshape(fread(fid,SeqData.width*SeqData.height,classname),SeqData.width,SeqData.height);%read the current image
|
---|
| 418 | A=A';
|
---|
| 419 | BinSize(NbBinFile)=BinSize(NbBinFile)+SeqData.width*SeqData.height*SeqData.bytesperpixel*8; %record bits read
|
---|
| 420 | try
|
---|
| 421 | imwrite(A,OutputFile,'BitDepth',BitDepth) % case of 16 bit images
|
---|
| 422 | disp([OutputFile ' written']);
|
---|
| 423 | % [s,errormsg] = fileattrib(OutputFile,'-w','a'); %set images to read only '-w' for all users ('a')
|
---|
| 424 | % if ~s
|
---|
| 425 | % % disp_uvmat('ERROR',errormsg,checkrun);
|
---|
| 426 | % return
|
---|
| 427 | % end
|
---|
| 428 | catch ME
|
---|
| 429 | errormsg=ME.message;
|
---|
| 430 | return
|
---|
| 431 | end
|
---|
| 432 | end
|
---|
| 433 | end
|
---|
| 434 | if fid~=0
|
---|
| 435 | fclose(fid)
|
---|
| 436 | end
|
---|
| 437 |
|
---|
| 438 |
|
---|
| 439 |
|
---|
| 440 |
|
---|
[930] | 441 | function [nbfield2,msg]=copyfile_modif(filexml,timestamp,newxml)
|
---|
| 442 | msg='';
|
---|
| 443 | t=xmltree(filexml);
|
---|
[907] | 444 |
|
---|
[930] | 445 | %% correct NbDtj
|
---|
| 446 | uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
|
---|
| 447 | uid_content=get(t,uid_NbDtj,'contents');
|
---|
| 448 | t=set(t,uid_content,'value','1');% set NbDtj to 1 (correct error in the xml file)
|
---|
[907] | 449 |
|
---|
[930] | 450 | %% check Dtj
|
---|
| 451 | uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj');
|
---|
| 452 | uid_content=get(t,uid_Dtj,'contents');
|
---|
[932] | 453 | Dtjstring=get(t,uid_content,'value');
|
---|
| 454 | if isempty(Dtjstring)
|
---|
| 455 | timestamp=timestamp';
|
---|
| 456 | nbfield2=1;
|
---|
[930] | 457 | else
|
---|
[932] | 458 | Dtj=str2num(get(t,uid_content,'value'));
|
---|
| 459 | nbfield2=numel(Dtj)+1;
|
---|
| 460 | timestamp=(reshape(timestamp,nbfield2,[]))';
|
---|
| 461 | diff_Dtj=diff(timestamp(1,:))-Dtj;
|
---|
| 462 | if max(abs(diff_Dtj))>min(Dtj)/1000
|
---|
| 463 | disp(['Dtj from xml file differs from time stamp by ' num2str(max(abs(diff_Dtj))) ', '])%'
|
---|
| 464 | else
|
---|
| 465 | disp('Dtj OK');
|
---|
| 466 | end
|
---|
[907] | 467 | end
|
---|
[930] | 468 | %% correct NbDti
|
---|
[939] | 469 | NbDti=size(timestamp,1)-1; %default for series or burst
|
---|
[930] | 470 | uid_motor_nbslice=find(t,'ImaDoc/TranslationMotor/Nbslice');
|
---|
[939] | 471 | uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
|
---|
| 472 | if ~isempty(uid_motor_nbslice)&& ~isempty(uid_NbDtk)
|
---|
[930] | 473 | uid_content=get(t,uid_motor_nbslice,'contents');
|
---|
| 474 | NbSlice=str2num(get(t,uid_content,'value'));
|
---|
| 475 | NbDti=NbSlice-1;
|
---|
[935] | 476 | uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
|
---|
| 477 | uid_content=get(t,uid_NbDti,'contents');
|
---|
| 478 | t=set(t,uid_content,'value',num2str(NbDti));
|
---|
[907] | 479 | end
|
---|
| 480 |
|
---|
[930] | 481 | %% adjust Dti
|
---|
| 482 | uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti');
|
---|
| 483 | uid_content=get(t,uid_Dti,'contents');
|
---|
| 484 | Dti=str2num(get(t,uid_content,'value'));
|
---|
| 485 | Dti_stamp=(timestamp(1+NbDti,1)-timestamp(1,1))/NbDti;
|
---|
| 486 | if abs(Dti_stamp-Dti)>Dti/1000
|
---|
| 487 | disp([msg 'Dti from xml file corrected by ' num2str(Dti_stamp-Dti) ', ']);%'
|
---|
| 488 | else
|
---|
| 489 | disp('Dti OK')
|
---|
[907] | 490 | end
|
---|
[930] | 491 | t=set(t,uid_content,'value',num2str(Dti_stamp));
|
---|
[907] | 492 |
|
---|
[930] | 493 | %% adjust Dtk
|
---|
| 494 | uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk');
|
---|
| 495 | if ~isempty(uid_Dtk)
|
---|
[949] | 496 | uid_content_Dtk=get(t,uid_Dtk,'contents');
|
---|
| 497 | Dtk=str2num(get(t,uid_content_Dtk,'value'));
|
---|
| 498 | uid_content_NbDtk=get(t,uid_NbDtk,'contents');
|
---|
| 499 | NbDtk=str2num(get(t,uid_content_NbDtk,'value'));
|
---|
| 500 | Dtk_stamp=(timestamp(end-NbDti,1)-timestamp(1,1))/NbDtk;
|
---|
| 501 | if abs(Dtk_stamp-Dtk)>Dtk/1000
|
---|
| 502 | disp(['Dtk from xml file corrected by ' num2str(Dtk_stamp-Dtk)]);
|
---|
| 503 | else
|
---|
| 504 | disp('Dtk OK')
|
---|
| 505 | end
|
---|
| 506 | t=set(t,uid_content_Dtk,'value',num2str(Dtk_stamp));
|
---|
[907] | 507 | end
|
---|
| 508 |
|
---|
[930] | 509 | save(t,newxml)
|
---|
[949] | 510 | [success,errormsg] = fileattrib(newxml,'+w','g');% allow writing access for the group of users
|
---|
| 511 | if success==0
|
---|
| 512 | disp({['warning: unable to set group write access to ' newxml ':']; errormsg});%error message for directory creation
|
---|
[969] | 513 | msg=errormsg;
|
---|
[949] | 514 | end
|
---|
[907] | 515 |
|
---|
| 516 |
|
---|
| 517 |
|
---|