[784] | 1 | %'get_file_info': determine info about a file (image, multimage, civdata,...) . |
---|
| 2 | %------------------------------------------------------------------------ |
---|
| 3 | % [FileInfo,VideoObject]=get_file_info(fileinput) |
---|
| 4 | % |
---|
| 5 | % OUTPUT: |
---|
| 6 | % FileInfo: structure containing info on the file (case of images or video), in particular |
---|
| 7 | % .FileType: type of file, needed as input of read_field.m |
---|
[1033] | 8 | % ='figure': Matlab figure |
---|
[1089] | 9 | % ='mat': Matlab data file |
---|
[1033] | 10 | % ='xml': xml file |
---|
| 11 | % ='xls': Excel file |
---|
| 12 | % ='dat': text file for data, |
---|
| 13 | % ='image': image format recognised by Matlab |
---|
| 14 | % ='multimage': image format recognised by Matlab with multiple frames |
---|
| 15 | % ='video': video movie file |
---|
| 16 | % ='mmreader': video from old versions of Matlab (<2009) |
---|
| 17 | % ='rdvision': images in binary format from company rdvision |
---|
| 18 | % ='image_DaVis': images from softwar DaVis (company LaVision) |
---|
| 19 | % ='cine_phantom': images from fast camera Phantom |
---|
| 20 | % ='bin': binary file without specific organisation |
---|
| 21 | % ='netcdf': netcdf file |
---|
| 22 | % ='civdata': netcdf files provided by civ_series |
---|
| 23 | % ='civx': netcdf files provided by the obsolete program civx (in fortran) |
---|
| 24 | % ='pivdata_fluidimage': PIV data from software 'fluidimage' |
---|
[1040] | 25 | % .FieldType='image' for all kinds of images and movies, =FileType else |
---|
| 26 | % .FileIndexing='on'/'off', for data files (when series of indexed files are expected) |
---|
[784] | 27 | % .Height: image height in pixels |
---|
| 28 | % .Width: image width in pixels |
---|
| 29 | % .BitDepth: nbre of bits per pixel (8 of 16) |
---|
| 30 | % .ColorType: 'greyscale' or 'color' |
---|
[1040] | 31 | % .NumberOfFrames: defined for images or movies |
---|
[784] | 32 | % .FrameRate: nbre of frames per second, =[] for images |
---|
| 33 | % VideoObject: in case of video |
---|
| 34 | % |
---|
| 35 | % INPUT: |
---|
| 36 | % fileinput: name, including path, of the file to analyse |
---|
[809] | 37 | |
---|
| 38 | %======================================================================= |
---|
[1126] | 39 | % Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
[809] | 40 | % http://www.legi.grenoble-inp.fr |
---|
[1127] | 41 | % Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr |
---|
[809] | 42 | % |
---|
| 43 | % This file is part of the toolbox UVMAT. |
---|
| 44 | % |
---|
| 45 | % UVMAT is free software; you can redistribute it and/or modify |
---|
| 46 | % it under the terms of the GNU General Public License as published |
---|
| 47 | % by the Free Software Foundation; either version 2 of the license, |
---|
| 48 | % or (at your option) any later version. |
---|
| 49 | % |
---|
| 50 | % UVMAT is distributed in the hope that it will be useful, |
---|
| 51 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 52 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 53 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
| 54 | %======================================================================= |
---|
| 55 | |
---|
[784] | 56 | function [FileInfo,VideoObject]=get_file_info(fileinput) |
---|
[1162] | 57 | |
---|
[784] | 58 | VideoObject=[]; |
---|
[1041] | 59 | FileInfo.FileType='';% input file does not exist |
---|
| 60 | FileInfo.FieldType=''; %default output |
---|
[1122] | 61 | if ~ischar(fileinput) |
---|
| 62 | return |
---|
| 63 | end |
---|
[1041] | 64 | % check the existence (not possible for OpenDAP data) |
---|
[1134] | 65 | if ~isempty(regexp(fileinput,'^http://','once'))|| exist(fileinput,'file') |
---|
[784] | 66 | FileInfo.FileName=fileinput; |
---|
| 67 | FileInfo.FileType='txt'; %default |
---|
[1162] | 68 | else |
---|
| 69 | return %input file does not exist. |
---|
[784] | 70 | end |
---|
| 71 | [tild,tild,FileExt]=fileparts(fileinput);%get the file extension FileExt |
---|
| 72 | |
---|
| 73 | switch FileExt |
---|
| 74 | case '.fig' |
---|
| 75 | FileInfo.FileType='figure'; |
---|
[1088] | 76 | case '.mat' |
---|
| 77 | FileInfo.FileType='mat'; |
---|
[784] | 78 | case {'.xml','.xls','.dat','.bin'} |
---|
| 79 | FileInfo.FileType=regexprep(FileExt,'^.','');% eliminate the dot of the extension; |
---|
[790] | 80 | case {'.seq','.sqb'} |
---|
[1157] | 81 | [~,FileInfo,timestamps,errormsg]=read_rdvision(fileinput,[]); |
---|
[1007] | 82 | case '.im7' |
---|
| 83 | try |
---|
[1162] | 84 | Input=readimx(fileinput); |
---|
| 85 | Image=Input.Frames{1}.Components{1}.Planes{1}; |
---|
| 86 | FileInfo.FileType='image_DaVis'; |
---|
| 87 | FileInfo.NumberOfFrames=numel(Input.Frames); |
---|
| 88 | FileInfo.Height=size(Image,2); |
---|
| 89 | FileInfo.Width=size(Image,1); |
---|
| 90 | FileInfo.TimeName='timestamp'; |
---|
| 91 | for ilist=1:numel(Input.Attributes) |
---|
| 92 | % if strcmp(Input.Attributes{ilist}.Name,'_Date') |
---|
| 93 | % DateString=Input.Attributes{ilist}.Value; |
---|
| 94 | % end |
---|
| 95 | % if strcmp(Input.Attributes{ilist}.Name,'_Time') |
---|
| 96 | % TimeString=Input.Attributes{ilist}.Value; |
---|
| 97 | % end |
---|
| 98 | end |
---|
[1007] | 99 | catch ME |
---|
[1033] | 100 | msgbox_uvmat('ERROR',{ME.message;'reading image from DaVis is possible only with Matlab version 2013 or earlier'}) |
---|
[1007] | 101 | return |
---|
| 102 | end |
---|
[946] | 103 | case '.h5' |
---|
[1134] | 104 | hinfo=h5info(fileinput); |
---|
| 105 | FileInfo.CivStage=0; |
---|
| 106 | for igroup=1:numel(hinfo.Groups) |
---|
| 107 | if strcmp(hinfo.Groups(igroup).Name,'/piv0') |
---|
| 108 | FileInfo.CivStage=3; |
---|
| 109 | end |
---|
| 110 | if strcmp(hinfo.Groups(igroup).Name,'/piv1') |
---|
| 111 | FileInfo.CivStage=6; |
---|
| 112 | break |
---|
| 113 | end |
---|
| 114 | end |
---|
| 115 | if FileInfo.CivStage~=0 |
---|
[946] | 116 | FileInfo.FileType='pivdata_fluidimage'; |
---|
[1134] | 117 | else |
---|
| 118 | FileInfo.FileType='h5'; |
---|
[946] | 119 | end |
---|
[979] | 120 | case '.cine' |
---|
| 121 | [FileInfo,BitmapInfoHeader, CameraSetup]=readCineHeader(fileinput); |
---|
| 122 | FileInfo.FileType='cine_phantom'; |
---|
| 123 | FileInfo.NumberOfFrames=FileInfo.ImageCount; |
---|
| 124 | FileInfo.FrameRate=CameraSetup.FrameRate; |
---|
| 125 | FileInfo.Height=BitmapInfoHeader.biHeight; |
---|
| 126 | FileInfo.Width=BitmapInfoHeader.biWidth; |
---|
[1162] | 127 | FileInfo.BitDepth=BitmapInfoHeader.biBitCount; |
---|
| 128 | FileInfo.TimeName='video'; |
---|
[1170] | 129 | case '.hcc' |
---|
| 130 | %cd 'TelopsToolbox_20230707(r20340)' |
---|
| 131 | installToolboxIRCAM |
---|
| 132 | [~,InfoArray]=readIRCam(fileinput,'HeadersOnly',true); |
---|
| 133 | FileInfo.FileType='telopsIR'; |
---|
| 134 | FileInfo.Height=InfoArray(1).Height; |
---|
| 135 | FileInfo.Width=InfoArray(1).Width; |
---|
| 136 | FileInfo.FrameRate=InfoArray(1).AcquisitionFrameRate; |
---|
| 137 | FileInfo.NumberOfFrames=numel(InfoArray); |
---|
| 138 | FileInfo.TimeName='video'; |
---|
[784] | 139 | otherwise |
---|
| 140 | if ~isempty(FileExt)% exclude empty extension |
---|
| 141 | FileExt=regexprep(FileExt,'^.','');% eliminate the dot of the extension |
---|
| 142 | if ~isempty(FileExt) |
---|
| 143 | if ~isempty(imformats(FileExt))%case of images |
---|
[1120] | 144 | FileInfo.FileType='image'; |
---|
[784] | 145 | try |
---|
| 146 | imainfo=imfinfo(fileinput); |
---|
[1162] | 147 | if length(imainfo) >1 %case of image with multiple frames |
---|
[784] | 148 | FileInfo=imainfo(1);%take info from the first frame |
---|
| 149 | FileInfo.NumberOfFrames=length(imainfo); |
---|
| 150 | FileInfo.FileType='multimage'; |
---|
| 151 | else |
---|
| 152 | FileInfo=imainfo; |
---|
| 153 | FileInfo.NumberOfFrames=1; |
---|
| 154 | FileInfo.FileType='image'; |
---|
| 155 | end |
---|
| 156 | FileInfo.FileName=FileInfo.Filename; %correct the info given by imfinfo |
---|
| 157 | nbfield=numel(fieldnames(FileInfo)); |
---|
| 158 | FileInfo=orderfields(FileInfo,[nbfield nbfield-1 nbfield-2 (1:nbfield-3)]); %reorder the fields of fileInfo for clarity |
---|
[1165] | 159 | catch ME |
---|
| 160 | FileInfo.error=ME.message |
---|
[784] | 161 | end |
---|
| 162 | else |
---|
| 163 | error_nc=0; |
---|
[1162] | 164 | try %try netcdf file |
---|
| 165 | [Data,tild,tild,errormsg]=nc2struct(fileinput,[]); |
---|
| 166 | if isempty(errormsg) |
---|
[1164] | 167 | % if isfield(Data,'absolut_time_T0') && isfield(Data,'hart') && ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart) |
---|
| 168 | % FileInfo.FileType='civx';%old civ data from the Fortran program |
---|
| 169 | % if isfield(Data,'patch2') && isequal(Data.patch2,1) |
---|
| 170 | % FileInfo.CivStage=6; |
---|
| 171 | % elseif isfield(Data,'fix2') && isequal(Data.fix2,1) |
---|
| 172 | % FileInfo.CivStage=5; |
---|
| 173 | % elseif isfield(Data,'civ2')&& isequal(Data.civ2,1) |
---|
| 174 | % FileInfo.CivStage=4; |
---|
| 175 | % elseif isfield(Data,'patch')&&isequal(Data.patch,1) |
---|
| 176 | % FileInfo.CivStage=3; |
---|
| 177 | % elseif isfield(Data,'fix')&&isequal(Data.fix,1) |
---|
| 178 | % FileInfo.CivStage=2; |
---|
| 179 | % else |
---|
| 180 | % FileInfo.CivStage=1; |
---|
| 181 | % end |
---|
| 182 | % else |
---|
| 183 | if isfield(Data,'Conventions') && strcmp(Data.Conventions,'uvmat/civdata') |
---|
[1161] | 184 | FileInfo.FileType='civdata'; % test for civ velocity fields |
---|
[784] | 185 | FileInfo.CivStage=Data.CivStage; |
---|
[1164] | 186 | MaskFile=''; |
---|
| 187 | if isfield(Data,'Civ2_Mask') |
---|
| 188 | MaskFile=Data.Civ2_Mask; |
---|
| 189 | if isfield(Data,'Civ2_NbSlice') |
---|
| 190 | FileInfo.MaskNbSlice=Data.Civ2_NbSlice; |
---|
| 191 | end |
---|
| 192 | elseif isfield(Data,'Civ1_Mask') |
---|
| 193 | MaskFile=Data.Civ1_Mask; |
---|
| 194 | if isfield(Data,'Civ1_NbSlice') |
---|
| 195 | FileInfo.MaskNbSlice=Data.Civ1_NbSlice; |
---|
| 196 | end |
---|
| 197 | end |
---|
| 198 | if isfield(Data,'VolumeScan') |
---|
| 199 | FileInfo.VolumeScan=Data.VolumeScan; |
---|
| 200 | end |
---|
| 201 | if ~isempty(MaskFile) |
---|
| 202 | [RootPath,SubDir,RootFile,~,~,~,~,FileExt,NomType]=fileparts_uvmat(MaskFile); |
---|
| 203 | if strcmp(NomType,'_1')&& isfield(FileInfo,'MaskNbSlice') |
---|
| 204 | FileInfo.MaskFile=fullfile(RootPath,SubDir,RootFile); |
---|
| 205 | else |
---|
| 206 | FileInfo.MaskFile=MaskFile;% single mask for the series (no indexing) |
---|
| 207 | end |
---|
| 208 | FileInfo.MaskExt=FileExt; |
---|
| 209 | end |
---|
[1161] | 210 | elseif isfield(Data,'Conventions') && strcmp(Data.Conventions,'uvmat/civdata_3D') |
---|
| 211 | FileInfo.FileType='civdata_3D'; % test for 3D volume civ velocity fields |
---|
| 212 | FileInfo.CivStage=Data.CivStage; |
---|
[1162] | 213 | z_dim_index=find(strcmp(Data.ListDimName,'npz')); |
---|
| 214 | FileInfo.NumberOfFrames=Data.DimValue(z_dim_index); |
---|
[784] | 215 | else |
---|
| 216 | FileInfo.FileType='netcdf'; |
---|
| 217 | FileInfo.ListVarName=Data.ListVarName; |
---|
[1162] | 218 | FileInfo.VarAttribute={}; |
---|
| 219 | if isfield(Data,'VarAttribute') |
---|
| 220 | FileInfo.VarAttribute=Data.VarAttribute; |
---|
| 221 | end |
---|
| 222 | FileInfo.ListDimName=Data.ListDimName; |
---|
[1165] | 223 | % FileInfo.NumberOfFrames=Data.DimValue; |
---|
[784] | 224 | end |
---|
[1162] | 225 | else |
---|
| 226 | error_nc=1; |
---|
[784] | 227 | end |
---|
| 228 | catch ME |
---|
| 229 | error_nc=1; |
---|
| 230 | end |
---|
| 231 | if error_nc |
---|
| 232 | try |
---|
[1162] | 233 | if exist('mmreader.m','file')% Matlab 2009a |
---|
| 234 | INFO=mmfileinfo (fileinput); |
---|
| 235 | if ~isempty(INFO.Video.Format) |
---|
| 236 | |
---|
| 237 | VideoObject=mmreader(fileinput); |
---|
| 238 | FileInfo=get(VideoObject); |
---|
| 239 | FileInfo.FileType='mmreader'; |
---|
| 240 | end |
---|
[784] | 241 | end |
---|
| 242 | FileInfo.BitDepth=FileInfo.BitsPerPixel/3; |
---|
| 243 | FileInfo.ColorType='truecolor'; |
---|
[1032] | 244 | FileInfo.TimeName='video'; |
---|
[784] | 245 | FileInfo.FileName=fileinput; |
---|
| 246 | nbfield=numel(fieldnames(FileInfo)); |
---|
[1032] | 247 | FileInfo=orderfields(FileInfo,[nbfield nbfield-4 nbfield-3 nbfield-1 nbfield-2 (1:nbfield-5)]); %reorder the fields of fileInfo for clarity |
---|
[1025] | 248 | if ~isfield(FileInfo,'NumberOfFrames') |
---|
| 249 | FileInfo.NumberOfFrames=floor(FileInfo.Duration*FileInfo.FrameRate); |
---|
| 250 | end |
---|
[784] | 251 | end |
---|
| 252 | end |
---|
| 253 | end |
---|
| 254 | end |
---|
| 255 | end |
---|
[790] | 256 | end |
---|
[1041] | 257 | |
---|
[1089] | 258 | if ismember (FileInfo.FileType,{'mat','image','image_DaVis','multimage','mmreader','cine_phantom','video','netcdf','civdata'}) |
---|
[1162] | 259 | FileInfo.FileIndexing='on'; % allow to detect file index for scanning series |
---|
[1041] | 260 | else |
---|
| 261 | FileInfo.FileIndexing='off'; |
---|
[809] | 262 | end |
---|
[1033] | 263 | FileInfo.FieldType=FileInfo.FileType;%default |
---|
| 264 | switch FileInfo.FileType |
---|
[1170] | 265 | case {'image','multimage','video','mmreader','rdvision','image_DaVis','cine_phantom','telopsIR'} |
---|
[1162] | 266 | FileInfo.FieldType='image'; |
---|
[1041] | 267 | case {'civx','civdata','pivdata_fluidimage'} |
---|
| 268 | FileInfo.FieldType='civdata'; |
---|
[1033] | 269 | end |
---|
| 270 | |
---|