[809] | 1 | %=======================================================================
|
---|
[1107] | 2 | % Copyright 2008-2022, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
[809] | 3 | % http://www.legi.grenoble-inp.fr
|
---|
| 4 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
|
---|
| 5 | %
|
---|
| 6 | % This file is part of the toolbox UVMAT.
|
---|
| 7 | %
|
---|
| 8 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
| 9 | % it under the terms of the GNU General Public License as published
|
---|
| 10 | % by the Free Software Foundation; either version 2 of the license,
|
---|
| 11 | % or (at your option) any later version.
|
---|
| 12 | %
|
---|
| 13 | % UVMAT is distributed in the hope that it will be useful,
|
---|
| 14 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 16 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
| 17 | %=======================================================================
|
---|
| 18 |
|
---|
[790] | 19 | function [A,FileInfo,timestamps,errormsg]=read_rdvision(filename,frame_idx)
|
---|
[991] | 20 | % BINREAD_RDV Permet de lire les fichiers bin g???n???r???s par Hiris ??? partir du
|
---|
| 21 | % fichier seq associ???.
|
---|
[785] | 22 | % [IMGS,TIMESTAMPS,NB_FRAMES] = BINREAD_RDV(FILENAME,FRAME_IDX) lit
|
---|
[991] | 23 | % l'image d'indice FRAME_IDX de la s???quence FILENAME.
|
---|
[785] | 24 | %
|
---|
[991] | 25 | % Entr???es
|
---|
[785] | 26 | % -------
|
---|
[991] | 27 | % FILENAME : Nom du fichier s???quence (.seq).
|
---|
| 28 | % FRAME_IDX : Indice de l'image ??? lire. Si FRAME_IDX vaut -1 alors la
|
---|
| 29 | % s???quence est enti???rement lue. Si FRAME_IDX est un tableau d'indices
|
---|
[785] | 30 | % alors toutes les images d'incides correspondant sont lues. Si FRAME_IDX
|
---|
| 31 | % est un tableau vide alors aucune image n'est lue mais le nombre
|
---|
[991] | 32 | % d'images et tous les timestamps sont renvoy???s. Les indices commencent ???
|
---|
| 33 | % 1 et se termines ??? NB_FRAMES.
|
---|
[785] | 34 | %
|
---|
| 35 | % Sorties
|
---|
| 36 | % -------
|
---|
| 37 | % IMGS : Images de sortie.
|
---|
| 38 | % TIMESTAMPS : Timestaps des images lues.
|
---|
[1106] | 39 | % NB_FRAMES : Nombres d'images dans la sequence.
|
---|
[785] | 40 |
|
---|
[790] | 41 | errormsg='';
|
---|
[785] | 42 | if nargin<2% no frame indices specified
|
---|
| 43 | frame_idx=-1;% all the images in the series are read
|
---|
| 44 | end
|
---|
| 45 | A=[];
|
---|
| 46 | timestamps=[];
|
---|
[790] | 47 | [PathDir,RootFile,Ext]=fileparts(filename);
|
---|
| 48 | RootPath=fileparts(PathDir);
|
---|
| 49 | switch Ext
|
---|
| 50 | case '.seq'
|
---|
| 51 | filename_seq=filename;
|
---|
| 52 | filename_sqb=fullfile(PathDir,[RootFile '.sqb']);
|
---|
| 53 | case '.sqb'
|
---|
| 54 | filename_seq=fullfile(PathDir,[RootFile '.seq']);
|
---|
| 55 | filename_sqb=filename;
|
---|
| 56 | otherwise
|
---|
| 57 | errormsg='input file extension must be .seq or .sqb';
|
---|
| 58 | end
|
---|
| 59 | if ~exist(filename_seq,'file')
|
---|
| 60 | errormsg=[filename_seq ' does not exist'];
|
---|
| 61 | return
|
---|
| 62 | end
|
---|
| 63 | s=ini2struct(filename_seq);
|
---|
[785] | 64 | FileInfo=s.sequenceSettings;
|
---|
[790] | 65 | if isfield(s.sequenceSettings,'numberoffiles')
|
---|
| 66 | FileInfo.NumberOfFrames=str2double(s.sequenceSettings.numberoffiles);
|
---|
| 67 | FileInfo.FrameRate=str2double(s.sequenceSettings.framepersecond);
|
---|
| 68 | FileInfo.ColorType='grayscale';
|
---|
[1032] | 69 | FileInfo.TimeName='timestamp';
|
---|
[790] | 70 | else
|
---|
| 71 | FileInfo.FileType='';
|
---|
| 72 | return
|
---|
| 73 | end
|
---|
| 74 | FileInfo.FileType='rdvision'; % file used to store info from image acquisition systems of rdvision
|
---|
| 75 | nbfield=numel(fieldnames(FileInfo));
|
---|
| 76 | FileInfo=orderfields(FileInfo,[nbfield nbfield-1 nbfield-2 (1:nbfield-3)]); %reorder the fields of fileInfo for clarity
|
---|
[785] | 77 |
|
---|
| 78 | % read the images the input frame_idxis not empty
|
---|
| 79 | if ~isempty(frame_idx)
|
---|
| 80 | w=str2double(FileInfo.width);
|
---|
| 81 | h=str2double(FileInfo.height);
|
---|
| 82 | bpp=str2double(FileInfo.bytesperpixel);
|
---|
| 83 | bin_file=FileInfo.binfile;
|
---|
[796] | 84 | % bin_file='Dalsa1_';
|
---|
[785] | 85 | nb_frames=str2double(FileInfo.numberoffiles);
|
---|
[797] | 86 | %%%% reading the .sqb file
|
---|
[790] | 87 | m = memmapfile(filename_sqb,'Format', { 'uint32' [1 1] 'offset'; ...
|
---|
[785] | 88 | 'uint32' [1 1] 'garbage1';...
|
---|
| 89 | 'double' [1 1] 'timestamp';...
|
---|
| 90 | 'uint32' [1 1] 'file_idx';...
|
---|
[797] | 91 | 'uint32' [1 1] 'garbage2' },'Repeat',nb_frames);
|
---|
[785] | 92 | data=m.Data;
|
---|
[797] | 93 | %%%%%%%BRICOLAGE in case of unreadable .sqb file
|
---|
[896] | 94 | % ind=[144 149:646];%indices of bin files
|
---|
| 95 | % lengthimage=w*h*bpp;% lengthof an image record on the binary file
|
---|
[796] | 96 | % for ii=1:32*numel(ind)
|
---|
[797] | 97 | % data(ii).offset=mod(ii-1,32)*2*lengthimage+lengthimage;%Dalsa_2
|
---|
| 98 | % %data(ii).offset=mod(ii-1,32)*2*lengthimage;%Dalsa_1
|
---|
[796] | 99 | % data(ii).file_idx=ind(ceil(ii/32));
|
---|
[797] | 100 | % data(ii).timestamp=0.2*(ii-1);
|
---|
[796] | 101 | % end
|
---|
[797] | 102 | %%%%%%%
|
---|
[785] | 103 | timestamps=[data.timestamp];
|
---|
[796] | 104 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
[785] | 105 | if frame_idx==-1
|
---|
| 106 | frame_idx=1:nb_frames;
|
---|
| 107 | end
|
---|
| 108 |
|
---|
| 109 | classname=sprintf('uint%d',bpp*8);
|
---|
| 110 | A=zeros([h,w,length(frame_idx)],classname);
|
---|
| 111 |
|
---|
| 112 | classname=['*' classname];
|
---|
| 113 |
|
---|
| 114 | for i=1:length(frame_idx)
|
---|
| 115 | ii=frame_idx(i);
|
---|
[794] | 116 | if ~isempty(FileInfo.binrepertoire)
|
---|
| 117 | binrepertoire=FileInfo.binrepertoire;
|
---|
| 118 | else %used when binrepertoire empty, strange feature of rdvision
|
---|
| 119 | binrepertoire=regexprep(FileInfo.bindirectory,'\\$','');%tranform Windows notation to Linux
|
---|
| 120 | binrepertoire=regexprep(binrepertoire,'\','/');
|
---|
| 121 | [tild,binrepertoire,DirExt]=fileparts(binrepertoire);
|
---|
[991] | 122 | binrepertoire=[binrepertoire DirExt];
|
---|
[794] | 123 | end
|
---|
[796] | 124 | % binrepertoire='2014-07-04T10.48.46'% case FJORD5a %%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
[1047] | 125 | % binrepertoire='2017-01-19T22.12.182'% EXP14 %%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
[794] | 126 | binfile=fullfile(RootPath,binrepertoire,sprintf('%s%.5d.bin',bin_file,data(ii).file_idx));
|
---|
[1058] | 127 | if ~exist(binfile,'file')
|
---|
| 128 | errormsg=[binfile ' does not exist'];
|
---|
[1106] | 129 | FileInfo.StartTime=regexprep(FileInfo.binrepertoire,'T',' ');
|
---|
| 130 | FileInfo.EndTime=datestr(datenum(FileInfo.StartTime,'yyyy-mm-dd HH.MM.SS')+timestamps(end)/86400);
|
---|
| 131 | disp(FileInfo)
|
---|
[1058] | 132 | return
|
---|
| 133 | else
|
---|
[785] | 134 | fid=fopen(binfile,'rb');
|
---|
| 135 | fseek(fid,data(ii).offset,-1);
|
---|
| 136 | A(:,:,i)=reshape(fread(fid,w*h,classname),w,h)';
|
---|
| 137 | fclose(fid);
|
---|
[1058] | 138 | end
|
---|
[785] | 139 | end
|
---|
| 140 |
|
---|
| 141 | if ~isempty(frame_idx)
|
---|
| 142 | timestamps=timestamps(frame_idx);
|
---|
[1106] | 143 | end
|
---|
| 144 | FileInfo.StartTime=regexprep(FileInfo.binrepertoire,'T',' ');
|
---|
| 145 | FileInfo.EndTime=datestr(datenum(FileInfo.StartTime,'yyyy-mm-dd HH.MM.SS')+timestamps(end)/86400);
|
---|
| 146 | disp(FileInfo)
|
---|
[785] | 147 | end
|
---|
| 148 |
|
---|
[1106] | 149 |
|
---|
| 150 |
|
---|
[785] | 151 | function Result = ini2struct(FileName)
|
---|
| 152 | %==========================================================================
|
---|
| 153 | % Author: Andriy Nych ( nych.andriy@gmail.com )
|
---|
| 154 | % Version: 733341.4155741782200
|
---|
| 155 | %==========================================================================
|
---|
| 156 | %
|
---|
| 157 | % INI = ini2struct(FileName)
|
---|
| 158 | %
|
---|
| 159 | % This function parses INI file FileName and returns it as a structure with
|
---|
| 160 | % section names and keys as fields.
|
---|
| 161 | %
|
---|
| 162 | % Sections from INI file are returned as fields of INI structure.
|
---|
| 163 | % Each fiels (section of INI file) in turn is structure.
|
---|
| 164 | % It's fields are variables from the corresponding section of the INI file.
|
---|
| 165 | %
|
---|
| 166 | % If INI file contains "oprhan" variables at the beginning, they will be
|
---|
| 167 | % added as fields to INI structure.
|
---|
| 168 | %
|
---|
| 169 | % Lines starting with ';' and '#' are ignored (comments).
|
---|
| 170 | %
|
---|
| 171 | % See example below for more information.
|
---|
| 172 | %
|
---|
| 173 | % Usually, INI files allow to put spaces and numbers in section names
|
---|
| 174 | % without restrictions as long as section name is between '[' and ']'.
|
---|
| 175 | % It makes people crazy to convert them to valid Matlab variables.
|
---|
| 176 | % For this purpose Matlab provides GENVARNAME function, which does
|
---|
| 177 | % "Construct a valid MATLAB variable name from a given candidate".
|
---|
| 178 | % See 'help genvarname' for more information.
|
---|
| 179 | %
|
---|
| 180 | % The INI2STRUCT function uses the GENVARNAME to convert strange INI
|
---|
| 181 | % file string into valid Matlab field names.
|
---|
| 182 | %
|
---|
| 183 | % [ test.ini ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
---|
| 184 | %
|
---|
| 185 | % SectionlessVar1=Oops
|
---|
| 186 | % SectionlessVar2=I did it again ;o)
|
---|
| 187 | % [Application]
|
---|
| 188 | % Title = Cool program
|
---|
| 189 | % LastDir = c:\Far\Far\Away
|
---|
| 190 | % NumberOFSections = 2
|
---|
| 191 | % [1st section]
|
---|
| 192 | % param1 = val1
|
---|
| 193 | % Param 2 = Val 2
|
---|
| 194 | % [Section #2]
|
---|
| 195 | % param1 = val1
|
---|
| 196 | % Param 2 = Val 2
|
---|
| 197 | %
|
---|
| 198 | % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
---|
| 199 | %
|
---|
| 200 | % The function converts this INI file it to the following structure:
|
---|
| 201 | %
|
---|
| 202 | % [ MatLab session (R2006b) ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
---|
| 203 | % >> INI = ini2struct('test.ini');
|
---|
| 204 | % >> disp(INI)
|
---|
| 205 | % sectionlessvar1: 'Oops'
|
---|
| 206 | % sectionlessvar2: 'I did it again ;o)'
|
---|
| 207 | % application: [1x1 struct]
|
---|
| 208 | % x1stSection: [1x1 struct]
|
---|
| 209 | % section0x232: [1x1 struct]
|
---|
| 210 | %
|
---|
| 211 | % >> disp(INI.application)
|
---|
| 212 | % title: 'Cool program'
|
---|
| 213 | % lastdir: 'c:\Far\Far\Away'
|
---|
| 214 | % numberofsections: '2'
|
---|
| 215 | %
|
---|
| 216 | % >> disp(INI.x1stSection)
|
---|
| 217 | % param1: 'val1'
|
---|
| 218 | % param2: 'Val 2'
|
---|
| 219 | %
|
---|
| 220 | % >> disp(INI.section0x232)
|
---|
| 221 | % param1: 'val1'
|
---|
| 222 | % param2: 'Val 2'
|
---|
| 223 | %
|
---|
| 224 | % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
---|
| 225 | %
|
---|
| 226 | % NOTE.
|
---|
| 227 | % WhatToDoWithMyVeryCoolSectionAndVariableNamesInIniFileMyVeryCoolProgramWrites?
|
---|
| 228 | % GENVARNAME also does the following:
|
---|
| 229 | % "Any string that exceeds NAMELENGTHMAX is truncated". (doc genvarname)
|
---|
| 230 | % Period.
|
---|
| 231 | %
|
---|
| 232 | % =========================================================================
|
---|
| 233 | Result = []; % we have to return something
|
---|
| 234 | CurrMainField = ''; % it will be used later
|
---|
| 235 | f = fopen(FileName,'r'); % open file
|
---|
| 236 | while ~feof(f) % and read until it ends
|
---|
| 237 | s = strtrim(fgetl(f)); % Remove any leading/trailing spaces
|
---|
| 238 | if isempty(s)
|
---|
| 239 | continue;
|
---|
| 240 | end;
|
---|
| 241 | if (s(1)==';') % ';' start comment lines
|
---|
| 242 | continue;
|
---|
| 243 | end;
|
---|
| 244 | if (s(1)=='#') % '#' start comment lines
|
---|
| 245 | continue;
|
---|
| 246 | end;
|
---|
| 247 | if ( s(1)=='[' ) && (s(end)==']' )
|
---|
| 248 | % We found section
|
---|
| 249 | CurrMainField = genvarname(lower(s(2:end-1)));
|
---|
| 250 | Result.(CurrMainField) = []; % Create field in Result
|
---|
| 251 | else
|
---|
| 252 | % ??? This is not a section start
|
---|
| 253 | [par,val] = strtok(s, '=');
|
---|
| 254 | val = CleanValue(val);
|
---|
| 255 | if ~isempty(CurrMainField)
|
---|
| 256 | % But we found section before and have to fill it
|
---|
| 257 | Result.(CurrMainField).(lower(genvarname(par))) = val;
|
---|
| 258 | else
|
---|
| 259 | % No sections found before. Orphan value
|
---|
| 260 | Result.(lower(genvarname(par))) = val;
|
---|
| 261 | end
|
---|
| 262 | end
|
---|
| 263 | end
|
---|
| 264 | fclose(f);
|
---|
| 265 | return;
|
---|
| 266 |
|
---|
| 267 | function res = CleanValue(s)
|
---|
| 268 | res = strtrim(s);
|
---|
| 269 | if strcmpi(res(1),'=')
|
---|
| 270 | res(1)=[];
|
---|
| 271 | end
|
---|
| 272 | res = strtrim(res);
|
---|
| 273 | return;
|
---|