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