[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) |
---|
| 57 | VideoObject=[]; |
---|
[1041] | 58 | FileInfo.FileType='';% input file does not exist |
---|
| 59 | FileInfo.FieldType=''; %default output |
---|
[1122] | 60 | if ~ischar(fileinput) |
---|
| 61 | return |
---|
| 62 | end |
---|
[1041] | 63 | % check the existence (not possible for OpenDAP data) |
---|
[1134] | 64 | if ~isempty(regexp(fileinput,'^http://','once'))|| exist(fileinput,'file') |
---|
[784] | 65 | FileInfo.FileName=fileinput; |
---|
| 66 | FileInfo.FileType='txt'; %default |
---|
[1134] | 67 | else |
---|
| 68 | return %input file does not exist. |
---|
[784] | 69 | end |
---|
| 70 | [tild,tild,FileExt]=fileparts(fileinput);%get the file extension FileExt |
---|
| 71 | |
---|
| 72 | switch FileExt |
---|
| 73 | case '.fig' |
---|
| 74 | FileInfo.FileType='figure'; |
---|
[1088] | 75 | case '.mat' |
---|
| 76 | FileInfo.FileType='mat'; |
---|
[784] | 77 | case {'.xml','.xls','.dat','.bin'} |
---|
| 78 | FileInfo.FileType=regexprep(FileExt,'^.','');% eliminate the dot of the extension; |
---|
[790] | 79 | case {'.seq','.sqb'} |
---|
[1157] | 80 | [~,FileInfo,timestamps,errormsg]=read_rdvision(fileinput,[]); |
---|
[1007] | 81 | case '.im7' |
---|
| 82 | try |
---|
| 83 | Input=readimx(fileinput); |
---|
| 84 | Image=Input.Frames{1}.Components{1}.Planes{1}; |
---|
| 85 | FileInfo.FileType='image_DaVis'; |
---|
| 86 | FileInfo.NumberOfFrames=numel(Input.Frames); |
---|
| 87 | FileInfo.Height=size(Image,2); |
---|
| 88 | FileInfo.Width=size(Image,1); |
---|
[1032] | 89 | FileInfo.TimeName='timestamp'; |
---|
[1033] | 90 | for ilist=1:numel(Input.Attributes) |
---|
[1157] | 91 | % if strcmp(Input.Attributes{ilist}.Name,'_Date') |
---|
| 92 | % DateString=Input.Attributes{ilist}.Value; |
---|
| 93 | % end |
---|
| 94 | % if strcmp(Input.Attributes{ilist}.Name,'_Time') |
---|
| 95 | % TimeString=Input.Attributes{ilist}.Value; |
---|
| 96 | % end |
---|
[1033] | 97 | end |
---|
[1007] | 98 | catch ME |
---|
[1033] | 99 | msgbox_uvmat('ERROR',{ME.message;'reading image from DaVis is possible only with Matlab version 2013 or earlier'}) |
---|
[1007] | 100 | return |
---|
| 101 | end |
---|
[946] | 102 | case '.h5' |
---|
[1134] | 103 | hinfo=h5info(fileinput); |
---|
| 104 | FileInfo.CivStage=0; |
---|
| 105 | for igroup=1:numel(hinfo.Groups) |
---|
| 106 | if strcmp(hinfo.Groups(igroup).Name,'/piv0') |
---|
| 107 | FileInfo.CivStage=3; |
---|
| 108 | end |
---|
| 109 | if strcmp(hinfo.Groups(igroup).Name,'/piv1') |
---|
| 110 | FileInfo.CivStage=6; |
---|
| 111 | break |
---|
| 112 | end |
---|
| 113 | end |
---|
| 114 | if FileInfo.CivStage~=0 |
---|
[946] | 115 | FileInfo.FileType='pivdata_fluidimage'; |
---|
[1134] | 116 | else |
---|
| 117 | FileInfo.FileType='h5'; |
---|
[946] | 118 | end |
---|
[979] | 119 | case '.cine' |
---|
| 120 | [FileInfo,BitmapInfoHeader, CameraSetup]=readCineHeader(fileinput); |
---|
| 121 | FileInfo.FileType='cine_phantom'; |
---|
| 122 | FileInfo.NumberOfFrames=FileInfo.ImageCount; |
---|
| 123 | FileInfo.FrameRate=CameraSetup.FrameRate; |
---|
| 124 | FileInfo.Height=BitmapInfoHeader.biHeight; |
---|
| 125 | FileInfo.Width=BitmapInfoHeader.biWidth; |
---|
[991] | 126 | FileInfo.BitDepth=BitmapInfoHeader.biBitCount; |
---|
[1032] | 127 | FileInfo.TimeName='video'; |
---|
[784] | 128 | otherwise |
---|
| 129 | if ~isempty(FileExt)% exclude empty extension |
---|
| 130 | FileExt=regexprep(FileExt,'^.','');% eliminate the dot of the extension |
---|
| 131 | if ~isempty(FileExt) |
---|
| 132 | if ~isempty(imformats(FileExt))%case of images |
---|
[1120] | 133 | FileInfo.FileType='image'; |
---|
[784] | 134 | try |
---|
| 135 | imainfo=imfinfo(fileinput); |
---|
| 136 | if length(imainfo) >1 %case of image with multiple frames |
---|
| 137 | FileInfo=imainfo(1);%take info from the first frame |
---|
| 138 | FileInfo.NumberOfFrames=length(imainfo); |
---|
| 139 | FileInfo.FileType='multimage'; |
---|
| 140 | else |
---|
| 141 | FileInfo=imainfo; |
---|
| 142 | FileInfo.NumberOfFrames=1; |
---|
| 143 | FileInfo.FileType='image'; |
---|
| 144 | end |
---|
| 145 | FileInfo.FileName=FileInfo.Filename; %correct the info given by imfinfo |
---|
| 146 | nbfield=numel(fieldnames(FileInfo)); |
---|
| 147 | FileInfo=orderfields(FileInfo,[nbfield nbfield-1 nbfield-2 (1:nbfield-3)]); %reorder the fields of fileInfo for clarity |
---|
| 148 | end |
---|
| 149 | else |
---|
| 150 | error_nc=0; |
---|
| 151 | try |
---|
| 152 | [Data,tild,tild,errormsg]=nc2struct(fileinput,[]); |
---|
| 153 | if ~isempty(errormsg) |
---|
| 154 | error_nc=1; |
---|
| 155 | else |
---|
| 156 | if isfield(Data,'absolut_time_T0') && isfield(Data,'hart') && ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart) |
---|
| 157 | FileInfo.FileType='civx'; |
---|
| 158 | if isfield(Data,'patch2') && isequal(Data.patch2,1) |
---|
| 159 | FileInfo.CivStage=6; |
---|
| 160 | elseif isfield(Data,'fix2') && isequal(Data.fix2,1) |
---|
| 161 | FileInfo.CivStage=5; |
---|
| 162 | elseif isfield(Data,'civ2')&& isequal(Data.civ2,1) |
---|
| 163 | FileInfo.CivStage=4; |
---|
| 164 | elseif isfield(Data,'patch')&&isequal(Data.patch,1) |
---|
| 165 | FileInfo.CivStage=3; |
---|
| 166 | elseif isfield(Data,'fix')&&isequal(Data.fix,1) |
---|
| 167 | FileInfo.CivStage=2; |
---|
| 168 | else |
---|
| 169 | FileInfo.CivStage=1; |
---|
| 170 | end |
---|
| 171 | elseif isfield(Data,'Conventions') && strcmp(Data.Conventions,'uvmat/civdata') |
---|
| 172 | FileInfo.FileType='civdata'; % test for civx velocity fields |
---|
| 173 | FileInfo.CivStage=Data.CivStage; |
---|
| 174 | else |
---|
| 175 | FileInfo.FileType='netcdf'; |
---|
| 176 | FileInfo.ListVarName=Data.ListVarName; |
---|
[1157] | 177 | FileInfo.VarAttribute=Data.VarAttribute; |
---|
[784] | 178 | end |
---|
| 179 | end |
---|
| 180 | catch ME |
---|
| 181 | error_nc=1; |
---|
| 182 | end |
---|
| 183 | if error_nc |
---|
| 184 | try |
---|
| 185 | if exist('VideoReader.m','file')%recent version of Matlab |
---|
| 186 | VideoObject=VideoReader(fileinput); |
---|
| 187 | FileInfo=get(VideoObject); |
---|
| 188 | FileInfo.FileType='video'; |
---|
| 189 | elseif exist('mmreader.m','file')% Matlab 2009a |
---|
| 190 | VideoObject=mmreader(fileinput); |
---|
| 191 | FileInfo=get(VideoObject); |
---|
| 192 | FileInfo.FileType='mmreader'; |
---|
| 193 | end |
---|
| 194 | FileInfo.BitDepth=FileInfo.BitsPerPixel/3; |
---|
| 195 | FileInfo.ColorType='truecolor'; |
---|
[1032] | 196 | FileInfo.TimeName='video'; |
---|
[784] | 197 | FileInfo.FileName=fileinput; |
---|
| 198 | nbfield=numel(fieldnames(FileInfo)); |
---|
[1032] | 199 | FileInfo=orderfields(FileInfo,[nbfield nbfield-4 nbfield-3 nbfield-1 nbfield-2 (1:nbfield-5)]); %reorder the fields of fileInfo for clarity |
---|
[1025] | 200 | if ~isfield(FileInfo,'NumberOfFrames') |
---|
| 201 | FileInfo.NumberOfFrames=floor(FileInfo.Duration*FileInfo.FrameRate); |
---|
| 202 | end |
---|
[784] | 203 | end |
---|
| 204 | end |
---|
| 205 | end |
---|
| 206 | end |
---|
| 207 | end |
---|
[790] | 208 | end |
---|
[1041] | 209 | |
---|
[1089] | 210 | if ismember (FileInfo.FileType,{'mat','image','image_DaVis','multimage','mmreader','cine_phantom','video','netcdf','civdata'}) |
---|
[790] | 211 | FileInfo.FileIndexing='on'; % allow to detect file index for scanning series |
---|
[1041] | 212 | else |
---|
| 213 | FileInfo.FileIndexing='off'; |
---|
[809] | 214 | end |
---|
[1033] | 215 | FileInfo.FieldType=FileInfo.FileType;%default |
---|
| 216 | switch FileInfo.FileType |
---|
| 217 | case {'image','multimage','video','mmreader','rdvision','image_DaVis','cine_phantom'} |
---|
| 218 | FileInfo.FieldType='image'; |
---|
[1041] | 219 | case {'civx','civdata','pivdata_fluidimage'} |
---|
| 220 | FileInfo.FieldType='civdata'; |
---|
[1033] | 221 | end |
---|
| 222 | |
---|